var grand_prix_countdown = function () {
	var time_left = 10; //number of seconds for countdown
	var output_element_id = 'grand_prix_countdown_time';
	var keep_counting = 1;
 
	function countdown() {
		if(time_left <= 0) {
			keep_counting = -1;
		}
 
		time_left = time_left - 1 * keep_counting;
	}
 
	function add_leading_zero(n) {
		if(n.toString().length < 2) {
			return '0' + n;
		} else {
			return n;
		}
	}
 
	function format_output() {
		var days, hours, minutes, seconds, sign = '';
		seconds = time_left % 60;
		minutes = Math.floor(time_left / 60) % 60;
		hours = Math.floor(time_left / 3600) % 24;
		days = Math.floor(time_left / 86400);
 
		seconds = add_leading_zero( seconds );
		minutes = add_leading_zero( minutes );
		hours = add_leading_zero( hours );
		days = add_leading_zero( days );
 
		if (keep_counting<0) {
			sign='-';
		}
		
		return sign + days + ':' + hours + ':' + minutes + ':' + seconds;
	}
 
	function show_time_left() {
		document.getElementById(output_element_id).innerHTML = format_output(); //time_left;
	}
 
	return {
		count: function () {
			countdown();
			show_time_left();
		},
		timer: function () {
			grand_prix_countdown.count();
			setTimeout("grand_prix_countdown.timer();", 1000);
		},
		init: function (t, element_id) {
			time_left = Math.abs(t);
			if (t<0) {
				keep_counting = -1;
			}
			output_element_id = element_id;
			grand_prix_countdown.timer();
		}
	};
}();
