var tstart=0;
var tout=0;

var menu_c=false;
var he=0;

var _rychlost=4;

function _$(a){
	var b=document.getElementById(a);
	return (b?b:document.getElementsByName(a)[0]);
}

function _z(a, t){
	if (a>he && tstart>0){
		_$("menu_z").style.height=a+"px";
		if (a==181)
			t=100;
		tra(_$("menu_z"),t);
		he=a;
	}
}

function mz(){
	if (tstart>0 && tstart!=500 && tstart!=1000){
		clearTimeout(tstart);
		tstart=0;
	}
}

function _s(a,t){
	if (a<he && tstart==0){
		_$("menu_z").style.height=a+"px";
		tra(_$("menu_z"),t);
		he=a;

		if (a==21){
			_$("menu_z").style.display="none";
			clearTimeout(tstart);
			clearTimeout(tout);
			tstart=tout=0;
		}
	}
}

function skryt(){
	return;
	for (var i=181;i>30;i--)
		setTimeout("_z("+i+")",(181-i)*2);
}

function menu(zob){
	clearTimeout(tout);
	tout=0;
	
	if (zob && tstart==0){
		tstart=setTimeout("start()",500);
		//tout=setTimeout("stop()",2000);
	}else if (!zob && tstart==1000){
		tout=setTimeout("stop()",700);
	}
}

function stop(){
	tstart=0;
	for (var i=181;i>20 && tstart==0;i-=5)
		setTimeout("_s("+i+","+((100/161)*(i-20))+")",(181-i)*_rychlost);
	/*
	if (tstart==0)
		_$("menu_z").style.display="none";
	*/
}

function tra(a,b){
	a.style.opacity=b/100;
	a.style.MozOpacity=b/100;
	a.style.KhtmlOpacity=b/100;
	a.style.filter="alpha(opacity="+b+")";
}

function start(){
	tstart=500;
	var x=_$("menu_z");
	x.style.overflow="hidden";
	x.style.height="1px";
	x.style.display="none";
	x.style.position="absolute";
	x.style.top="125px"
	x.style.zIndex="100";
	x.style.marginLeft="-495px";
	x.style.left="50%";
	//x.style.top="93px";
	x.style.top="93px";//109
	x.style.textAlign="left";
	tra(x,0);
	//x.innerHTML="";
	
	if (menu_c==false){
		req("/menu_lo.php",menu_l);
	}else{
		menu_l("");
	}
}

function l(a){
	var l=0;
	if (a.offsetParent)
		do{
			l+=a.offsetLeft;
		}while (a=a.offsetParent);
	return l;
}

function menu_l(a){
	menu_c=true;
	var x=_$("menu_z");
	if (a!="")
		x.innerHTML=a;
	
	x.style.display="block";
	for (var i=21;i<182 && tstart>0;i+=5)
		setTimeout("_z("+i+","+(100/161*(i-21))+")",(i-31)*_rychlost);
	
	//x.style.height="181px";
	tstart=1000;
}
function rx(){
	if (!window.XMLHttpRequest){
 		try{ return new ActiveXObject("MSXML3.XMLHTTP") }catch(e){}
    try{ return new ActiveXObject("MSXML2.XMLHTTP.3.0") }catch(e){}
    try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
    try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
    throw new Error("Could not find an XMLHttpRequest alternative.")
  }else{
  	return new XMLHttpRequest();
  }
}

function req(url,callbackFunction){
	var request=rx();
	if (request==null) return false;
	
  request.open("GET",url,true);
  request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
  request.onreadystatechange=function(){
  	
  	if (request.readyState==4 && request.status==200){
    	if (request.responseText){
      	callbackFunction(request.responseText);
     	}
   	}
  };
  request.send("");
  return true;
}

function css(a,b){
/*
	if (a==0)
		css="zilina2.css";
	else
		css="css.php?c="+a;
	_$("menu_z").innerHTML=_$("menu_z").innerHTML+'<link rel="stylesheet" type="text/css" href="/'+css+'" title="default" media="all" />';
	b.href="#";
	b="#";
*/
}

function homepage(){
/*
	try{
		if (1 || document.all){
			document.body.style.behavior='url(#default#homepage)';
			document.body.setHomePage('http://www.zilina.sk/');
		}
	}catch (e){
	}
*/
	var d=["Žilina - oficiálne stránky mesta","http://www.zilina.sk"];

	if (window.sidebar){
		window.sidebar.addPanel(d[0],d[1],'');
	}else if (window.opera && window.print){
		var a=document.createElement('a');
		a.rel="sidebar";
		a.target="_search";
		a.title=d[0];
		a.href=d[1];
		a.click();
	}else{
        window.external.AddFavorite(d[1],d[0]);
	}
}

