function zeroPad(num, count) {
	var numZeropad = num + '';
	while(numZeropad.length < count) {
		numZeropad = '0' + numZeropad;
	}
	return numZeropad;
}

function drawEventProgress(leftTime, totalTime, progressBarId, clockId) {
	var progressBar = document.getElementById(progressBarId);
	var clock = document.getElementById(clockId);
	
	var ratio = leftTime / totalTime;
	
	progressBar.style.width = (300 - (ratio * 300)) + 'px';
	
	var seconds = leftTime % 60;
	var minutes = parseInt(leftTime / 60);
	var hours = parseInt(minutes / 60);
	var days = parseInt(hours / 24);
	if (days == 0) {
		clock.innerHTML = zeroPad(hours % 24, 2) + ':' + zeroPad(minutes % 60, 2) + ':' + zeroPad(seconds, 2);
	} else {
		clock.innerHTML = days + ' gün ' + zeroPad(hours % 24, 2) + ':' + zeroPad(minutes % 60, 2) + ':' + zeroPad(seconds, 2);
	}
	
	if (leftTime == 0) {
		window.location.href = window.location.href;
		return;
	}
	
	leftTime--;
	
	setTimeout('drawEventProgress(' + leftTime + ', ' + totalTime + ', "' + progressBarId + '", "' + clockId + '")', 1000);
}


function blink(id, interval) {
	var obj = document.getElementById(id);
	// Flip flop.
	if (obj.style.visibility == 'visible') {
		obj.style.visibility = 'hidden';
	} else {
		obj.style.visibility = 'visible';
	}
	setTimeout("blink('" + id + "', " + interval + ")", interval);
}