jQuery(document).ready(function(){

    var timer;

   jQuery('.menu-item').hover(function(){
        var id = this.id;
        var mnu = jQuery('#'+id+' .sub-menu').html();
        if(!mnu){
            jQuery('#submenu-holder').html('');
            jQuery('#subsub').show();
        }else{
           if(mnu.length > 4){   
                jQuery('#subsub').hide();
                jQuery('#submenu-holder').html("<ul id='tmp-ul'>"+mnu+"</ul>");  
            } 
        }
    },function(){
        timer = setTimeout(function(){
            jQuery('#submenu-holder').html('');
            jQuery('#subsub').show();    
        },5000);
    });

    jQuery('#submenu-holder').hover(function(){
        clearTimeout(timer);
    },function(){
        timer = setTimeout(function(){
            jQuery('#submenu-holder').html('');
            jQuery('#subsub').show();    
        },6000);
    });
   
   function popMenu(){
        var menyoo = jQuery('#access .current_page_item .sub-menu').html();
        if(!menyoo){
            var menyoo2 = jQuery('#access .current-page-ancestor .sub-menu').html();
            if(menyoo2){
                jQuery('#subsub').html("<ul id='static-ul'>"+menyoo2+"</ul>");
            }
        }else{
            jQuery('#subsub').html("<ul id='static-ul'>"+menyoo+"</ul>");
        }
        
       
   } popMenu();
   
});

