/* ---------------------------------------------------- */
/* JQuery												*/
/* ---------------------------------------------------- */
$jQuery(document).ready(function() 
{

	/* Fix PNG transparency issues on IE6 */
	$jQuery(document).pngFix(); 
	
	/*############################################################################
	Fancybox popup image system - any link with the class 'popup'
	############################################################################ */
	$jQuery("a.popup").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	600, 
		'speedOut'		:	150, 
		'overlayShow'	:	true
	});
	
	/*############################################################################
	Fancybox popup video system - for viewing Cultures of Resistance video in popup
	############################################################################ */
	$jQuery("a.culturespopup").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 825,
		'height'		: 464,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=18028650',
		'type'			: 'swf'
	});
	
	
	/* Initialise the Easy Slider system */
	$jQuery("#slider").easySlider({
		auto: false,
		continuous: false,
		numeric: true
	});

	/* Hide the two partner divs, which aren't needed until the fader makes them visible */
	$jQuery("div#partners2").hide();
	$jQuery("div#partners3").hide();
	
	/* specify the time time delay between the partner div fades */
	var time_delay = 4000;	
	/* run the partner div fader, passing in the time delay, the first div number and the final div number */
	partner_div_fader(time_delay, 1, 3);
	
});


/* ---------------------------------------------------- */
/* A recursive function which cycles through divs	    */
/* ---------------------------------------------------- */
function partner_div_fader(time_delay, img_num, final_div_num) {
	
	window.setTimeout(function() {
		
		$jQuery("div#partner_block").fadeOut('slow', function() {
			
			/* Hide the currently displayed partners block */
			$jQuery("div#partners" + img_num).css( "visibility", "hidden");
			$jQuery("div#partners" + img_num).hide();
			
			/* if the current div processed is not the final div, then add one to it and continue, else reset it to the 1st div (ie start again) */
			if (img_num != final_div_num) { img_num = img_num + 1; } else { img_num = 1;}
			
			/* Show the next partners block */
			$jQuery("div#partners" + img_num).show();
			$jQuery("div#partners" + img_num).css( "visibility", "visible");
			$jQuery("div#partner_block").fadeIn('slow');
		
			/* run the function recursively with the next div */
			partner_div_fader(time_delay, img_num, final_div_num);
			return;		
		});
	}, time_delay);
	
}
