function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}



   //
   //document.getElementById("pd1").style.visibility="hidden";
  
var actualMenu = null;
var actualSubMenu = null;
   
var xsize = 30;
   
function hideAllmenu() {
	for (i = 0; i < 300 ; i++) {
		e = document.getElementById('menu' + i);
		if (e != null) {
			if (actualMenu == 'menu' + i || actualSubMenu == 'menu' + i) {
				e.style.visibility = "visible";
			} else {
				e.style.visibility = "hidden";
			}
		}
	}
}
   
function showmenu(linkID, menuID, direction, parent, level, second) {
	  
	par = parent;
	fromTop = (level)*24;
	
	// nastavi posunutie podla prehliadaca
	ie = navigator.userAgent.indexOf('MSIE') != -1 ? true : false;
	opera = navigator.userAgent.indexOf('Opera') != -1 ? true : false;
	if (opera) {
		plusY = 25;
		plusX = 10;
		fftop = 6;
	}
	else if (ie) {
		plusY = 20; 
		plusX = 0;
		fftop = 1;
	}
	else {
		plusY = 20;
		plusX = 0;
		fftop = 23;
	}
   	  
   	  
	if (second) {
		plusX = plusX - 25;
		if (ie) plusY = plusY - 3;
	}
   	  
	linka = document.getElementById(linkID);
	  
	if (direction == 0) {
		if (actualMenu == null) actualMenu = menuID;
		if (menuID != actualMenu) {
			
			actualMenu = menuID;
			hidemenu(menuID);
		}
	}
	  
	if (direction == 1) {
		if (actualSubMenu == null) actualSubMenu = menuID;
		
		if (menuID != actualSubMenu) {
			
			actualSubMenu = menuID;
			hidemenu(menuID);
		}
	}
	  
	
	if (direction != 1) {
		elem = document.getElementById(actualMenu);  
		if (elem != null) {
			if (direction != 0) {
				elem.style.left = linka.offsetWidth + plusX - xsize + 28 + 'px';
				elem.style.top =  fromTop - 3 +  'px' ;
			} else {
				elem.style.left = findPosX(linka) + plusX  + 'px';
				elem.style.top = findPosY(linka) + plusY + 14 - fftop + 'px' 
			}
			//elem.style.visibility = "visible";
		}
	} else {
	
		elem = document.getElementById(actualSubMenu);  
		if (elem != null) {
			if (direction != 0) {
				elem.style.left = linka.offsetWidth + plusX - xsize + 28 + 'px';
				elem.style.top =  fromTop - 3 +  'px' ;
			} else {
				elem.style.left = findPosX(linka) + plusX  + 'px';
				elem.style.top = findPosY(linka) + plusY + 14 - fftop + 'px' 
			}
			//elem.style.visibility = "visible";
		}
	}
	
	hideAllmenu();
	  
}
   
   function hidemenu(menuID) {
   	   
   	  
   	  
      actualMenu = null;
      //hideAllmenu();
      //setTimeout("hideAllmenu()", 1000);
      
   	  
   	  //setTimeout("changeK()", 500);
   	  
      
      //if (actualMenu != menuID) {
      	//setTimeout("hm('" + menuID + "')", 1);
      //}
      
      //setTimeout("changeActual('" + menuID + "')", 300);
      //hm(menuID);
      //alert('vypni menu ' + menuID);
   }
   
   function changeK() {
   	  actualMenu = null;
      //hideAllmenu();
   }
   
   //function changeActual(menuID) { actualMenu = null; }
   
   function hm(menu) {
   	  m = document.getElementById(menu);
   	  if (m != null) {
      	//m.style.visibility = "hidden";
   	  }
      //alert("kuk");
   }
   
   
   function hideNow(elemID) {
   	/*
       e = document.getElementById(elemID);
       if (e != null) {
	       document.getElementById(elemID).style.visibility = "hidden";
       }
       */
		//setTimeout("hm('"+elemID+"')", 1);
		
		//actualSubMenu = null;
        //hideAllmenu();
        
        setTimeout("changeT()", 3000);
   }
   
   
	function changeT() {
		actualSubMenu = null;
        //hideAllmenu();
	}
   
	var oldActual = null;
	var oldSubActual = null;
	
	function clearAll() {
		oldActual = actualMenu;
		oldSubActual = actualSubMenu;
		setTimeout("clearAllAndHide()", 3000);
	}
	
	function clearAllAndHide() {
		if (oldActual == actualMenu && oldSubActual == actualSubMenu) {
			actualMenu = null;
			actualSubMenu = null;
			hideAllmenu();
		}
	}
	
   /*
   menuIframe = function() {

                var uLists = document.getElementById("topmenu").getElementsByTagName("UL");
        
                
                for (j=0; j<uLists.length; j++) {
                        uLists[j].innerHTML = ('<iframe src="about:blank" scrolling="no" frameborder="0"></iframe>' + uLists[j].innerHTML);
                        var par = uLists[j].firstChild;
                        par.style.width=uLists[j].offsetWidth+"px";
                        par.style.height=uLists[j].offsetHeight+"px";   
                        uLists[j].style.zIndex="99";
                }
    
    uLists = document.getElementById("sm").getElementsByTagName("UL");
        
                
                for (j=0; j<uLists.length; j++) {
                        uLists[j].innerHTML = ('<iframe src="about:blank" scrolling="no" frameborder="0"></iframe>' + uLists[j].innerHTML);
                        var par = uLists[j].firstChild;
                        par.style.width=uLists[j].offsetWidth+"px";
                        par.style.height=uLists[j].offsetHeight+"px";   
                        uLists[j].style.zIndex="99";
                }
        }
        if (window.attachEvent && navigator.userAgent.indexOf('Opera') == -1) window.attachEvent('onload', menuIframe);
   
   */
