var _countDowncontainer=0;
var _currentSeconds=0;
 
function ActivateCountDown(strContainerID, targetDate) {
    _countDowncontainer = document.getElementById(strContainerID);
    
    if (!_countDowncontainer) {
        alert("count down error: container does not exist: "+strContainerID+
            "\nmake sure html element with this ID exists");
        return;
    }

	var dthen = new Date(targetDate);
	var dnow = new Date();
	ddiff = new Date(dthen-dnow);
    
    SetCountdownText(Math.floor(ddiff.valueOf()/1000));
    window.setTimeout("CountDownTick()", 1000);
}
 
function CountDownTick() {
    if (_currentSeconds <= 0) {
        alert("Welcome to OutGames Copenhagen 2009!");
        return;
    }
    
    SetCountdownText(_currentSeconds-1);
    window.setTimeout("CountDownTick()", 1000);
}
 
function SetCountdownText(seconds) {

	//store:
    _currentSeconds = seconds;

    //get minutes:
    var minutes=parseInt(seconds/60);
    
    //shrink:
    seconds = (seconds%60);
    
    //get hours:
    var hours=parseInt(minutes/60);
    
    //shrink:
    minutes = (minutes%60);

	//get days:
    var days=parseInt(hours/24);
    
    //shrink:
    hours = (hours%24);

    //build text:
	var strText = "<h4>OutGames 2009 ";
	if (_currentSeconds < 0)
		strText = strText + "are open!";
	else
	{
		strText = strText + "opening ceremony in " + days + " day";
		if (days != 1)
			strText = strText + "s";
		strText = strText + ", " + hours + " hour";
		if (hours != 1)
			strText = strText + "s";
		strText = strText + ", " + minutes + " minute"
		if (minutes != 1)
			strText = strText + "s";
		strText = strText + " and " + seconds + " second";
		if (seconds != 1)
			strText = strText + "s";
	}
	strText = strText + "</h4>";
    
    //apply:
    _countDowncontainer.innerHTML = strText;
}
 
