countdate = "12/24/2009 0:00 AM";
if (typeof(format) == "undefined")
	format = "%D% Days, %H% Hours, %M% Minutes, %S% Seconds.";

var dthen = new Date(countdate);
var dnow = new Date();
ddiff = new Date(dthen-dnow);

createcounter();
docount(Math.floor(ddiff.valueOf()/1000));

function createcounter() {
	document.write("<span id='counter'></span>");
}

function calcage(secs, num1, num2) {
	s = ((Math.floor(secs/num1))%num2).toString();
	if (s.length < 2)
		s = "0" + s;
	return s;
}

function docount(secs) {
	if (secs < 0) {
		$('#counter').html('Det ar jul!');
		return;
	}
	str = format.replace(/%D%/g, calcage(secs,86400,100000));
	str = str.replace(/%H%/g, calcage(secs,3600,24));
	str = str.replace(/%M%/g, calcage(secs,60,60));
	str = str.replace(/%S%/g, calcage(secs,1,60));

	$('#counter').html(str);
	setTimeout("docount(" + (secs-1) + ")", 1000);
}


