//new Date(year, month, day, hours, minutes, seconds, milliseconds)
var eventDate= new Date(2010,5,4,9,0,0,0);
//var eventDate= new Date(2010,2,25,14,58,0,0); 
var viewersTimezoneOffset= "";
var daysLeft= "";
var hoursLeft= "";
var minutesLeft= "";
var secondsLeft= "";

$(document).ready(function() {
	calculateTimezoneOffset();
	performCountdown();
});

function calculateTimezoneOffset() {
	var timezoneDate= new Date();
	//The getTimezoneOffset function returns the number of minutes west of GMT the user's/viewer's browser is.  For example, a browser in the New York EST timezone would be 300 minutes off of GMT.  NOTE:  does not factor in Daylight Savings Time.
	viewersTimezoneOffset= (timezoneDate.getTimezoneOffset()*60)*1000;
	
} //end of calculateTimezoneOffset

function performCountdown() {
	calculateRemainingTime(eventDate);
	displayRemainingTime();
	//This will cause the process to repeat every second (1000 milliseconds)
	window.setTimeout("performCountdown()","1000");
} //end of performCountdown function


function calculateRemainingTime(eventDate) {
	var todaysDate= new Date();
	//Factor in the time zone of the viewer's' browser before determining the time between now and the event start time.
	var timeDifference= (eventDate-viewersTimezoneOffset)-todaysDate;
	if (timeDifference > 0)
		{
			//Perform the calculations
			daysLeft= Math.floor((((timeDifference/1000)/60)/60)/24);
			hoursLeft= Math.floor((((timeDifference/1000)/60)/60) % 24);
			minutesLeft= Math.floor(((timeDifference/1000)/60) % 60);
			secondsLeft= Math.floor((timeDifference/1000) % 60);
		}
	else
		{
			//The event has started or is in the past, so replace the countdown with a message
			//$("#countdown").html("<h1>The <strong>Dublin Horse Show<\/strong><\/h1><br class=\"clear\"\>");
			$("#countdown").addClass("hide4print");
		}

}  //end of calculateRemainingTime function

function displayRemainingTime() {
	if (daysLeft > 0)
		{
			if (daysLeft < 2)
				{
					$("#dayLabel").text("Day");
				}
			$("#daysCounter").text(daysLeft);
		}
	else
		{
			$("#daysCounter").text("0");
			$("#daysCounter").parents("ul").parents("div").addClass("hideElement");
		}
		
	$("#hoursCounter").text(hoursLeft);
	$("#minutesCounter").text(minutesLeft);
	$("#secondsCounter").text(secondsLeft);
		
} //end of displayRemainingTime function