/**
 * CzyToWeekend.pl
 *
 * shared styles
 * @author PZ
 */


/* -- setup -- */
var dNow;
var iWeekend, iNow = 0;
var iInterval = 0;


/* -- countdown function -- */
function countDown()
{
	var iTime = iWeekend - (new Date().getTime() + iNow);
	if (iTime<0) 
	{
		bWeekend = true; 
	}
	else
	{
		bWeekend = false;
	}
	var iHours = Math.floor( iTime/(1000*60*60) );
	var iMinutes = Math.floor( iTime/(1000*60) % 60 );
	var iSeconds = Math.floor( iTime/(1000) % 60 );
	if (iMinutes<10) iMinutes = "0"+ iMinutes;
	if (iSeconds<10) iSeconds = "0"+ iSeconds;
	if (iTime>1000)
	{
		sCounter = "";
		if (iHours>0) sCounter += iHours +"h ";
		if (iMinutes>0) sCounter += iMinutes +"m ";
		sCounter += iSeconds +"s";
		document.getElementById("c").innerHTML = sCounter;
	}
	else
	{
		document.getElementById("h").innerHTML = "TAK";
		document.getElementById("p").innerHTML = "weekend! można już świętować!";
		iInterval = window.clearInterval(iInterval);
	}
}


/* -- page setup -- */
function setup()
{
	if (document.getElementById("c")) 
	{
		iWeekend = document.getElementById("w").value;
		dNow = new Date();
		iNow = document.getElementById("i").value - dNow.getTime();

		iInterval = window.setInterval('countDown()', 250);
	}
}

window.onload = setup;


/* -- end -- */