var rotateSpeed = 8000; /* Milliseconds to wait until switching tabs. */
var currentSlot = 0; /* Set to a different number to start on a different tab. */
var numSlots; /* This variable is set on document ready. */
var autoRotate; /* used to hold the pointer to the timeout. */

function openSlot(targetSlot) {
  jQuery(".rotator-slot").hide();
  jQuery(".rotator-slot:eq("+targetSlot+")").show();
	currentSlot = targetSlot;
}

function rotateSlots() {
	var nextSlot = (currentSlot == (numSlots - 1)) ? 0 : currentSlot + 1;
	openSlot(nextSlot);
}

function rotateSlotsBack() {
	var previousSlot = (currentSlot == 0) ? (numSlots - 1) : currentSlot - 1;
	openSlot(previousSlot);
}

jQuery(document).ready(function() {
	numSlots = jQuery(".rotator-slot").length;
	
	jQuery(".rotator-slot-previous").click( function() { rotateSlotsBack(); });
  jQuery(".rotator-slot-next").click(     function() { rotateSlots(); });
		
	jQuery(".rotator-slot").mouseover(function(){ 
    clearInterval(autoRotate); 
  }).mouseout(function(){ 
    autoRotate = setInterval("rotateSlots()", rotateSpeed); 
  });
	
	jQuery(".rotator-slot:eq("+currentSlot+")").mouseout();	
});
