//////////////////ROTATOR FUNCTIONS/////////////////
//contains jquery and js that runs the index page 
//content rotator.
////////////////////////////////////////////////////

function autoRotator(){	
	//auto-rotates every 5 seconds
	$(document).everyTime(8000,"timedMove",function(){
		$("#rotatorContainer").fadeToNext(0);
	});
}

//image rotator code
//fades out currently visible child, fades in next child, or the first child if you are on the last
$.fn.fadeToNext = function(speed){
	$(this).children().each(function(){
	
		if($(this).is(":visible")){
			
			
			var callback;
			if(!$(this).is(":last-child")){
				callback = function(){$(this).next().fadeIn(speed);};
			}
			else{
				//no last child, so we fade in the first child of the list
				callback = function(){$(this).parent().children(":first").fadeIn(speed);};
			}
			$(this).fadeOut(speed,callback);
			return false; //stops looping
		}
	
	
	});
	
}
	
$.fn.fadeToPrev = function(speed){
 
	 $(this).children().each(function(){
	 
	 	if($(this).is(":visible")){
			
			var callback;
			if(!$(this).is(":first-child")){
				callback = function(){$(this).prev().fadeIn(speed);};
			}
				
			else{
				//no previous element, so we fade in the last child
				callback = function(){$(this).parent().children(":last").fadeIn(speed);};
			}
			$(this).fadeOut(speed,callback);
			return false; //stops looping
		}
	 
	 });
}


