/* By Dylan Wagstaff, http://www.alohatechsupport.net 
 * Edited by: Eric Rubi, Northstar Internet Services
 */

function theSponsorsRotator() {
	//Set the opacity of all images to 0
	//jQuery('div.rotate2 ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	//jQuery('div.rotate2 ul li:first-child').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	
	//only rotate when the page is on view
	setInterval('rotateSponsors()',5000);
	
}

function rotateSponsors() {	
	//Get the first image
	var current1 = (jQuery('div.rotate1 ul li.show')?  jQuery('div.rotate1 ul li.show') : jQuery('div.rotate1 ul li:first-child'));
	var current2 = (jQuery('div.rotate2 ul li.show')?  jQuery('div.rotate2 ul li.show') : jQuery('div.rotate2 ul li:first-child'));
	var current3 = (jQuery('div.rotate3 ul li.show')?  jQuery('div.rotate3 ul li.show') : jQuery('div.rotate3 ul li:first-child'));

	

    if ( current1.length == 0 ) current1 = jQuery('div.rotate1 ul li:first-child');
	if ( current2.length == 0 ) current2 = jQuery('div.rotate2 ul li:first-child');
	if ( current3.length == 0 ) current3 = jQuery('div.rotate3 ul li:first-child');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next1 = ((current1.next().length) ? ((current1.next().hasClass('show')) ? jQuery('div.rotate1 ul li:first-child') :current1.next()) : jQuery('div.rotate1 ul li:first-child'));
	var next2 = ((current2.next().length) ? ((current2.next().hasClass('show')) ? jQuery('div.rotate2 ul li:first-child') :current2.next()) : jQuery('div.rotate2 ul li:first-child'));
	var next3 = ((current3.next().length) ? ((current3.next().hasClass('show')) ? jQuery('div.rotate3 ul li:first-child') :current3.next()) : jQuery('div.rotate3 ul li:first-child'));
	
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length );
    //var next = jQuery( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next1.css({opacity: 1.0}).removeClass("noshow").addClass("show").animate({opacity: 1.0}, 1000);
	next2.css({opacity: 1.0}).removeClass("noshow").addClass("show").animate({opacity: 1.0}, 1000);
	next3.css({opacity: 1.0}).removeClass("noshow").addClass("show").animate({opacity: 1.0}, 1000);


	//Hide the current image
	current1.animate({opacity: 0.0}, 1000).removeClass("show");
	current2.animate({opacity: 0.0}, 1000).removeClass("show");
	current3.animate({opacity: 0.0}, 1000).removeClass("show");

	//current.css('display','none');
	
};



jQuery(document).ready(function() {		
	//Load the slideshow
	theSponsorsRotator();
	//jQuery('div.rotate2').fadeIn(1000);
    //jQuery('div.rotate2 ul li').fadeIn(1000); // tweek for IE
});
