/* we can't use $ on this page because it's already being used by lightwindow */

jQuery(function(){

	jQuery('#partnerRotation').css({
		'width':'418',
		'height':'288'
	});
	
	var rotation = [];
	
	/* loop event (requires "jquery.timers.js" plugin) 
	syntax: everyTime(duration[ms], function, iterations [0 = endless])
	*/
	jQuery(this).everyTime(8000,function(){
										 
		/* upon fadeout of current image, callback function loads next image */
		jQuery('#partnerRotation').children().fadeOut(2000,function(){
			
			/* remove old anchored images to free up browser memory */
			jQuery('#partnerRotation').empty();
			
			/* build/rebuild unused-image array 
			("partners" array is dynamically generated outside of this file)
			(slice creates independent copy of array) 
			*/
			if (rotation.length == 0) rotation = partners.slice();
			
			/* remove and use randomly selected image from array */
			var r = Math.floor ( Math.random() * rotation.length ); 
			var newImg = rotation[r];
			rotation.splice(r,1);
			
			/* clone anchored image from queue and display */
			jQuery('#imageQueue')
			.find('img.'+newImg).parent()
			.clone()
			.attr('id','active')
			.appendTo('#partnerRotation')
			.hide()
			.fadeIn(2000);
			
			/* on image click, load Lightwindow 
			 (automatically destroyed when associated link is removed from DOM)
			*/
			myLightWindow.createWindow(jQuery('#partnerRotation a').attr('id'));
			
		});
	},0);
});