
function CountdownTimer(id, seconds)
{
	this.element = $("#timer_"+id);
	target = seconds;
	this.target = target;
	this.update = update;
	timer = this;
	this.update(timer);
}

function update(timer)
{	
	var now = new Date();
	var diff = Math.max(0, (timer.target) - Math.floor(Date.parse(now.toString()) / 1000));

	var days = Math.floor(diff/86400);
	if(days < 10) days = '0' + days;
	var hours = Math.floor(diff/3600) % 24;
	if (hours < 10) hours = '0' + hours;
	var minutes = Math.floor(diff/60) % 60;
	if (minutes < 10) minutes = '0' + minutes;
	var seconds = diff % 60;
	if (seconds < 10) seconds = '0' + seconds;
	
	timer.element.find(".time").html( days + "<span> : </span>" + hours + "<span> : </span>" + minutes + "<span> : </span>" + seconds );
	
	timer.timeout = setTimeout('timer.update(timer)', 500);
}