var PI = 3.1415927; //lze použít také konstantu Math.PI
polomer = 32;
poziceX = 51;
poziceY = 51;
sekundy = 0;
hodiny = 0;
minuty = 0;

// nastaveni datumu
var ted;

function cas()
{
	setTimeHours();
  	
	setTimeout('cas()', 990);
}

function setTimeHours()
{
	ted = new Date();
	
	var tedTZL = new Date();
	var msie = navigator.userAgent.indexOf("MSIE")
	var TZL = tedTZL.getTimezoneOffset();
	if( msie > -1 ) 
	{
    	if( navigator.userAgent.substring( msie+5, msie+6 ) <= 3 ) TZL *= -1;
    	else if( navigator.userAgent.indexOf( "4.0b2" ) > -1 ) TZL += 60;
 	}
	
	ted.setTime( tedTZL.getTime() + ( TZL * 60000 ) );
	
	hodiny = ted.getHours();
	//alert( hodiny );
	hodiny = setSummerTime( hodiny, ted.getMonth(), 3, 11 );
	//alert( hodiny );
	hodiny = setHour( hodiny, 1 );
	minuty = ted.getMinutes();
	sekundy = ted.getSeconds();
}

 function setHour( hod, posun )
 {
  	var out = 0;
	
	out = hod * 1 + posun;
	if( out > 23 ) out-= 24;
	if( out < 0 ) out = 24 + out;
	
	return out;
 }
  
  
 function setSummerTime( hod, tedMes, odMes, doMes )
 {
  	var out = hod;
	tedMes = tedMes * 1 + 1;
	
	if( ( tedMes > odMes ) && ( tedMes < doMes ) ) out = out * 1 + 1;
	
	return out;
 }
  
function nastavRucicky()
{
	setTimeHours();
	
	var strImgHod = '/img/hodiny/h_';
	var strImgMin = '/img/hodiny/M_';
	
	var minutyPosun = minuty * 1 + 1;
	if( minutyPosun > 59 ) minutyPosun = minutyPosun * 1 - 60;
	if( minutyPosun == 0 ) minutyPosun = 60;
	
	var hodinyPosun = hodiny;
	if( hodinyPosun > 11 ) hodinyPosun = hodinyPosun * 1 - 12;
	hodinyPosun = hodinyPosun * 5;
	if( minuty > 12 ) hodinyPosun = hodinyPosun * 1 + 1;
	if( minuty > 24 ) hodinyPosun = hodinyPosun * 1 + 2;
	if( minuty > 36 ) hodinyPosun = hodinyPosun * 1 + 3;
	if( minuty > 48 ) hodinyPosun = hodinyPosun * 1 + 4;
	if( hodinyPosun > 59 ) hodinyPosun = hodinyPosun * 1 - 60;
	if( hodinyPosun == 0 ) hodinyPosun = 60;
	
	var strHod = '000' + hodinyPosun;
	var strMin = '000' + minutyPosun;
	
	strMin = strMin.substring( strMin.length - 4 );
	//alert( strMin );
	
	strHod = strHod.substring( strHod.length - 4 );
	//alert( strHod );
	
	strImgHod = '/img/hodiny/h_' + strHod + '.gif';
	strImgMin = '/img/hodiny/M_' + strMin + '.gif';
	//alert( strImgHod + ' - ' + strImgMin );
	 
	imgHod.src = strImgHod;
	imgMin.src = strImgMin;
	
	setTimeout( 'nastavRucicky()', 60 * 990 );
}


function cifernik()
{
	var cif = 3;
	for (i = 0; i < (11/6)*PI; i+=((1/6)*PI))
	{
		if( cif <= 9 )
		{
			x = poziceX + polomer * Math.cos(i);
		}
		else
		{
			x = (poziceX + polomer * Math.cos(i))-4; //pokud je cislo dvouciferne zmensi se x souradnice
		}
	y = poziceY + polomer * Math.sin(i);
	if( cif >= 12 ) cif = 1;
	cif++;
	cifernik.innerHTML += '<div style="position:absolute; top:' + y +'; left:' + x + '; font-family: Courier; font-weight: bold;">'+cif+'</div>';
	}
}


function sekundovka()
{
	sec.innerHTML = '';
	//sec.innerHTML = '<img src="" border="0" width="300" height="300" />';
	for (i = 30; i >= 5; i-=1)
	{
		sX = poziceX + (polomer - i) * Math.cos((sekundy/30)*PI-PI/2);
		sY = (poziceY + (polomer - i) * Math.sin((sekundy/30)*PI-PI/2)) +2;
		sec.innerHTML += ('<div style="position: absolute; color: #8d7050; left:'+sX+'px; top:'+sY+'px;">.</div>');
	}
	//alert( sec.innerHTML );
	setTimeout('sekundovka()',990);
}

function hodinovka()
{
	hod.innerHTML = '';
	for (i = 30; i >= 12; i-=1)
	{
		sX = poziceX + (polomer - i) * Math.cos((hodiny/6 + minuty/360)*PI-PI/2);
		sY = (poziceY + (polomer - i) * Math.sin((hodiny/6 + minuty/360)*PI-PI/2))+1;
		width = 4;
		height = 4;
		
		/*
		width = 1;
		height = 1;
		if( i > 25 )
		{
			width = 4;
			height = 4;
		}
		if( i > 20 && i <= 25 )
		{
			width = 3;
			height = 3;
		}
		if( i > 15 && i <= 20 )
		{
			width = 2;
			height = 2;
		}
		*/
		//if( i < 18 )
		//{
			hod.innerHTML += ('<div style="position: absolute; color: #cc9933; left:'+sX+'px; top:'+sY+'px;"><img src="/img/rucicka.gif" width="'+width+'" height="'+height+'" /></div>');
		//}
		//else
		//{
		//	hod.innerHTML += ('<div style="position: absolute; color: #cc9933; left:'+sX+'px; top:'+sY+'px;"></div>');
		//}
	}
}

var x = 0;
function minutovka()
{
	min.innerHTML = '';
	x = minuty;
	for (i = 30; i >= 5; i-=1)
	{
		sX = poziceX + (polomer - i) * Math.cos((minuty/30)*PI-PI/2);
		sY = (poziceY + (polomer - i) * Math.sin((minuty/30)*PI-PI/2)) +1 ;
		min.innerHTML += ('<div style="position:absolute; color: #996600; left:'+sX+'px; top:'+sY+'px;"><img src="/img/rucicka.gif" width="4" height="3" /></div>');
	}
	setInterval('if (x!=minuty) minutovka(),hodinovka();',990);
}


