
// JavaScript Document

/*
 * Carousel script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Stefan Isfeld 
 * 
 *
 */


// initalize
var panelcount = 0;		// Which panl is being displayed
var lastPanel = 2;		// How may panels are thre in total
var backToButton = 0;	// Which carousel button to go back to after rollover
var carouselTimer;		// Timer id

$(document).ready(function(){
	/* CONFIG */
	$(".carousel:first").css( {"display":"block"} );
	carouselTimer = setTimeout ( "nextpanel()", 3000 );
	$("#cButton_0").css( {"background": "url(/pics/sports/sport_basic/promo_carousel_0_ov.gif) no-repeat"  } );
	/* CONFIG */
	
	// Carousel Button rollover
	$(".carouselB").mouseover(function() {
		
		carouselLength = $(".carouselB").length;
		for (x=0;x<carouselLength;x++) {
			imgNum = "url(/pics/sports/sport_basic/promo_carousel_"+x+".gif) no-repeat";
			idNum = whichId = "#" + "cButton_" + x;
			$(idNum).css( {"background": imgNum } );
		}
		
		whichId = parseInt( $(this).attr("id").substring( $(this).attr("id").lastIndexOf("_")+1 , $(this).attr("id").length) );
		whichImg = "url(/pics/sports/sport_basic/promo_carousel_"+whichId+"_ov.gif) no-repeat";
		$(this).css( {"background": whichImg } );
		
		panelcount = whichId;
		$( ".carousel" ).css( {"display":"none"} );
		$(".carousel:eq("+panelcount+")").fadeIn();
		
		clearTimeout ( carouselTimer );
		
		}).mouseout(function() {	
			carouselTimer = setTimeout ( "nextpanel()", 3000 );
			});

});

function nextpanel() {
	$( ".carousel" ).css( {"display":"none"} );
	
	if (panelcount == lastPanel) {
		lastPanel = panelcount;
		panelcount = 0;
	} else {
		panelcount = panelcount + 1;
	}
	$(".carousel:eq("+panelcount+")").fadeIn();
	
	carouselLength = $(".carouselB").length;
	for (x=0;x<carouselLength;x++) {
		imgNum = "url(/pics/sports/sport_basic/promo_carousel_"+x+".gif) no-repeat";
		idNum = whichId = "#" + "cButton_" + x;
		$(idNum).css( {"background": imgNum } );
	}
	
	whichImg = "url(/pics/sports/sport_basic/promo_carousel_"+panelcount+"_ov.gif) no-repeat";
	whichId = "#" + "cButton_" + panelcount;
	$(whichId).css( {"background": whichImg } );
	
	carouselTimer = setTimeout ( "nextpanel()", 3000 );
}

