$(document).ready(function()
{
	//Start Rotation of Spotlights
	startRotation();
	
	// Switch Between the SPOTLIGHTS Tabs's
	$('div#gs_youth_spotlight ul li a').click(function() {
		$(this).parent("li").parent("ul").prevAll("div").hide();
		$('#'+$(this).attr("name")).fadeIn();
		return false;
	});
	
	// Limiting Rototing Spotlights to stop if the mouse hovers the text or the image
    $(".gs_spotlight").hover(
      function () {
        $(document).stopTime('spotlights');
      }, startRotation);
	
});

function startRotation() {
	$(document).everyTime(15000, "spotlights",function(i) {
			var currentspotID = $('#gs_youth_spotlight').children("div:visible").attr("id");
			currentspotID = currentspotID.substr(currentspotID.lastIndexOf("_")+1, 10);
			var lastspotID = $('#gs_spotlight_switcher').children("li:first").children("a").attr("name");
			lastspotID = lastspotID.substr(lastspotID.lastIndexOf("_")+1, 10);
			var firstspotID = $('#gs_spotlight_switcher').children("li:last").children("a").attr("name");
			firstspotID = firstspotID.substr(firstspotID.lastIndexOf("_")+1, 10);
			var nextspotID = $("#gs_spotlight_switcher").children("li").children("a[name='gs_spotlight_"+ currentspotID+"']").parent("li").prev("li").children("a").attr("name");
			if (nextspotID != undefined) nextspotID = nextspotID.substr(nextspotID.lastIndexOf("_")+1, 10);
			if ((currentspotID == lastspotID) || (nextspotID == undefined)) {
				nextspotID = firstspotID;
			}
			
			$('#gs_youth_spotlight').children("div:visible").hide();
			$('#gs_youth_spotlight').children("div#gs_spotlight_"+nextspotID).fadeIn();
	}, 0, 1);
};