﻿
    var closeTopNavTimer;
    
    var currentFloater	= null;
    var currentTdSelection = null;
    

    // open hidden layer
    function showDropdown(sender, articleId)
    {	
        hideDropdown();
        
        var coordinates = GetElementCoordinates(sender);
        
	    // close old layer
	    if(currentFloater)
	    {
	        currentFloater.style.display = "none";
	    }
	    
	    currentTdSelection = sender.parentNode.parentNode; 
	    
	    if(currentTdSelection.oldClassName==null)
	    {
	        currentTdSelection.oldClassName = currentTdSelection.className;
	    }
	    
        currentTdSelection.className = "node selected";
        
        currentFloater = document.getElementById("top_menu_" + articleId);
        
        currentFloater.style.visibility = "hidden";
	    currentFloater.style.display = "";
	    
	    
        currentFloater.style.left = (coordinates.bottomLeft.x -10) + "px";
        currentFloater.style.top = (coordinates.bottomLeft.y -20) + "px";
	    
	    
	    
        currentFloater.style.visibility = "visible";
	    currentFloater.style.display = "inline-block";    
	    
	    // Nothis is display until here

    }
    // close showed layer
    function closeDropdown()
    {
	    if(currentFloater) currentFloater.style.display = 'none';
	    unSelectMenu();
	       
    }
    
    function noMenu()
    {
        unSelectMenu();
    }
    
    
    function unSelectMenu()
    { 
        if(currentTdSelection != null)
	    {
	        currentTdSelection.className =  currentTdSelection.oldClassName.toString();
	        currentTdSelection.oldClassName = null;
	    }
    }

    // go close timer
    function hideDropdown()
    {
        var closeTopNavTimer = setInterval(
            function()
            {
                if(currentFloater!=null && currentTdSelection!=null)
                {
                    // we have an active menu
                    if(!IsMouseOverElementCoordinates(currentFloater) && !IsMouseOverElementCoordinates(currentTdSelection))
                    {
                        
                        var closeTimeout = setTimeout(function()
                        {
                        
                            closeDropdown();
                            unSelectMenu();
                            clearTimeout(closeTimeout);
                            
                        }, 50);
                        
                        clearInterval(closeTopNavTimer);
                    }
                }
            }
        , 50);
    }

