
// Menu information

var menus = [
["people", "/people/", [
        [ "WHY NAMSA?", "/people/why-namsa/", [] ], 
        [ "INDUSTRY LEADERSHIP", "/people/leadership/", 
            [ 
                ["NAMSA AUTHORED<br />PAPERS", "/people/leadership/authored-papers.aspx", []],
                ["NAMSA UPDATE<br />NEWSLETTER", "/people/leadership/newsletters.aspx", []],
                ["RELATED SITES", "/people/leadership/related-sites.aspx", []]               
            ] 
        ],
        [ "OUR COMPANY", "/people/about/", 
            [ 
                ["OUR HISTORY", "/people/about/history.aspx", []],
                ["OUR VALUES", "/people/about/values.aspx", []],
                ["OUR BUSINESS UNITS", "/people/about/business-units.aspx", []],
                ["QA AND COMPLIANCE", "/people/about/compliance.aspx", []]
            ]         
        ]
    ]
],
["science", "/science/", [

        [ "TESTING BY CATEGORY", "/science/testing-by-category/", 
            [ 
                ["MATERIALS CHARACTERIZATION &amp; ANALYTICAL SERVICES", "/science/testing-by-category/analytical-chemistry.aspx", []],
                ["EFFICACY", "/science/testing-by-category/efficacy.aspx", []],
                ["BIOCOMPATIBILITY", "/science/testing-by-category/biocompatibility.aspx", []],
                ["CLINICAL TRIALS", "/science/testing-by-category/clinical-trials.aspx", []],
                ["STERILITY ASSURANCE &amp; MICROBIOLOGY", "/science/testing-by-category/sterility-assurance.aspx", []]                
            ] 
        ], 
        [ "TESTING BY DEVICE TYPE", "/science/testing-by-type/", 
            [ 
                ["CARDIOVASCULAR", "/science/testing-by-type/cardiovascular.aspx", []],
                ["DENTAL", "/science/testing-by-type/dental.aspx", []],
                ["DRUG DELIVERY", "/science/testing-by-type/drug-delivery.aspx", []],
                ["GASTROENTEROLOGIC", "/science/testing-by-type/gastroenterologic.aspx", []],
                ["NEUROLOGIC", "/science/testing-by-type/neurologic.aspx", []],
                ["OBSTETRICS/GYNECOLOGY", "/science/testing-by-type/obstetrics-gynecology.aspx", []],
                ["OPHTHALMOLOGY", "/science/testing-by-type/ophthalmology.aspx", []],
                ["ORTHOPEDIC", "/science/testing-by-type/orthopedic.aspx", []],
                ["TISSUE ENGINEERING", "/science/testing-by-type/tissue-engineering.aspx", []],
                ["UROLOGIC", "/science/testing-by-type/urologic.aspx", []],
                ["WOUND HEALING", "/science/testing-by-type/wound-healing.aspx", []]                
            ]         
        ]
]],
["solutions", "/solutions/", [

        [ "A COMPETITIVE<br />ADVANTAGE", "/solutions/competitive-advantage.aspx", []],
        [ "SOLUTIONS THAT WORK", "/solutions/solutions-that-work.aspx", []],
        [ "A PROVEN PROCESS", "/solutions/proven-success.aspx", []]

]]
];

var liveMenus = [];
var liveMenuSelected = [];

function showMenu(idx, type, reference, wrapper, inner)
{
    var menu = fillMenu(idx, type, reference, wrapper, inner);
    if (menu)
    {
        menu.style.display = "block";    
        var position = Position.cumulativeOffset($(reference));
        var dimensions = Element.getDimensions($(reference));

        if (idx.length == 1)
        {    
            if (liveMenus[idx.length - 1])
                liveMenus[idx.length - 1].style.display = "none";        
        
            menu.style.left = position[0] + "px";
            menu.style.top = position[1] + "px";
            menu.style.display = "block";  

            Event.observe(menu, 'mouseout', hideMenuEventLevel1, false);
        }
        else
        {
            menu.style.left = (position[0] + 147) + "px";
            menu.style.top = (position[1] + 84) + "px";
            menu.style.display = "block";  

            Event.observe(menu, 'mouseout', hideMenuEventLevel2, false);    
        }
        
        
        liveMenus[idx.length - 1] = menu;
        liveMenuSelected[idx.length - 1] = "";
    }
    else if (liveMenus[idx.length - 1])
    {
        liveMenus[idx.length - 1].style.display = "none";
    }
}

function hideMenuEventLevel1(evt)
{
    var child = Event.element(evt);
    
    if ((child.descendantOf(liveMenus[0])) || (child == liveMenus[0]))
    {   
        var position = Position.cumulativeOffset(liveMenus[0]);
        var dimensions = Element.getDimensions(liveMenus[0]);

        if (((Event.pointerX(evt) < position[0] + 1) || 
            (Event.pointerX(evt) > position[0] + dimensions["width"] - 1) || 
            (Event.pointerY(evt) < position[1] + 1) || 
            (Event.pointerY(evt) > position[1] + dimensions["height"] - 1)) &&
            (liveMenus[0].style.display == "block"))
        {
            hideMenu(0);
        }
    }
}
function hideMenuEventLevel2(evt)
{
    var child = Event.element(evt);
    
    if ((child.descendantOf(liveMenus[1])) || (child == liveMenus[1]))
    {   
        var position = Position.cumulativeOffset(liveMenus[1]);
        var dimensions = Element.getDimensions(liveMenus[1]);

        if (((Event.pointerX(evt) < position[0] + 1) || 
            (Event.pointerX(evt) > position[0] + dimensions["width"] - 1) || 
            (Event.pointerY(evt) < position[1] + 1) || 
            (Event.pointerY(evt) > position[1] + dimensions["height"] - 1)) &&
            (liveMenus[0].style.display == "block"))
        {
            hideMenu(1);
        }
    }
}

