// JavaScript Document
var header_ss_index=1;

$(document).ready(function() { 	
	//write your code here
	$("#header-carousel ul li a").mouseover(
		function () {
			$(this).children("div").css("display","block");
	  	}
	);
	
	$("#header-carousel ul li a").mouseout(
		function () {
			$(this).children("div").css("display","none");
	  	}
	);
	
	$("#header-carousel ul li a").click(
		function () {
			clearInterval(interval);
			$(this).children("div").css("display","block");
			arr = this.id.split("tab");
			num = parseInt(arr[1]);
			header_ss_index = num;
			switchSlide();
			interval = setInterval("switchSlide()",5000);
			/*
			$("#header-carousel .images").each(function (i) {
				if(i==num-1)
					$(this).fadeIn("slow");
				else
					$(this).hide();	
					
			});
			*/
	  	}
	);
	
	interval = setInterval("switchSlide()",7000);
	
});

function switchSlide() {
	//alert("switch is called");
	$("#header-carousel .images").each(function (i) {
		if(i==header_ss_index-1) {
			$("#tab"+(i+1)).addClass("tab"+(i+1)+"-active");
			$("#tab"+(i+1)).removeClass("tab"+(i+1));
			//$("#tab"+(i+1)+" div").show();
			$(this).fadeIn("slow");
		}	
		else {
			$("#tab"+(i+1)).removeClass("tab"+(i+1)+"-active");
			$("#tab"+(i+1)).addClass("tab"+(i+1));
			//$("#tab"+(i+1)+" div").hide();
			$(this).hide();	
		}	
	});
	
	if(header_ss_index==5)
		header_ss_index = 1;
	else
		header_ss_index++;	
	
}
