
var countdowns = new Array();

function updateCountDowns(){
	for (var i=0; i<countdowns.length; ++i){
		var cd = countdowns[i];
		cd.timer--;
		if (cd.timer < 0) cd.timer = 0;
		cd.div.innerHTML = countDownHtml(cd.timer);
	}
	setTimeout("updateCountDowns()", 1000);
}

function countDownHtml(s){
	var result = "";
	var t = { h:0, m:0, s:s };
	if (t.s >= 3600){
		t.h = Math.floor( t.s / 3600);
		t.s = t.s - (t.h * 3600);
	}
	if (t.s >= 60){
		t.m = Math.floor( t.s / 60 );
		t.s = t.s - (t.m * 60);
	}
	if (true || t.h > 0){
		result += (t.h >= 0 && t.h < 10) ? "0"+t.h : t.h;
		result += ":";
	}
	if (true || t.h > 0 || t.m > 0){
		result += (t.m >= 0 && t.m < 10) ? "0"+t.m : t.m;
		result += ":";
	}
	result += (t.s >= 0 && t.s < 10) ? "0"+t.s : t.s;
	return result;
}

function addCountDown(id, ct){
	countdowns.push({
		div:document.getElementById(id),
		timer:ct
	});
}

function initTimers(seconds){
	var div = document.getElementById("countdown");
	if (div != null) addCountDown("countdown", seconds);
	if (countdowns.length > 0) { updateCountDowns(); }
}

