$(document).ready(function() {
	
	var timer = window.setInterval("changeMotive()", 5000);
	$("#motive").hover( function(event) {
		stopInterval();
		event.stopPropagation();									
	}, function(event) {
        /*var timer = window.setInterval("changeMotive()", 5000);
		event.stopPropagation(); */
	});
	
	$("#motive a").mouseover(function(){
		setMotive($("#motive a").index(this));																	
	});

});

function changeMotive() {
	actualMotive = (actualMotive < 5 ? ++actualMotive : 0);
	
	/*$("#motive img").fadeOut("fast", function(){
		$(this).attr("src", "/img/"+actualLang+"/hp/motives/hp_motive-"+actualMotive+".jpg");
	});
	
	$("#motive img").fadeIn(300);*/
	$("#motive img").hide();
	$("#motive img").attr("src", "/img/"+actualLang+"/hp/motives/hp_motive-"+actualMotive+".jpg");
	$("#motive img").show();
}

function setMotive(index) {
	actualMotive = index;
	$("#motive img").hide();
	$("#motive img").attr("src", "/img/"+actualLang+"/hp/motives/hp_motive-"+actualMotive+".jpg");
	$("#motive img").show();
}

function stopInterval() {
	clearInterval(timer);
}


var motiveId;
function countdown() {
	rest--;
	hours = rest % 86400;
	days = (rest - hours) / 86400;
	mins = hours % 3600;
	hours = (hours - mins) / 3600;
	secs = mins % 60;
	mins = (mins - secs) / 60;
	
	days = days.toString();
	hours = hours.toString();
	mins = mins.toString();
	secs = secs.toString();
	
	if (days.length == 2) { days = "x"+days;} 
	if (days.length == 1) { days = "xx"+days;}
	
	if (hours.length == 1) { hours = "0"+hours;}
	if (mins.length == 1) { mins = "0"+mins;}
	if (secs.length == 1) { secs = "0"+secs;}
	if (secs.length == 1) { secs = "0"+secs;}
	
	document.getElementById("d1").src = "/img/u/nums/"+days.charAt(0)+".gif";
	document.getElementById("d2").src = "/img/u/nums/"+days.charAt(1)+".gif";
	document.getElementById("d3").src = "/img/u/nums/"+days.charAt(2)+".gif";
	
	document.getElementById("h1").src = "/img/u/nums/"+hours.charAt(0)+".gif";
	document.getElementById("h2").src = "/img/u/nums/"+hours.charAt(1)+".gif";
	
	document.getElementById("m1").src = "/img/u/nums/"+mins.charAt(0)+".gif";
	document.getElementById("m2").src = "/img/u/nums/"+mins.charAt(1)+".gif";
	
	document.getElementById("s1").src = "/img/u/nums/"+secs.charAt(0)+".gif";
	document.getElementById("s2").src = "/img/u/nums/"+secs.charAt(1)+".gif";

	if (rest > 0) {
		window.setTimeout("countdown()", 1000);
	}
}
