//countdown.js - odpocitavadlo
//source: http://scripts.franciscocharrua.com/countdown-clock.php
//charset: UTF-8

function countdown_clock(year, month, day, hour, minute, format)
	{
		//zvolíme si div jako tag pro odpočítávadlo
		var rand = Math.round(Math.random()*1000);
		var div_id = 'c'+rand;
		html_code = '<div id="'+div_id+'" class="countdown-en" style="'+countdown_style+'">countdown<\/div>';

		document.write(html_code);
		countdown(year, month, day, hour, minute, format, div_id);
	}

function countdown(year, month, day, hour, minute, format, div_id)
	{
		Today = new Date();
		Todays_Year = Today.getFullYear() - 2000;
		Todays_Month = Today.getMonth() + 1;

		//převedeme oba datumy na milisekundy
		Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
		Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();

		//vypočteme rozdíl a převedeme ho na sekundy
		Time_Left = Math.round((Target_Date - Todays_Date) / 1000);

		if(Time_Left < 0)
			Time_Left = 0;

		switch(format)
			{
				case 0:
					//nejlehčí cesta jak vypsat zbývající čas
					document.getElementById(div_id).innerHTML = Time_Left + ' seconds';
				break;
				case 1:
					//více podrobné (upraveno na univerzální)
					days = Math.floor(Time_Left / (60 * 60 * 24));
					Time_Left %= (60 * 60 * 24);
					hours = Math.floor(Time_Left / (60 * 60));
					Time_Left %= (60 * 60);
					minutes = Math.floor(Time_Left / 60);
					Time_Left %= 60;
					seconds = Time_Left;

					//převedení na dvouciferný formát
					if(days    < 10)    days = "0" + days;
					if(hours   < 10)   hours = "0" + hours;
					if(minutes < 10) minutes = "0" + minutes;
					if(seconds < 10) seconds = "0" + seconds;

					//zápis do tagu
					document.getElementById(div_id).innerHTML  = days + ' days, ';
					document.getElementById(div_id).innerHTML += hours + ' hours, ';
					document.getElementById(div_id).innerHTML += minutes + ' minutes, ';
					document.getElementById(div_id).innerHTML += seconds + ' seconds';
				break;
				default:
					document.getElementById(div_id).innerHTML = Time_Left + ' seconds';
			}

		//rekrusivní volání, při hodinovém impulsu
		setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ', \'' + div_id + '\');', 1000);
	}