function onAfter(curr, next, opts) {
    var index = opts.currSlide;
    $('#releasePrev')[index == 0 ? 'hide' : 'show']();
    $('#releaseNext')[index == opts.slideCount - 1 ? 'hide' : 'show']();
};

function theFeatureRotator() {
	//Set the opacity of all images to 0
	$('div#feature_rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#feature_rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('featurerotate()',10000);	
};
function featurerotate() {	
	//Get the first image
	var current = ($('div#feature_rotator ul li.show')?  $('div#feature_rotator ul li.show') : $('div#feature_rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#feature_rotator ul li:first') :current.next()) : $('div#feature_rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};


function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',10000);	
};
function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};
$(document).ready(function() {
	$(".movable").sortable({
		handle : '.handle',
		update : function () {
			var order = $('.movable').sortable('serialize');
		}
	});
	//Load the slideshow
	theRotator();
	theFeatureRotator();
	
	//language tab setting 
	//Default Action
	$(".tab_content").hide(); //Hide all content
	//$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {
		//$("ul.tabs li").removeClass("active"); //Remove any "active" class
		//$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn("Slow"); //Fade in the active content
		return false;
	});
	
	
	/** begin PROFILE : for LUCAS VALENTINE */
	
	/* same as tabs action, but for profile top chart */
	$(".chart_content").hide();
	$(".chart_content:first").show();
	$("ul.chart li").click(function() {
		$(".chart_content").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn("fast");
		return false;
	});
	
	$(".chart_content_beta").hide();
	$(".chart_content_beta:first").show();
	$("ul.chart_beta li").click(function() {
		$(".chart_content_beta").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn("fast");
		return false;
	});
	
	
	/* end PROFILE : for LUCAS VALENTINE **/
	
	//needs jquery.tools.scrollable
	//$("div.scrollable").scrollable({
	//	size: 1
	//});
	
	//$("#yuliatrack").tabs({
	//	collapsible: true
	//});
	
	/* defining for fancybox.. mainly used in news when there's a thumbnail in article and stuff... calling the class "zoomit" */
	$("a.zoomit").fancybox({
		'zoomOpacity'	: true,
		'overlayShow'	: false,
		'padding'		: 3,
		'zoomSpeedIn'	: 300,
		'zoomSpeedOut'	: 300
	});
	
	/** declaring random background */
	/* okay i was trying to do it on jquery but when you think about it, this loads the jpg first which means it has to download all the fucking shit
	so im just gonna do it the php way. jquery way is just too inefficient -makki 2010.04.06 */
	//bgImageTotal=3;
	//randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1;
	//imgPath=('/img/background/'+randomNumber+'.jpg');
	//$('body').css('background', ('url("'+imgPath+'") repeat-x #1e1e1e !important'));
	/* end of random background **/
	


	/** hoping to convert all the visual effects to jquery.cycle soon */
	$('#newreleases_slideshow').cycle({ 
	    fx:     'scrollHorz', 
	    prev:   '#releasePrev', 
	    next:   '#releaseNext', 
	    after:   onAfter,
	    timeout: 0 
	});
	
	/* the featureRotator thing is way too complicated **/
	
	
});