// countdown timer to specified date
// Rob Hutchison
// 19/04/2010
var COUNTDOWNDATE = '09/20/2010 09:00:00';

function getCountdown(id)
{
	currDate = new Date();
	endDate = new Date(COUNTDOWNDATE);  
	timeLeft = (endDate - currDate)/1000; // time to date in seconds
	// check for past date, just in case
	if (timeLeft<0)
	{
		days=0;
		hours=0;
		mins=0;
		secs=0;
	}
	else {
		secs = timeLeft;	
		days = Math.floor((secs / (60*60*24)));
		secs = timeLeft % (60*60*24);
		hours = Math.floor((secs / (60*60)) );
		secs = timeLeft % (60*60);
		mins = Math.floor((secs / 60) );
		secs = (timeLeft % 60).toFixed(0);
	}
	daysLabel = days == 1 ? '&nbsp;day ' : '&nbsp;days ';
	hoursLabel = hours == 1 ? '&nbsp;hour ' : '&nbsp;hours ';
	minsLabel = mins == 1 ? '&nbsp;minute ' : '&nbsp;minutes ';
	secsLabel = secs == 1 ? '&nbsp;second&nbsp;&nbsp;' : '&nbsp;seconds';
	
	spanStart = '<span class="header_digit" style="width:80px;">';
	spanEnd = '</span>';
	var dest = document.getElementById(id);
	var countdown;
	if (days>9) {
		countdown = spanStart + days+ spanEnd +  daysLabel;
	}
	else
	{
		countdown = spanStart +'0'+ days+ spanEnd + daysLabel;
	}
	if (hours>9) {
		countdown += spanStart + hours+ spanEnd + hoursLabel;
	}
	else
	{
		countdown += spanStart +'0'+ hours+ spanEnd + hoursLabel;
	}
	if (mins>9) {
		countdown += spanStart + mins+ spanEnd + minsLabel;
	}
	else
	{
		countdown += spanStart +'0'+ mins+ spanEnd + minsLabel;
	}
	if (secs>9) {
		countdown += spanStart + secs+ spanEnd + secsLabel;
	}
	else
	{
		countdown += spanStart +'0'+ secs+ spanEnd + secsLabel;
	}
	if(dest!=null)
	{
		dest.innerHTML = countdown;
		setTimeout("getCountdown('"+id+"')",1000);
	}
}
