var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

setInterval("init('March 31, 2009')", 1000);//Runs the clock every 1 second

function init(dateToCome){
	if(!document.getElementById) return;
	if(!document.getElementById("countDown")) return;
/* Sets the target date and gets the current Date- also creates a display for both */
	var currentDate = new Date();//Get the current date	
	var targetDate = new Date(dateToCome);//Set the count to date
	var currentDateDisplay = months[currentDate.getMonth()] + "  " + currentDate.getDate() + ',  ' + currentDate.getFullYear();//Prepare current date for display
	var targetDateDisplay = months[targetDate.getMonth()] + "  " + targetDate.getDate() + ',  ' + targetDate.getFullYear();	//Prepare target date for display	
	var placeCurrentDate = document.getElementById("currentDate");//Gets the id placeholder for the current date
	placeCurrentDate.innerHTML = "Today is  " + currentDateDisplay;//Places the current date display into the current date placeholder
	var placeTargetDate = document.getElementById("targetDate");//Gets the id placeholder for the target date
	placeTargetDate.innerHTML = "End Date  " + targetDateDisplay;//Places the current date display into the target date placeholder		
/* Gets the difference between the two dates and then calculates time remaining in days, hours, minutes and seconds */
	var timeDifference = targetDate - currentDate;//Get the  difference between the dates
	
	if(timeDifference > 0) {
		var ddays=Math.floor(timeDifference/(60*60*1000*24)*1);//Calculates the days left
		var dhours=Math.floor((timeDifference%(60*60*1000*24))/(60*60*1000)*1);//Calculates the hours left
		var dmins=Math.floor(((timeDifference%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);//Calculates the minutes left
		var  dsecs=Math.floor((((timeDifference%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);//Calculates the seconds left	
/* Displays the time dates and time remaining  */	
		if(ddays > 0) {//If days greater than 0, then show the days in the day placeholder
			var placeDays = document.getElementById("days");
			placeDays.innerHTML = ddays;//Places the current date display into the  days placeholder
		}	
		if(dhours >= 0) {//If hours are greater than 0, show the hours in the hour placeholder
			var placeHours = document.getElementById("hours");//Gets the id placeholder for the hours
			placeHours.innerHTML = dhours;//Places the current date display into the  hours placeholder			
		}
		var placeMinutes = document.getElementById("minutes");//Gets the id placeholder for the minutes placeholder
		placeMinutes.innerHTML = dmins;	//Places the current date display into the  minutes placeholder
		var placeSeconds = document.getElementById("seconds");//Gets the id placeholder for the seconds placeholder
		placeSeconds.innerHTML = dsecs;	//Places the current date display into the  seconds placeholder
	} else {
		var placeCurrentDate = document.getElementById("pastDate");
		placeCurrentDate.className = "displayOn";
		return;
	}//End of check of timeDifference
}


