Framework.TimeCountDown = Class.create({
	
	id: null,
	
	initialize: function(id)
	{
		this.id = $(id);
		this.time = parseInt(this.id.getClassData('time'), 10);
		this.daysEl = this.id.down('span.days_diff');
		this.hoursEl = this.id.down('span.hours_diff');
		this.minutesEl = this.id.down('span.minutes_diff');
		this.secondsEl = this.id.down('span.seconds_diff');
		
		this.executer = new PeriodicalExecuter(this.update.bind(this), 1);
	},
	
	update: function()
	{
		// debug("Framework.TimeCountDown.update()");
		
		var date = new Date();
		var time = Math.floor(date.getTime() / 1000);
		var diff = this.time - time;
		
		var secondsDiff = 0;
		var minutes = 0;
		var minutesDiff = 0;
		var hours = 0;
		var hoursDiff = 0;
		var days = 0;
		
		if (diff > 0)
		{
			secondsDiff = diff % 60;
			minutes = Math.floor(diff / 60);
			minutesDiff = minutes % 60;
			hours = Math.floor(minutes / 60);
			hoursDiff = hours % 24;
			days = Math.floor(hours / 24);
		}
		
		days = (days < 10) ? "0" + days: days;
		hoursDiff = (hoursDiff < 10) ? "0" + hoursDiff : hoursDiff;
		minutesDiff = (minutesDiff < 10) ? "0" + minutesDiff : minutesDiff;
		secondsDiff = (secondsDiff < 10) ? "0" + secondsDiff : secondsDiff;
		
		/*
		debug("days: " + days);
		debug("hours: " + hoursDiff);
		debug("minutes: " + minutesDiff);
		debug("seconds: " + secondsDiff);
		*/
		
		if (this.daysEl)
		{
			this.daysEl.update(days);
		}
		if (this.hoursEl)
		{
			this.hoursEl.update(hoursDiff);
		}
		if (this.minutesEl)
		{
			this.minutesEl.update(minutesDiff);
		}
		if (this.secondsEl)
		{
			this.secondsEl.update(secondsDiff);
		}
	},
	
	_eoo: true
	
});