
var slideTimeout = 5000;
var curIndex;
var numSlides;
var timerId;


$(document).ready(function() {

	var inProgress = false;
	curIndex = 0;
	numSlides = $("ul#overlay").children().size();
	

	$("ul#overlay li a").bind('custom', function(){


		if(inProgress == true)
		{
			return false;
		} 

		inProgress = true;
		clearTimeout ( timerId );
		curIndex = $("ul#overlay li").index($(this).parent());
		


		$("ul#overlay li a").removeClass("selected");
		
		$(this).addClass("selected");

		var link = $(this).attr("href");
		var imgsrc = $(this).attr("rel");
		var caption = $(this).find(".caption").html();
		


		$(".banner h2").fadeOut('fast',function(){
			$(".banner img").fadeOut('fast',function(){
				$(".banner").html('');
				$(".banner").image(imgsrc,function(){
					$(".banner img").wrap("<a href='" + link + "'></a>");
					$(".banner").append("<h2 class='caption'>" + caption + "</h2>");
					$("h2.caption").fadeIn('fast');
					inProgress = false;
				});
			});
		});
		
		timerId = setTimeout("startShow()", slideTimeout );	
		return false;
	
	});


	timerId = setTimeout("startShow()", slideTimeout );


});



function startShow()
{
	curIndex++;
	
	if(curIndex >= numSlides)
		curIndex = 0;
		
	$("ul#overlay li:eq(" + curIndex + ") a").trigger('custom');

}








