
function JavascriptMenu(menuList){
    this.MenuList = menuList;
    InitializeMenu(this.MenuList);  
    JavascriptMenu.prototype.InitializeMenu = InitializeMenu;
    JavascriptMenu.prototype.AttachMenuItemEvents = AttachMenuItemEvents;
    JavascriptMenu.prototype.mouseOverMenuItem = mouseOverMenuItem;
    JavascriptMenu.prototype.mouseOutMenuItem = mouseOutMenuItem;
   
    function InitializeMenu(menuList)
    {
        if(menuList.childNodes != null){
            InitializeMenuItems(menuList);
         }
     }
     function InitializeMenuItems(menuList)
     {
        for(var i = 0; i < menuList.childNodes.length;i++)
        {
            if(menuList.childNodes[i].tagName == "LI")
            {
                InitializeMenuItem(menuList.childNodes[i]);
            }
         }
     }
     function InitializeMenuItem(menuItem)
     {
        
        var subList = menuItem.getElementsByTagName("ul");
        if(subList.length != 0)
        {
            if(subList[0].childNodes.length != 0){
                subList[0].originalClassName = subList[0].className;
                AttachMenuItemEvents(menuItem);
                InitializeSubMenu(subList[0]);
            }else{
                menuItem.removeChild(subList[0]);
            }
        }
     }
     function InitializeSubMenu(subList)
     {
        subList.parentNode.className = subList.parentNode.className + " hasChildren";
        subList.hasLayout = false;
        if(navigator.appVersion.indexOf("MSIE 6.0") > 0)// || navigator.appVersion.indexOf("MSIE 7.0") > 0)
        {
            FixForIE6(subList);
        }
        InitializeMenu(subList);
     }
     function FixForIE6(subList)
     {
        /*
        Fixes problem with relative positioning by adding a div around the element to be relative positioned.
        The problem occurs most in IE6, but worked as a solution to a IE7 problem as well.
        The div is then positioned relative and sub element is positioned absolute inside the relative positioned element.
        Problem was that sometimes takes the up the space where the relative element was originally even when element is placed elsewhere.
        By adding another level of elements, settings the first(new) to be relative, next to absolute will have the same effect as Firefox
        would show by just setting the second element to be relative height=0.
        */
        var wrapper = document.createElement("div");
        
        var parentNode = subList.parentNode;
        parentNode.appendChild(wrapper);
        wrapper.appendChild(subList);
     }
     function AttachMenuItemEvents(menuItem)
     {
        menuItem.onmouseover = mouseOverMenuItem;
        menuItem.onmouseout = mouseOutMenuItem;
     }
     function mouseOverMenuItem()
     {
        var subList = this.getElementsByTagName("ul");
        window.activeItem = this;
        if(subList.length != 0)
        {
            subList[0].className = subList[0].className + " expanded";
        }
     }
     function mouseOutMenuItem()
     {
        var subList = this.getElementsByTagName("ul");
        setTimeout("hideActiveItem()",500);
        if(subList.length != 0)
        {
            subList[0].className = subList[0].originalClassName;
        } 
     }
}
function hideActiveItem()
{
}

