time = {
	endTime: null,
	units: null,
	elm: null,
	debug: false,
	callback: null,

	init: function(endTime, callBack, debug){
		this.endTime = endTime.getTime() / 1000,
		this.units = { 
			min : 60, 
			hour: 60 * 60,
			day : 60 * 60 * 24,
			week: 60 * 60 * 24 * 7 
		};
		if(debug){
			this.debug = true
			this.elm = document.getElementById(debug);
		}
		this.callback = callBack;
		this.timeLeft();
	},

	timeLeft: function(){
		var now = new Date();
		var nowTime = (now.getTime() + (now.getTimezoneOffset() * 1000)) / 1000 ;
		var timeLeft = this.endTime - nowTime;
		
		if(this.debug){
			var weeks = Math.floor( timeLeft / this.units.week )
			var days = Math.floor( (timeLeft - (weeks * this.units.week)) / this.units.day );  // number of seconds 
			var hours = Math.floor( (timeLeft - (weeks * this.units.week) - (days * this.units.day)) / this.units.hour ) ;
			var mins = Math.floor( (timeLeft - (weeks * this.units.week) - (days * this.units.day) - (hours * this.units.hour)) / this.units.min );
			var seconds = Math.floor( (timeLeft - (weeks * this.units.week) - (days * this.units.day) - (hours * this.units.hour) - (mins * this.units.min)) );

			this.elm.innerHTML = 
				'<span class="number">' + weeks + '</span> <span class="name">weeks</span>, ' + 
				'<span class="number">' + days + '</span> <span class="name">days</span>, ' + 
				'<span class="number">' + time.checkTime(hours) + '</span> <span class="name">Hours</span>, ' + 
				'<span class="number">' + time.checkTime(mins) + '</span> <span class="name">Minutes</span>, ' + 
				'<span class="number">' + time.checkTime(seconds) +'</span> <span class="name">Seconds</span> ';
		}
		if(timeLeft < 0){
			this.callback();
		} else {
			setTimeout("time.timeLeft();",500);
		}		
	},
	checkTime: function(i){
		if (i<10) {
	  		i="0" + i;
	  	}
		return i;
	}
}
//window.onload = function(){
//	time.init(new Date(2009, 09, 19, 19, 00, 00, 00), function (){ return;}, 'countdown');
//}