$(function() {
	// control search query input
	$('#sQ').defaultvalue('Search');
	$('#sQ').focus(function() {
		$(this).toggleClass('focus');
	}).blur(function() {
		$(this).toggleClass('focus');
	});
	// flyout my account nav
	$('#hSub p a:eq(1)').mouseover(function(){
		$('#hSub').animate({
			width: '850px'
		},1000);
		$('#i18n').fadeOut(100);
		setTimeout("$('#accntNav').fadeIn('slow')",500);
	});
	$('#accntNav img').click(function() {
		$('#hSub').animate({
			width: '375px'
		},500, function() { setTimeout("$('#i18n').fadeIn(500);",100); });
		$('#accntNav').fadeOut('fast');
	});

	// homepage
	$('#homeSlideCntrls').ifixpng();
	$.preload('#homeSlide div', {
		onFinish: playHome
	});
	
	$('#cntrls img.c1').css('cursor','pointer').click(function() { actionCall(1) });
	$('#cntrls img.c2').css('cursor','pointer').click(function() { actionCall(2) });
	$('#cntrls img.c3').css('cursor','pointer').click(function() { actionCall(3) });
	$('#cntrls img.c4').css('cursor','pointer').click(function() { actionCall(4) });
	$('#cntrls img.c5').css('cursor','pointer').click(function() { actionCall(5) });
});
// you can change these values
var delay = 10000;
var playCountMax = 3
// do not change these values
var playCount = 0;
var timeOne = 0;
var timeTwo = 0;
var timeThree = 0;
var timeFour = 0;
var timeFive = 0;
var timeNext = 0;
function playHome() {
	$('#homeSlide').css('background-image','none');
	actionCall(1);
}
function show1() {
	playCount++;
	$('#slide5').fadeOut('slow');
	$('#cntrls div.c5').fadeOut('slow');
	$('#slide1').fadeIn('slow', function() { timeOne = setTimeout("show2()",delay); });
	$('#cntrls div.c1').fadeIn('slow');
}
function show2() {
	if (playCount <= playCountMax) {
		$('#slide1').fadeOut('slow');
		$('#cntrls div.c1').fadeOut('slow');
		$('#slide2').fadeIn('slow', function() { timeTwo = setTimeout("show3()",delay); });
		$('#cntrls div.c2').fadeIn('slow');
	}
}
function show3() {
	if (playCount <= playCountMax) {
		$('#slide2').fadeOut('slow');
		$('#cntrls div.c2').fadeOut('slow');
		$('#slide3').fadeIn('slow', function() { timeThree = setTimeout("show4()",delay); });
		$('#cntrls div.c3').fadeIn('slow');
	}
}
function show4() {
	if (playCount <= playCountMax) {
		$('#slide3').fadeOut('slow');
		$('#cntrls div.c3').fadeOut('slow');
		$('#slide4').fadeIn('slow', function() { timeFour = setTimeout("show5()",delay); });
		$('#cntrls div.c4').fadeIn('slow');
	}
}
function show5() {
	if (playCount <= playCountMax) {
		$('#slide4').fadeOut('slow');
		$('#cntrls div.c4').fadeOut('slow');
		$('#slide5').fadeIn('slow', function() { timeFour = setTimeout("show1()",delay); });
		$('#cntrls div.c5').fadeIn('slow');
	}
}
function actionCall(sec) {
	clearTimeout(timeNext);
	if (sec <= 4) {
		var nextSec = sec + 1;
	} else {
		var nextSec = 1;
	}
	clearTimeout(timeOne);
	clearTimeout(timeTwo);
	clearTimeout(timeThree);
	clearTimeout(timeFour);
	clearTimeout(timeFive);
	$('#homeSlide div').fadeOut('fast');
	$('#cntrls div').fadeOut('fast');
	$('#slide' + sec + '').fadeIn('slow');
	$('#cntrls div.c' + sec + '').fadeIn('slow');
	// continuous play control, comment for no autoplay
	if (playCount <= playCountMax) {
		timeNext = setTimeout("show" + nextSec + "()",delay);
	}
}