window.onload=WindowLoad;
function WindowLoad(event) {
	OneHourCountDown("OneHourCountDown", $('main').data("time")); //60sec x 60min = 1hour or 3600 sec
}

var _countDowncontainer=0;
var _currentSeconds=0;
function OneHourCountDown(strContainerID, initialValue) {
	_countDowncontainer = document.getElementById(strContainerID);
	if (!_countDowncontainer) {
		return;
	}
	SetCountdownText(initialValue);
	window.setTimeout("CountDownTick()", 1000);
}
function CountDownTick() {
	if(window.gameOn)
	{
		if (_currentSeconds <= 0) {
			$("#jplayer_wrong").jPlayer("play");
			setTimeout(function(){
				window.location.reload();
			}, 2000);
			return;
		}
		SetCountdownText(_currentSeconds-1);
		window.setTimeout("CountDownTick()", 1000);
	}
}
function SetCountdownText(seconds) {
	_currentSeconds = seconds;
	var minutes=parseInt(seconds/60);
	seconds = (seconds%60);
	var hours=parseInt(minutes/60);
	minutes = (minutes%60);
	var strText = AddZero(hours) + ":" + AddZero(minutes) + ":" + AddZero(seconds);
	_countDowncontainer.innerHTML = strText;
}
function AddZero(num) {
	return ((num >= 0)&&(num < 10))?"0"+num:num+"";
}