var handler = 1;

$(window).load(function(){

	$('.menuItem').bind("mouseenter", function(){
	
	    handler = 1;
	    
    	    tab = new Array();
	    tab = $(this).attr('id').split('_');
    	    $('.menuSubItemContainer').hide();
    	    $('.menuSubSub').hide();
    	    
    	    tops = $(this).height()+$(this).offset().top+2;
	    $('#subNode_' + tab[1]).css('left',$(this).offset().left);
    	    $('#subNode_' + tab[1]).css('top',tops);
	    $('#subNode_' + tab[1]).show();
		
		
	})
	
	$('.menuSubItem').bind("mouseenter", function(){
	    handler = 1;
	    tab = new Array();
            tab = $(this).attr('id').split('_');
	    tops = $(this).offset().top-$(this).height()*3+4;
		
	    $('.menuSubSub').hide();
	    
	    $('#subNode_' + tab[1]).css('left',$(this).parent().width()+1);
	    $('#subNode_' + tab[1]).css('top',tops);
	    $('#subNode_' + tab[1]).show();	
	});
	
    $('#menu,.menuSubItemContainer').bind("mouseleave", function(){ 
        handler = 0;
        setTimeout('hideMenu(true)', 500);
    });
	
	
});

function hideMenu(){
	if(handler == 0) {
	    $('.menuSubItemContainer').hide();
	    $('.menuSubSub').hide();
	}
}
