	/**
	 * A quick function for getting document
	 * elements.
	 */
	var el = function(n) { return document.getElementById(n); }
	
	/**
	 * Creates the Countdown object.
	 */
	function Countdown(config) {
		this.toDate 		= config.toDate;
		this.dayElements	= config.dayElements;
		this.hourElements	= config.hourElements;
		this.minuteElements	= config.minuteElements;
		this.secondElements	= config.secondElements;
		this.timer		= undefined;
	
		/**
		 * Updates the countdown display.
		 */
		this.update = function() {
			var elapsed = (this.toDate.getTime() 
				- (new Date()).getTime())/1000;
			this.setDisplay(
				this.age(elapsed, Countdown.DAY),
				this.age(elapsed, Countdown.HOUR),
				this.age(elapsed, Countdown.MINUTE),
				this.age(elapsed, Countdown.SECOND)
			);
		};
		
		/**
		 * returns the age
		 */
		this.age = function(seconds, t) {
			if (seconds<=0) { return [0, 0]; }
			var s = ((Math.floor(seconds/t.unit))%t.length).toString();
			return (s.length < 2) 
				? ["0", s] 
				: [s.substring(0, 1), s.substring(1, 2)];
		};
	
		/**
		 * Starts the countdown timer
		 */
		this.setDisplay = function(day, hour, minute, second) {
			this.display(day, this.dayElements);
			this.display(hour, this.hourElements);
			this.display(minute, this.minuteElements);
			this.display(second, this.secondElements);
		};
		
		/**
		 * Does the display
		 */
		this.display = function(num, els) {
			els[0].innerHTML = num[0];
			els[1].innerHTML = num[1];
			els[0].className = "num_"+num[0];
			els[1].className = "num_"+num[1];
		};
		
		// start timer
		var that = this;
		this.timer = setInterval(function(){that.update()}, 250);
	}
	
	/**
	 * some constants
	 */
	Countdown.DAY 		= {unit: 86400, length: 100000};
	Countdown.HOUR 		= {unit: 3600, length: 24};
	Countdown.MINUTE 	= {unit: 60, length: 60};
	Countdown.SECOND 	= {unit: 1, length: 60};

