
var contesttimer={
	init:function(){
		contesttimer.label=$('#lastdate');
		contesttimer.to=new Date(1000*$('#contest_info').attr('enddate'));
		contesttimer.process();
	},
	
	process:function(){		
		if (!contesttimer.label) return;
		now = new Date();
		if (contesttimer.to>now)
			var d=new Date(contesttimer.to-now-3*60*60*1000);
		else
			var d=new Date(0-3*60*60*1000);
			
		var dyrem=(d.getDate()<10)?('0'+d.getDate()-1):(d.getDate()-1);
		out=dyrem;
		out+=' '+n2en(dyrem,'дней','день','дня')+', ';
		out+=(d.getHours()<10)?'0'+d.getHours():d.getHours();
		out+=':';
		out+=(d.getMinutes()<10)?'0'+d.getMinutes():d.getMinutes();
		out+=':';
		out+=(d.getSeconds()<10)?'0'+d.getSeconds():d.getSeconds();
		contesttimer.label.html(out);
	}
}

$(function(){
	contesttimer.init();
	setInterval(function(){contesttimer.process();},1000);  
});


