var TimeTicker = function(id, to) {
	var interval;
	var element = $(id);
	
	return {
		start: function() {
			var self = this;
			this.countTo();
			interval = setInterval(function() {
				self.countTo();
			}, 1000);
		},
		countTo: function() {
			var now = new Date();
			if(now < to) {
				var totalSecs = Math.floor((to - now) / 1000);
				var totalHrs = Math.floor(totalSecs / 3600);
				var days = Math.floor(totalHrs / 24);
				var hrs = Math.floor(totalHrs % 24);
				var mins = Math.floor(totalSecs / 60 % 60);
				var secs = Math.floor(totalSecs % 60);
				var s = this.zeroPad(days, 2) + ' ' + this.zeroPad(hrs, 2) + ' ' + this.zeroPad(mins, 2) + ' ' + this.zeroPad(secs, 2);
				element.innerHTML = s;
			}
			else {
				element.innerHTML = '00 00 00 00';
				this.stop();
			}
		},
		zeroPad: function(number, count) {
			var pad = count - (number + '').length;
			for(var i = 0; i < pad; i++) {
				number = '0' + number;
			}
			return number;
		},
		stop: function() {
			clearInterval(interval);
		}
	}
};