function hideMenu(idx)
{
    for (var k = idx; k < liveMenus.length; k++)
    {
        liveMenus[k].style.display = "none";
    }
}
function selectMenuItem(idx, id)
{
    if ((liveMenuSelected[idx]) && ($("item_" + liveMenuSelected[idx])))
    {
        $("item_" + liveMenuSelected[idx]).className = "menu_item";
        //$("image_" + liveMenuSelected[idx]).src = "/images/spacer.gif";
    }
    //alert(liveMenuSelected[idx]);
    liveMenuSelected[idx] = id;
    $("item_" + id).className = "menu_item_active";
    //$("image_" + id).src = "/images/menu/menu_point.png";
}

function fillMenu(idx, type, reference, wrapper, inner)
{
    // Find correct menu ref and build index string. 
    var menuRef = menus;
    var itemRef = [];
    var menuString = "";
    var idString = "";
    
    for (var k = 0; k < idx.length; k++)
    {
        menuString += idx[k] + ",";
        idString += idx[k] + "_";
    
        // Find current menu
        itemRef = menuRef[idx[k]];
        menuRef = menuRef[idx[k]][2];
    }    
    
    if (menuRef.length > 0)
    {    
        // Build menu
        html = "";
        for (var k = 0; k < menuRef.length; k++)
        {
            var localIdString = idString + k;
            //<img id='image_" + localIdString + "' width='6' height='10' class='menu_pointer' src='/images/spacer.gif' />
            html += "<div class='menu_item' id='item_" + localIdString + "'><div class='menu_text'><a href='" + menuRef[k][1] + "' onmouseover='selectMenuItem(" + (idx - 1) + ",\"" + localIdString + "\");showMenu([" + menuString + k + "], \"level2\", \"" + reference + "\", \"menu_level2_wrapper\", \"menu_level2_body\");'>" + menuRef[k][0] + "</a></div></div>";
            html += "<div class='menu_rule'><img src='/images/menu/rule_menu.png' /></div>";
        }

        $(inner).innerHTML = html;
        return $(wrapper);
    }
    else
    {
        return "";
    }    
}



function toggleDiv(group, divName, styleActive, styleInactive)
{
    if (group)
    {
        for (var k = 0; k < group.length; k++)
        {
            $(group[k]).className = styleInactive;
        }   
        if ($(divName))
        {
            $(divName).className = styleActive;
        }
        else
        {
            $(group[0]).className = styleActive;
        }
    }
}

function showNewsMenu(menuId, reference)
{
    hideCareersMenu();
    hideProductsMenu();

    var position = Position.cumulativeOffset($(reference));
    var dimensions = Element.getDimensions($(reference));

    $(menuId).style.left = position[0] + "px";
    $(menuId).style.top = (position[1] - Element.getHeight($(menuId)) + 20) + "px";
    $(menuId).style.display = "block";
    
    Event.observe($(menuId), 'mouseover', showNewsMenu2, false);
    Event.observe($(menuId), 'mouseout', hideNewsMenu, false);
}
function showCareersMenu(menuId, reference)
{
    hideProductsMenu();
    hideNewsMenu();

    var position = Position.cumulativeOffset($(reference));
    var dimensions = Element.getDimensions($(reference));

    $(menuId).style.left = position[0] + "px";
    $(menuId).style.top = (position[1] - Element.getHeight($(menuId)) + 20) + "px";
    $(menuId).style.display = "block";
    
    Event.observe($(menuId), 'mouseover', showCareersMenu2, false);
    Event.observe($(menuId), 'mouseout', hideCareersMenu, false);
}
function showProductsMenu(menuId, reference)
{
    hideCareersMenu();
    hideNewsMenu();

    var position = Position.cumulativeOffset($(reference));
    var dimensions = Element.getDimensions($(reference));

    $(menuId).style.left = position[0] + "px";
    $(menuId).style.top = (position[1] - Element.getHeight($(menuId)) + 20) + "px";
    $(menuId).style.display = "block";
    
    Event.observe($(menuId), 'mouseover', showProductsMenu2, false);
    Event.observe($(menuId), 'mouseout', hideProductsMenu, false);
}
function hideNewsMenu()
{
    $("menu_news").style.display = "none";
}
function showNewsMenu2()
{
    $("menu_news").style.display = "block";
}

function hideCareersMenu()
{
    $("menu_careers").style.display = "none";
}
function showCareersMenu2()
{
    $("menu_careers").style.display = "block";
}

function hideProductsMenu()
{
    $("menu_product_catalog").style.display = "none";
}
function showProductsMenu2()
{
    $("menu_product_catalog").style.display = "block";
}


function hideSimpleMenu(menuId)
{
     //$(menuId).style.display = "none";
}
