// JavaScript Document
window.time_left = 0;
window.timer_ID = '';
t = new Array();
for (a=0,b=9; a<=b; a++) {
	t[a] = new Image(); 
	t[a].src = '/img/timer/t_'+a+'.png';
}

function render_value (info,place) {
	if (place!='day') {
		if (info<10) { 
			info = '0'+info;
		}
		else {
			info = '' + info + '';
		}
	}
	else {
		info = '' + info + '';
	}
		out = '';
		for (a=0,b=info.length;a<b;a++) {
			out = out + '<img src="'+t[info[a]].src+'" width=15 border=0>';
		}
		return out;
	
}

function count() {
	days = Math.floor (time_left/60/60/24);
	hours = Math.floor ((time_left-days*24*60*60)/60/60);
	minutes = Math.floor ((time_left-days*24*60*60-hours*60*60)/60);
	seconds = time_left - hours * 60 * 60 - minutes * 60 - days * 24 * 60 * 60;
	document.getElementById('timer').innerHTML = '<center><table cellpadding="2" cellspacing="0" width="190" border="0" style="font-size:12px;"><tr><td width="45" align=center>' + render_value(days,'day') + '</td><td width="45" align=center>' + render_value(hours,'hour') + '</td><td width="45" align=center>' + render_value(minutes,'minute') + '</td><td width="45" align=center>' + render_value(seconds,'second') + '</td></tr><tr><td align=center>дней</td><td align=center>часов</td><td align=center>минут</td><td align=center>секунд</td></tr></table></center>';
	time_left--;
	window.timer_ID = setTimeout("count()",1000);
}

function init_timer (info) {
	clearTimeout(window.timer_ID);
	window.time_left = parseInt(info);
	count();
}
