﻿doc.scripts['openHRMenu'] =  openHRMenu;

window.onload = function () { doc.runScripts() };

function openHRMenu()
{
    var HRItems = doc.css('HRMenu')[0].getElementsByTagName("li");
    var HRLinks = doc.css('HRMenu')[0].getElementsByTagName("a");
    
    for(var i = 0; i < HRItems.length; i++)
    {
        doc.setFunction(HRItems[i], 'mousemove', openUnderlying);
    }
    for(var i = 0; i < HRItems.length; i++)
    {
        doc.setFunction(HRItems[i], 'mousemove', openUnderlying);
    }
    
    timerCounter = 0;
}

function openUnderlying(e)
{
    var rootElement = doc.target(e).tagName == 'A' ? doc.target(e).parentNode : doc.target(e);
   
    if(!rootElement.className.match(/(^| )open( |$)/) 
       && rootElement.getElementsByTagName('li').length > 0)
    {
        rootElement.className += " open";
        
    }
    
    var children = rootElement.getElementsByTagName("ul");
    for(var i = 0; i < children.length; i++)
    {
        children[i].className = children[i].className.replace(/(^| )hidden( |$)/g, "");
    }
    doc.setFunction(rootElement, 'mouseout', startClosingTimeout);
}

function startClosingTimeout(e)
{
    timerCounter++;
    window['rootElement' + window.timerCounter] = doc.target(e);
    window['rootElement' + window.timerCounter + 'Timer'] = setTimeout('closeUnderlying("rootElement' + timerCounter + '")', 3300);
}

function closeUnderlying(rootElement)
{
    window[rootElement].className = window[rootElement].className.replace(/(^| )open( |$)/g, "");
    var children = window[rootElement].getElementsByTagName("ul");
    for(var i = 0; i < children.length; i++)
        children[i].className += " hidden";
    clearTimeout(window[rootElement +  'Timer']);
}
