$(document).ready(function(){

	// GET CURRENT DATE AND TIME, FIGURE DAYS, HOURS, MINUTES, SECONDS LEFT
	var dthen = new Date('3/17/2010 8:00 PM');
	var dnow = new Date();

	var ddiff = new Date(dthen-dnow);
	
	var gsecs = Math.floor(ddiff.valueOf()/1000);
	//alert(dthen + ' - ' + dnow + ' = ' + gsecs);
	
	// SET INITIAL DAYS, HOURS, MINUTES, SECONDS
	var counterDays = Math.floor(gsecs/86400);
	gsecs = gsecs - counterDays*86400;
	var counterHours = Math.floor(gsecs/3600);
	gsecs = gsecs - counterHours*3600;
	var counterMinutes = Math.floor(gsecs/60);
	var counterSeconds = gsecs - counterMinutes*60;
	
	$("#countdownRegistration td.counterDays").html(counterDays);
	$("#countdownRegistration td.counterHours").html(counterHours);
	$("#countdownRegistration td.counterMinutes").html(counterMinutes);
	$("#countdownRegistration td.counterSeconds").html(counterSeconds);
	
	setTimeout("degradeSeconds();",1000);

})

function degradeSeconds(){
	
	//alert("time recycling...");
	
	var secondsLeft = parseInt($("#countdownRegistration td.counterSeconds").html());
	var origSeconds = secondsLeft;
	var minutesLeft = parseInt($("#countdownRegistration td.counterMinutes").html());
	var hoursLeft = parseInt($("#countdownRegistration td.counterHours").html());
	var daysLeft = parseInt($("#countdownRegistration td.counterDays").html());
	
	if(secondsLeft != 0){
		secondsLeft = secondsLeft - 1;
	}
	else{
		secondsLeft = 59;
	}
			
	if(secondsLeft == 0 && parseInt(minutesLeft) > 0){
		//secondsLeft = 59;
		minutesLeft = parseInt(minutesLeft)-1;
	}
	if(minutesLeft == 0 && parseInt(hoursLeft) > 0 && origSeconds == 0){
		minutesLeft = 59;
		hoursLeft = parseInt(hoursLeft)-1;
	}
	if(hoursLeft == 0 && parseInt(daysLeft) > 0 && origSeconds == 0){
		hoursLeft = 23;
		daysLeft = parseInt(daysLeft)-1;
	}
	//alert(daysLeft + ' ' + hoursLeft + ' ' + minutesLeft + ' ' + secondsLeft);
	$("#countdownRegistration td.counterDays").html(daysLeft);
	$("#countdownRegistration td.counterHours").html(hoursLeft);
	$("#countdownRegistration td.counterMinutes").html(minutesLeft);
	$("#countdownRegistration td.counterSeconds").html(secondsLeft);

	if(secondsLeft!=0||minutesLeft!=0||hoursLeft!=0||daysLeft!=0){
		setTimeout("degradeSeconds();",1000);
	}
	
}