//Change this message
var countdownCompleteMsg = 'This Sweep has ended';
//Do not change any values below this line
var countdownArray = {};
var timerID;
scriptStart = new Date();
var startMS = scriptStart.getTime();
$(document).ready(function(){
	$.each( $(".countdown"), function(i, n){
		countdownArray[n.id] = $("#"+n.id).text();
		$("#"+n.id).text("Loading...");
	});
	timerID = self.setInterval("updateTime()", 1000);
});
function updateTime()
{
	$.each( countdownArray, function(key, value){
		endMS = value;
		scriptCurrent = new Date();
		currMS = scriptCurrent.getTime();
		diffMS = currMS-startMS;
		if( endMS == 0 || diffMS >= endMS ){
			leftMS = 0;
			$("#"+key).text(countdownCompleteMsg);
		}else{
			leftMS = endMS-diffMS;
			$("#"+key).text(displayCountdown(leftMS));
		}
	});
}
function displayCountdown( timeLeft )
{
	aDay = 86400000;
	aHour = 3600000;
	aMinute = 60000;
	aSecond = 1000;

	days = Math.floor(timeLeft/aDay);
	timeLeft -= aDay*days;
	days = String(days);

	hours = Math.floor(timeLeft/aHour);
	timeLeft -= aHour*hours;
	hours = String(hours);

	minutes = Math.floor(timeLeft/aMinute);
	timeLeft -= aMinute*minutes;
	minutes = String(minutes);

	seconds = Math.floor(timeLeft/aSecond);
	seconds = String(seconds);

	if( days.length < 2 )
		days = "0"+days;
	if( hours.length < 2 )
		hours = "0"+hours;
	if( minutes.length < 2 )
		minutes = "0"+minutes;
	if( seconds.length < 2 )
		seconds = "0"+seconds;

	return days+" days "+hours+"h "+minutes+"m "+seconds+"s";
}

