/***********************************************
* Dynamic Countdown script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function checkTime(i, threshold) {
	if (i<threshold)
	{
		i="0" + i;
	}
	return i;
}

function cdtime(container, targetdate) {
	if (!document.getElementById || !document.getElementById(container)) return
	this.container=document.getElementById(container)
	this.currentTime=new Date()
	this.targetdate=new Date(targetdate)
	this.timesup=false
}

cdtime.prototype.displaycountdown=function(baseunit, functionref) {
	this.baseunit=baseunit
	this.formatresults=functionref
	this.showresults()
}

cdtime.prototype.showresults=function() {
	var thisobj=this
	this.currentTime = new Date();
	var timeDifference=(this.targetdate-this.currentTime) //difference btw target date and current date, in milliseconds
	if (timeDifference<0) { //if time is up
		this.timesup=true
		this.container.innerHTML=this.formatresults()
		return
	}

	var dayfield = Math.floor((((timeDifference/1000)/60)/60)/24);
	var hourfield = Math.floor((((timeDifference/1000)/60)/60) % 24);
	hourfield = checkTime(hourfield, 10);
	var minutefield = Math.floor(((timeDifference/1000)/60) % 60);
	minutefield = checkTime(minutefield, 10);
	var secondfield = Math.floor((timeDifference/1000) % 60);
	secondfield = checkTime(secondfield, 10);
	var millisecondfield = (timeDifference % 1000);
	millisecondfield = checkTime(millisecondfield, 10);
	millisecondfield = checkTime(millisecondfield, 100);

	this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield, millisecondfield)
	setTimeout(function(){thisobj.showresults()}, 1) //update results every millisecond
}

function formatresults() {
	if (this.timesup==false){//if target date/time not yet met
		var displaystring=arguments[0]+": "+arguments[1]+": "+arguments[2]+": "+arguments[3]+": "+arguments[4];
	}
	else{ //else if target date/time met
		var displaystring="Happy New Year!"
	}
return displaystring
}
