var Presentation = {
	_timeDiff: null,
	
	Initialize: function()
	{
		var nstClock = $('clock');
		nstClock.insert(new Element('span',{'id':'countdownLabel'}).update('Race starts in '));
		nstClock.insert(new Element('span',{'id':'metTimer'}));
		
		Presentation._updateClock();
		
		nstClock.setStyle('display','block');
		
		window.setInterval('Presentation._updateClock();',1000);
	},

	_updateClock: function()
	{
		var eventTime = new Date(2012, 4, 21, 8, 15, 0, 0);
 		var now = new Date();
		var eventDiff = Math.floor((eventTime.getTime() - now.getTime()) / 1000);
		if (eventDiff > 0)
		{
			var days = Math.floor(eventDiff / 86400);
			var hours = Math.floor((eventDiff % 86400) / 3600);
			var minutes = Math.floor((eventDiff % 3600) / 60);
			var seconds = eventDiff % 60;
		
			$('metTimer').update(
				((days > 0) ? days + ' day' + ((days > 1) ? 's' : '') + ', ' : '') +
				hours + ':' +
				((minutes < 10) ? '0' : '') + minutes + ':' + 
				((seconds < 10) ? '0' : '') + seconds
			);
		}
		else
		{
			$('clock').update('');
		}
		
	}
}

Event.observe(window, 'load', function() { Presentation.Initialize(); } );

