// JavaScript Document
var allMonths=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

function olympicCount(yr,m,d){
	
	// Put inot another format - held for later to be resent inot the function
	theyear = yr;
	themonth = m;
	theday = d;
	
	// Set todays date
	var today = new Date();
	
	//Set year
	var todayy = today.getYear();
	
	//Pad year
	if (todayy < 1000) {
		todayy += 1900;
	}
	
	//Get the rest of todays date params
	var todaym = today.getMonth();
	var todayd = today.getDate();
	var todayh = today.getHours();
	var todaymin = today.getMinutes();
	var todaysec = today.getSeconds();
	
	//Set date as string for comparison
	var todaystring = allMonths[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
	
	//Start of future date
	futurestring = allMonths[m-1]+" "+d+", "+yr;
	
	//Get the time difference (In MilliSeconds)
	dd = Date.parse(futurestring)-Date.parse(todaystring);
	dday = Math.floor(dd/(60*60*1000*24)*1); // Difference in days
	dhour = Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1) // DIfference in hours
	dmin = Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1); // Difference in minutes
	dsec = Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1); // Difference in seconds
	
	//See if the date is the same
	if(dday==0&&dhour==0&&dmin==0&&dsec==1){
		document.getElementById('days').innerHTML = 0;
		document.getElementById('hours').innerHTML = 0;
		document.getElementById('minutes').innerHTML = 0;
		document.getElementById('seconds').innerHTML = 0;
	}
	else {
		
		// Populate the countdown fields
		document.getElementById('days').innerHTML = dday;
		document.getElementById('hours').innerHTML = dhour;
		document.getElementById('minutes').innerHTML = dmin;
		document.getElementById('seconds').innerHTML = dsec;
		
		//Set the function to run again in exactly one second
		setTimeout("olympicCount(theyear,themonth,theday)",1000);
	}
}
