﻿function HighlightParentNavigationButton(event, control)
{
    var parent = $(control.parentNode);
    
    if(parent.className != 'NavigationButton Selected1' || (parent.oldClassName == null && parent.className != 'NavigationButton Selected'))
    {
        if(event.type == 'mouseover')
        {
            parent.oldClassName = parent.className;
            parent.className = 'NavigationButton Selected';
        }
        else
        {
            parent.className = parent.oldClassName;
            parent.oldClassName = null;
        }
    }
}

function DisplayDropDownMenu(control, menuID, highlightParentNode)
{
    var menu = $(menuID);
    
    if(menu != null)
    {
        var parent = $(menu.parentNode);
        
        if(menu.style.display == 'none' || menu.style.display == '')
        {
            menu.style.display = 'block';
            
            if(highlightParentNode && (parent.className != 'NavigationButton Selected' || parent.oldClassName != null))
            {                
                parent.className = 'NavigationButton Selected1';
            }
        }
        else
        {
            menu.style.display = 'none';
            
            if(highlightParentNode && (parent.className != 'NavigationButton Selected' || parent.oldClassName != null))
            {                
                parent.className = 'NavigationButton';
            }
        }
    }
}

function DisplayDropDownMenuHover(control, menuID, highlightParentNode)
{
    var menu = $(menuID);
    
    if(menu != null)
    {
        if(menu.style.display == 'none' || menu.style.display == '')
        {
            menu.observe('mouseover', OnNavMenuMouseOver.curry('mouseover', control, menu, highlightParentNode));
            menu.observe('mouseout', OnNavMenuMouseOver.curry('mouseout', control, menu, highlightParentNode));
            $(control).observe('mouseout', OnNavMenuMouseOver.curry('mouseout', control, menu, highlightParentNode));                
                
            DisplayDropDownMenu(control, menuID, highlightParentNode);
        }
    }
}

function OnNavMenuMouseOver(eventType, control, menu, highlightParentNode) {
    clearTimeout(menu.menuTimeOut);

    if (eventType == 'mouseout') {
        menu.menuTimeOut = setTimeout(
            function() {
                DisplayDropDownMenu(control, menu.id, highlightParentNode);
            }, 2000);
    }
}

function HideShow(controlName, navigationLinksName) {

    var navigationLinks = document.getElementById(navigationLinksName);

    for (i = 0; i < navigationLinks.children.length; i++) 
    {
        var child = navigationLinks.children[i];
        
        // Div with sub menus
        if (child.attributes.length == 0) 
        {
            var childLinks = navigationLinks.children[i].children[1];
            childLinks.style.display = 'none';
        }
        
    }
    
    if (document.getElementById(controlName).style.display == 'block') {
        document.getElementById(controlName).style.display = 'none'
    }
    else { document.getElementById(controlName).style.display = 'block' }
}
