﻿/*****************************************************
 * File Name: menu.js
 * Created By: Tim Stratton
 * Date Created: 9/25/2007
 * 
 * Summary:
 * This file defines all the client side script the 
 * side navigation menu needs to function.  If javascript
 * is disabled, the menu will still be navigable, but the 
 * collasping functionallity of the sub menus will be 
 * inactive.
 *
 * Revisions:
 * Modified By      Date        Comments
 * -----------      ----        --------
 * Tim Stratton     10/23/07    Restricted code to test anchors only in the menu, instead of whole page
 * 
 *****************************************************/
 
/*****************************************************
 * Function: menuClick
 * Summary: This function is triggered when a submenu
 *          without a landing page is clicked.  It will
 *          collapse/uncollapse the submenu.
 * Parameters:
 *  jid: A string that uniquely identitifies a submenu's
 *       anchor tag and it's div tag containing sub items
 *  depth: the current depth of the selected submenu
 *
 * Returns: nothing
 *****************************************************/
function menuClick(jid,depth)
{   
    /* capture the DIV tag and Anchor tag of the seleced submenu*/ 
    var div = document.getElementById("menu_"+jid);
    var anchor = document.getElementById("button_"+jid);
    
    /*if the sub menu is already collapsed*/
    if (div.className == "collapse")
    {                   
        /*un-collapse the sub menu*/
        div.className = "";
        
        /*create an array of all anchors within tag IDed as 'navigation'.
          These will be tested to see if they are
          part of un-collapsed sub menus that must now
          collapse*/
        var anchors = document.getElementById('navigation').getElementsByTagName('a');

        /*iterate through all anchors*/
        for (var i =0;i< anchors.length;i++)
        {
            /*If the current anchor has a class in the form of 'depth#Selected', Then it is uncollapsed.
              If it is also at a depth equal to or greater then the newly selected sub menu, then...*/
            var str = anchors[i].className;                
            if (str.match(/depth([0-9]+)Selected/) && (parseInt(str.substring(5,str.length-1)) >= depth))
            {
                /*make the current anchor de-selected*/                                                
                anchors[i].className = "menuItemDepth" + parseInt(str.substring(5,str.length-1));
                
                /*capture the next HTMLDOM object next to the anchor*/
                var nextSib = anchors[i].nextSibling;
                
                /*If there is a sibling object and it is a DIV tag, then it is the collection of
                  sub menu items and must be set to 'collapsed'*/
                if(nextSib != null)
                {
                    if (nextSib.tagName == "DIV")
                    {
                        nextSib.className = "collapse";
                    }                        
                }
            }            
        }  
        /*set the anchor to 'selected'*/              
        anchor.className = "depth" + depth + "Selected";   
    }                 
}        

/*****************************************************
 * inline command
 * Summary: By Default, the class .collapse is set to 
 * 'display:block' such that if javascript is disabled,
 * All submenus will be un-collapsed and navigable.
 * When javascript is enabled, this inline command will
 * execute, overwriting the properties of .collapse .
 *****************************************************/
document.write("<style type=\"text/css\">.collapse{display:none;}</style>");          

