    var delay = 250;
    var tim;
    //top level menu
    var curTopMenu=null;
    var classForActiveTop="prknopka  ";
    var classForActiveTopLink="menu ";
    var classForNormalTop="knopka ";
    var classForNormalTopLink="menu";
    // menu
    var curMenu=null;
    var mouseX=0;
    var mouseY=0;
    var typeEffect="fold";
    
    function setTypeEffect(pt){
        typeEffect=pt;
    }
    ////////
    
    function isInDIV(el){
        var res=false;
        var nmY=mouseY;
        var nmX=mouseX;
        if(null!=el)
        if(el.position().top<nmY)
            if(el.position().top+el.outerHeight()>nmY)
                if(el.position().left<nmX)
                    if(el.position().left+el.outerWidth()>nmX)
                            {res=true;}
        
        return res;
    }
    function showMenu(name){
        
        if(curTopMenu!=null) if(curTopMenu.attr("id")==name) return;
        
           shutMenu();
           cancelHide();
      
         curTopMenu= $("#"+name);
         curMenu=$("#menu"+name);
        
         
         curTopMenu.attr("class",classForActiveTop); 
         curTopMenu.find("a").attr("class",classForActiveTopLink);
       
        var  newY=  curTopMenu.position().top+curTopMenu.outerHeight();
        var  newX=  curTopMenu.position().left;
         curMenu.css("top",newY);
         curMenu.css("left",newX);
         
       //  curMenu.show();
         curMenu.show(typeEffect,{},500,function(){});
         
        // activeSubmenu=name;
    } 
    function hideMenu(){
        cancelHide();
	tim=setTimeout("shutMenu()",delay);
    }
    function shutMenu(){
	
	//shutSubMenu();
	 
        if(!(isInDIV(curMenu)|| isInDIV(curTopMenu))){
            if(null!=curMenu)   
                curMenu.hide(typeEffect,{},500,function(){});
            curMenu=null;
            
            if(null!=curTopMenu) {
                curTopMenu.attr("class",classForNormalTop); 
                curTopMenu.find("a").attr("class",classForNormalTopLink);
            }
            curTopMenu=null;
        }
    }
function cancelHide(){if(tim!=null)clearTimeout(tim);}