﻿var IdTime = null;
var gnHiddenMenuCount = 0;

function outObj(){
  ClearTime();
  IdTime = window.setTimeout("allHiddenMenu()",480);
}

function allHiddenMenu(objId){
	ClearTime();
	for (id=1; id<=gnHiddenMenuCount+100; id++){
		o = getE("ch"+id);
		if (o != null){
			if (id != objId) {o.style.height='1px';o.style.visibility = "hidden";}
		}
	}
}

function chHiddenMenu(chID,pID){
  ClearTime();
	for (id=1; id<=gnHiddenMenuCount+100; id++){
		o = getE("ch"+id);
		if (o != null){
			if(id > pID && id != chID) {o.style.height='1px';o.style.visibility = "hidden";}
		}
	}
}

function onRoot(obj,obj2)
{
// obj - podmenu ktere zobrazime, obj2 rodič obj
if (obj && obj2){
ClearTime();
IdTime=window.setTimeout("onRootTime('"+obj.id+"','"+obj2.id+"')",200);
}
}

function onRootTime(obj,obj2){
  allHiddenMenu(obj);
  ClearTime();
  submenu=document.getElementById(obj);
  rootmenu=document.getElementById(obj2).parentNode;
  
  var x=rootmenu.offsetLeft;
  submenu.style.height='auto';
  submenu.style.left=x.toString()+'px';
  
  var width=submenu.offsetWidth;
  if (x+width+document.getElementById('obsah').offsetLeft >= document.body.clientWidth) x=document.body.clientWidth-document.getElementById('obsah').offsetLeft-width;
  
  submenu.style.top=(0-submenu.offsetHeight).toString()+'px';
  //alert((0-submenu.offsetHeight).toString()+'px');
  //alert(x.toString()+'px');
  submenu.style.width=width.toString()+'px';
  submenu.style.visibility='visible';
  
  //alert(width.toString()+'px');
}

function onChildren(chID,ID,pID){

// zrusim casovac
 ClearTime();
  var objElem = ID;
	var x = 0;
	var y = 0;
//	alert(objElem.parentNode.offsetLeft);
 chHiddenMenu(chID,pID);
	if(getE('ch'+chID)!= null ){

 //   if (x+getE('ch'+chID).offsetWidth+getE('MenuFloat').offsetLeft > document.body.clientWidth) x = x-getE('ch'+pID).offsetWidth-getE('ch'+chID).offsetWidth+2;
  

    x=objElem.parentNode.parentNode.offsetLeft+objElem.offsetWidth;
    //overim zda uz nelezu z obrazovky kdyz ano nastavim doleva - tam musim zachovat rezevu
    //alert(String(document.body.clientWidth) + '>=' +String(x+250));
    
    getE('ch'+chID).style.left=0;
    var width=getE('ch'+chID).offsetWidth;
    if (x+width+document.getElementById('obsah').offsetLeft >= document.body.clientWidth) x = x-objElem.offsetWidth-width;
    getE('ch'+chID).style.left = x.toString()+'px';
    getE('ch'+chID).style.width = width.toString()+'px';
    getE('ch'+chID).style.visibility = "visible";
    getE('ch'+chID).style.height='auto';
 	var y = objElem.parentNode.parentNode.offsetHeight-objElem.offsetTop-getE('ch'+chID).offsetHeight;
  if (y>0) y=0;
  
		getE('ch'+chID).style.top = (objElem.parentNode.parentNode.offsetTop+objElem.offsetTop+y).toString()+'px';
		//alert (objElem.parentNode.offsetTop+objElem.offsetTop)
	}
}

function ClearTime(){
   clearTimeout(IdTime);
   IdTime=null;
}

// inicializace a fce pro posouvání menu


function mnFloatUpd() {
	var vyska, go
  vyska = document.getElementById("obsah").offsetHeight-64;
  oMenu = document.getElementById("MenuFloat");
  if (!oMenu) return;

  mnGo = document.body.clientHeight-38+ document.body.scrollTop-15;
//alert (String(vyska)+' > '+ String(mnGo));


  if (vyska >= mnGo)
  {
     oMenu.style.top=mnGo
     
/*      if (oMenu.style.top=='') oMenu.style.top=mnGo;
      var oMenuPos=Math.round(oMenu.style.top.replace("px",""))
 //     alert (oMenuPos + ' < ' +mnGo);

  if (oMenuPos < mnGo) {
      if (oMenuPos < mnGo-30) {oMenu.style.top=oMenuPos+15}
      else if (oMenuPos < mnGo-15) {oMenu.style.top=oMenuPos+10}
      else if (oMenuPos < mnGo-5) {oMenu.style.top=oMenuPos+5}
      else {oMenu.style.top=oMenuPos+1}
      }
  if (oMenuPos > mnGo) {
      if (oMenuPos > mnGo+30) {oMenu.style.top=oMenuPos-15}
      else if (oMenuPos > mnGo+15) {oMenu.style.top=oMenuPos-10}
      else if (oMenuPos > mnGo+5) {oMenu.style.top=oMenuPos-5}
      else {oMenu.style.top=oMenuPos-1}
      }
      //alert (oMenuPos);*/
	}
	else
	{
	oMenu.style.top='';
	}
	//body.onscroll=function(){mnFloatUpd()};
	tmr = window.setTimeout("mnFloatUpd()",50);
}

function mnInit() { 

  if (!document.getElementById("MenuFloat") || !document.getElementById("obsah")) return;
  
  var vyska;

 tmr = window.setTimeout("mnFloatUpd()",50);
}

//subcatmenu
var acsubmenu,acsubmenuhref,tmrsubcatmenu

function showsubcat(i)
{
if (document.getElementById('cathref'+i))
 {
  if (acsubmenuhref) acsubmenuhref.className='';
  acsubmenuhref=document.getElementById('cathref'+i);
  acsubmenuhref.className='active';
  if(tmrsubcatmenu) {clearTimeout(tmrsubcatmenu);}
    if (acsubmenu) {acsubmenu.style.visibility='hidden';}
  document.getElementById('catimg').src='/img/new/catimg-'+i+'.jpg';
  document.getElementById('subcats0').style.visibility='hidden';
  acsubmenu = document.getElementById('subcats'+i);
  acsubmenu.style.visbility='visible';
 //   alert('/img/new/catimg-'+i+'.jpg');
 }
}

function hidemenusubcat()
{
tmrsubcatmenu = window.setTimeout("hidemenusubcatdelayed()",500);
}

function hidemenusubcatdelayed()
{

if(document.getElementById('catimg')) document.getElementById('catimg').src='/img/new/catimg-welcome.jpg';
if(document.getElementById('subcats0')) document.getElementById('subcats0').style.visibility='visible';
if (acsubmenu) acsubmenu.style.visiility='hidden';
clearTimeout(tmrsubcatmenu);
if (acsubmenuhref) acsubmenuhref.className='';
}

