jQuery(function ($) {

	//change the text below to reflect your own,
	var aMonths = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	
	var EST = -5;
	
	function countdown (year, month, day) {
			
		var theyear = year;
		var themonth = month;
		var theday = day;

		var today = new Date();
		var todayy = today.getYear();

		var gmtHours = -today.getTimezoneOffset() / 60;
		gmtHours = gmtHours - EST;

		// It's the millenia!
		if (todayy < 1000) {
			todayy += 1900;
		}

		var todaym = today.getMonth();
		var todayd = today.getDate();
		var todayh = today.getHours() - gmtHours;
		var todaymin = today.getMinutes();
		var todaysec = today.getSeconds();
		var todayString = aMonths[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec;

		// Requested time
		futureString = aMonths[month - 1] + " " + day + ", " + year;
		
		// Parse the dates and subtract
		iTimestamp = Date.parse(futureString) - Date.parse(todayString);

		dday	= Math.floor(iTimestamp / (60 * 60 * 1000 * 24) * 1);
		dhour	= Math.floor((iTimestamp % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
		dmin	= Math.floor(((iTimestamp % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
		dsec	= Math.floor((((iTimestamp % (60 * 60 * 1000 * 24)) % (60 *60 * 1000)) % (60 * 1000)) / 1000 * 1);

		if (dday == 0 && dhour == 0 && dmin == 0 && dsec == 1) {

			console.log(current);
			return
		}
		else {

			// Pad with 0's
			if (dday < 10) {
				dday = '0' + dday;
			}
			if (dhour < 10) {
				dhour = '0' + dhour;
			}
			if (dmin < 10) {
				dmin = '0' + dmin;
			}
			if (dsec < 10) {
				dsec = '0' + dsec;
			}
			
			//console.log("Only " + dday + " days, " + dhour + " hours, " + dmin + " minutes, and " + dsec + " seconds left until ");
			
			$('#countdown_days').html(dday);
			$('#countdown_hours').html(dhour);
			$('#countdown_minutes').html(dmin);
			$('#countdown_seconds').html(dsec);
			
			setTimeout(function () {
				countdown(theyear, themonth, theday);
			}, 1000);
		}
		
	}
	
	//enter the count down date using the format year/month/day
	countdown(2012, 2, 2);
	
});

