
function Timer(future, obj)
{
	this.future = future;
	this.obj = obj;
	this.years = '0';
	this.months = '00';
	this.days = '00';
	this.hours = '00';
	this.minutes = '00';
	this.seconds = '00';
	this.calculate = calculate;
	this.format = format;
	this.show = show;
}

function calculate()
{		
	var end_date = new Date(), now = new Date();
	end_date.setTime(this.future);
	var times = Math.round((end_date.getTime() - now.getTime()) / 1000 + end_date.getTimezoneOffset() * 60);
	var residue = 0;
	if(times < 0)
		return false;
	this.years = Math.floor(times / 31556926);
	residue = times % 31556926;
	this.months = Math.floor(residue / 2629744);
	residue %= 2629744;
	this.days = Math.floor(residue / 86400);
	residue %= 86400;
	this.hours = Math.floor(residue / 3600);
	residue %= 3600;
	this.minutes = Math.floor(residue / 60);
	residue %= 60;
	this.seconds = Math.floor(residue);
	this.format();
}
		
function format()
{
	this.months = this.months > 9 ? this.months : '0' + this.months;
	this.days = this.days > 9 ? this.days : '0' + this.days;
	this.hours = this.hours > 9 ? this.hours : '0' + this.hours;
	this.minutes = this.minutes > 9 ? this.minutes : '0' + this.minutes;
	this.seconds = this.seconds > 9 ? this.seconds : '0' + this.seconds;
}

function show()
{
	this.calculate();
	if(this.obj.year != undefined)
		this.obj.year.innerHTML = this.years;
	if(this.obj.month != undefined)
		this.obj.month.innerHTML = this.months;
	if(this.obj.day != undefined)
		this.obj.day.innerHTML = this.days;
	if(this.obj.hour != undefined)
		this.obj.hour.innerHTML = this.hours;
	if(this.obj.minute != undefined)
		this.obj.minute.innerHTML = this.minutes;
	if(this.obj.second != undefined)
		this.obj.second.innerHTML = this.seconds;
	setTimeout("time.show()", 1000);
}
		
var $getEle = function(id){
	return document.getElementById(id);
};				
