var TimerLeft = Class.create();

TimerLeft.prototype = {
	initialize : function(DivId) {
		this.div_id=DivId;
		all_seconds=$(this.div_id).innerHTML;
		if(all_seconds>0)
		{
			all_minutes=Math.floor(all_seconds/60);
			all_hours=Math.floor(all_minutes/60);
			all_days=Math.floor(all_hours/24);
			this.seconds=all_seconds-all_minutes*60;
			this.minutes=all_minutes-all_hours*60;
			this.hours=all_hours-all_days*24;
			this.days=all_days;
			this.can_dec=true;
			this.can_refresh=true;
		}
		else
		{
			this.can_dec=false;
			this.can_refresh=false;
		}
	},

	DecrementSecond: function (){
		if(this.seconds>0)
		{
			this.seconds--;
		}
		else if(this.minutes>0)
		{
			this.seconds=59;
			this.minutes--;
		}
		else if(this.hours>0)
		{
			this.seconds=59;
			this.minutes=59;
			this.hours--;
		}
		else if(this.days>0)
		{
			this.seconds=59;
			this.minutes=59;
			this.hours=23;
			this.days--;
		}
		else
		{
			this.can_dec=false;
			if(this.can_refresh)
			{
				window.location.reload();
			}
		}

		var str='';

		if(this.days>0)
		{
			str=this.days+timer_day+' ';
		}
		str+=((this.hours>9)?this.hours:("0"+this.hours))+':'+((this.minutes>9)?this.minutes:("0"+this.minutes))+':'+((this.seconds>9)?this.seconds:("0"+this.seconds));
		if(!this.can_dec)
		{
			str='00:00:00';
		}
		$(this.div_id).innerHTML=str;
		setTimeout(this.DecrementSecond.bind(this), 1000);
	},


	onTimerEvent: function() {
			this.DecrementSecond();
	},


	StartTimer: function (){
		this.timer = setInterval(this.onTimerEvent.bind(this), 1000);
	}
}

TimerLeft.methods = {


}