var slide_index=-1;
var slide_count=0;
var slide_auto=true;
var slide_auto_time=8; //in seconds
var slide_animating=false;
var slide_timer;

var t=0;

$(function(){
	$("#dvAltTexts").hide();
	
	slide_count=5;
	
	var str='';
	$("div.carouselSlideClass").each(function(){
		var i = $(this).attr("id").replace("carouselSlide", "");
		str += '<a href="#'+i+'" id="lnkBullet'+i+'" class="lnkBullet">&nbsp;</a>';
	});
	
	$("a.moreInfo").hover(function(){
		$(this).children("img").attr("src", "splash-page-resources/images-v3/more-info-hover.gif");
	}, function(){
		$(this).children("img").attr("src", "splash-page-resources/images-v3/more-info.gif");
	})
	
	$("div.btn").hover(function(){
		show_slide($(this).attr('id').replace("lnk-slide-", ""));
	}, function(){
		hide_slide();		
	});
	
	$("div.carouselSlideClass").hover(function(){
		show_slide($(this).attr('id').replace("carouselSlide", ""));
	}, function(){
		hide_slide();
	});

	//change_slide(Math.floor(Math.random()*3));
	change_slide(1);	
});

function show_slide(id){
slide_auto=false;//DISABLE AUTOPLAY 
		clearTimeout(slide_timer);
		
		//change_slide($(this).text());
		change_slide(id);
}
function hide_slide(){
	slide_auto=true;//ENABLE AUTOPLAY 
	slide_timer=setTimeout("change_slide()",slide_auto_time*500);
}

function change_slide(change_to){
	if(slide_index==(change_to-1)){
		return;
	}
	var prev_slide_index=slide_index;
	
	if(change_to==undefined){
		slide_index++;
	}
	else{
		slide_index=change_to-1;
	}
	
	if(slide_index>=slide_count && change_to!=0){
		slide_index=0;
	}
	
	
	var sindex = slide_index;
	
	$("#tesl-img").css({opacity:0});
	
	$("#lnk-slide-"+(prev_slide_index+1)).stop(true, true).animate({
		top:5,
		opacity:.6
	});
	var sobj = $("#lnk-slide-"+(sindex+1));
	sobj.stop(true, true).animate({
		top:0,
		opacity:1
	});
	
	
	$("#dvSliderArrow").stop(false, false).animate({
		left: (sobj.position().left + (sobj.width()/2)) - ($("#dvSliderArrow").width()/2)+17
	});
	
	
	var obj_prv = $("#dvCarouselSlidesContainer .carouselSlideClass").eq(prev_slide_index);
	obj_prv.children("a.moreInfo").hide();
	obj_prv.stop(true, true).hide();
	if(sindex>=0){
		var obj_nxt = $("#dvCarouselSlidesContainer .carouselSlideClass").eq(sindex);
		obj_prv.children("a.moreInfo").show();
		obj_nxt.stop(true, true).fadeIn();
	}

	if(slide_auto){
		clearTimeout(slide_timer);
		slide_timer=setTimeout("change_slide()",slide_auto_time*1000);
	}

	$("#dvCarouselIndicator a").removeClass("selected");	
	$("#lnk-bullet-"+(slide_index+1)).addClass("selected");	
	
}
