jQuery(function() {
	// homepage
	jQuery.preload('#main_image div', {
		onFinish: playHome
	});

	jQuery('#control_1').click(function() { actionCall(1) });

	jQuery('#control_2').click(function() { actionCall(2) });

	jQuery('#control_3').click(function() { actionCall(3) });
//remove
//	jQuery('#control_4').click(function() { actionCall(4) });
//remove
//	jQuery('#control_5').click(function() { actionCall(5) });
	
});
// you can change these values

var delay = 8000;

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() {
	jQuery('#main_image').css('background-image','none');
	actionCall(1);
}
function show1() {
	playCount++;
//remove
//	jQuery('#slide_5').fadeOut('slow');
//	jQuery('#control_5').removeClass('active');
	jQuery('#slide_3').fadeOut('slow');
	jQuery('#control_3').removeClass('active');
	jQuery('#slide_1').fadeIn('slow', function() { timeOne = setTimeout("show2()",delay); });
	jQuery('#control_1').addClass('active');
}
function show2() {
	if (playCount <= playCountMax) {
		jQuery('#slide_1').fadeOut('slow');
		jQuery('#control_1').removeClass('active');
		jQuery('#slide_2').fadeIn('slow', function() { timeTwo = setTimeout("show3()",delay); });
		jQuery('#control_2').addClass('active');
	}
}
function show3() {
	if (playCount <= playCountMax) {
		jQuery('#slide_2').fadeOut('slow');
		jQuery('#control_2').removeClass('active');
		jQuery('#slide_3').fadeIn('slow', function() { timeThree = setTimeout("show1()",delay); });
		jQuery('#control_3').addClass('active');
	}
}
function show4() {
	if (playCount <= playCountMax) {
		jQuery('#slide_3').fadeOut('slow');
		jQuery('#control_3').removeClass('active');
		jQuery('#slide_4').fadeIn('slow', function() { timeFour = setTimeout("show5()",delay); });
		jQuery('#control_4').addClass('active');
	}
}
function show5() {
	if (playCount <= playCountMax) {
		jQuery('#slide_4').fadeOut('slow');
		jQuery('#control_4').removeClass('active');
		jQuery('#slide_5').fadeIn('slow', function() { timeFour = setTimeout("show1()",delay); });
		jQuery('#control_5').addClass('active');
	}
}
function actionCall(sec) {
	clearTimeout(timeNext);
	if (sec <= 2) {
		var nextSec = sec + 1;
	} else {
		var nextSec = 1;
	}
	clearTimeout(timeOne);
	clearTimeout(timeTwo);
	clearTimeout(timeThree);
//	clearTimeout(timeFour);
//	clearTimeout(timeFive);
	jQuery('#main_image div').fadeOut('fast');
	jQuery('#controls li').removeClass('active');
	jQuery('#slide_' + sec + '').fadeIn('slow');
	jQuery('#control_' + sec + '').addClass('active');
	// continuous play control, comment for no autoplay
	if (playCount <= playCountMax) {
		timeNext = setTimeout("show" + nextSec + "()",delay);
	}
}