﻿/* 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Nav.js defines the behavior of a collapsible menu having the following 
attributes:
1.  The hidden input element txtShowItems can take on two values: "true" 
and "false".  If "true", menu items are displayed; if false, they are
hidden.
2.  By default, menu items are visible.  Thus, the default value for 
txtShowItems is "true".  Hence, the menu is accessible to Users without 
javascript.

Source: Adapted from Quirksmode.org
http://www.quirksmode.org/book/examplescripts/dropdown/dropdown.js .
Note: Most of the comments were added by me.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
*/

//Example of object detection (see ppk p. 78-80). This particular test is an
//effective check for W3C DOM support.
var W3CDOM = (document.getElementsByTagName && document.createElement);

//Initialize scripts for the navigation menu when the window loads. Note
//that this window.onload event does NOT overwrite any other window.onload
//events that might be declared in other javascript scripts.
//Source: ppk, pp. 125-126.
addEventSimple(window,"load",hideDvdItems);
addEventSimple(window,"load",hideBooksItems);
addEventSimple(window,"load",hideCalcItems);
addEventSimple(window,"load",hideClubsItems);
addEventSimple(window,"load",hideGearItems);
addEventSimple(window, "load", hideTutorialItems);

//Allows me to set an unlimited number of event handlers on the same 
//element, and none of the event handlers overwrite the others.
//Source: ppk, pp. 125-126, 307-308.
//NOTE: The "this" keyword does not work correctly with addEventSimple or
//removeEventSimple. Do not add or remove functions that use "this" (see
//ppk, pp. 308-309).
function addEventSimple(obj,evt,fn) {
    //Check for support of addEventListener (W3C) or attachEvent (Microsoft).
    //Source: ppk, p.80-81.
    if (obj.addEventListener)
        //This browser supports the W3C model
	    obj.addEventListener(evt,fn,false);
    else if (obj.attachEvent) 
        //This browser supports the Microsoft model      
	    obj.attachEvent('on'+evt,fn);
}

//Show DVD menu items 
function showDvdItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
     var Anc = document.getElementById("navDvdTitle");   //anchor element title
     var Lst = document.getElementById("navDvdMenuItems");   //menu list
    
    //Show items
    Anc.className="navTitle";
    Lst.style.display="block";
}

//Hide DVD menu items 
function hideDvdItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
     var Anc = document.getElementById("navDvdTitle");   //anchor element title
     var Lst = document.getElementById("navDvdMenuItems");   //menu list
    
    //Hide items
    try{
        var CanCollapse = document.getElementById("txtCanCollapseDvdItems");
        
        if (CanCollapse.value == "true") {
            Anc.className="navTitleNormal";
            Lst.style.display="none";
        }
    }
    catch(e){
        //The Try block above throws an error when CanCollapse is null
    }
}

//Show Books menu items 
function showBooksItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
     var Anc = document.getElementById("navBooksTitle");   //anchor element title
     var Lst = document.getElementById("navBooksMenuItems");   //menu list
    
    //Show items
    Anc.className="navTitle";
    Lst.style.display="block";
}

//Hide DVD menu items 
function hideBooksItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
     var Anc = document.getElementById("navBooksTitle");   //anchor element title
     var Lst = document.getElementById("navBooksMenuItems");   //menu list
    
    //Hide items
    try{
        var CanCollapse = document.getElementById("txtCanCollapseBooksItems");
        
        if (CanCollapse.value == "true") {
        Anc.className="navTitleNormal";
        Lst.style.display="none";
        }
    }
    catch(e){
        //The Try block above throws an error when CanCollapse is null
    }
}

//Show Calc menu items 
function showCalcItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    
    if (!W3CDOM) {return;};
    
    //Identify elements
     var Anc = document.getElementById("navCalcTitle");   //anchor element title
     var Lst = document.getElementById("navCalcMenuItems");   //menu list
    
    //Show items
    Anc.className="navTitle";
    Lst.style.display="block";
}

//Hide Calc menu items 
function hideCalcItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
    var Anc = document.getElementById("navCalcTitle");   //anchor element title
    var Lst = document.getElementById("navCalcMenuItems");   //menu list
    
    //Hide items
    try{
        var CanCollapse = document.getElementById("txtCanCollapseCalcItems");
        
        if (CanCollapse.value == "true") {
            Anc.className="navTitleNormal";
            Lst.style.display="none";
        }
    }
    catch(e){
        //The Try block above throws an error when CanCollapse is null
    }
}

//Show Clubs menu items 
function showClubsItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
     var Anc = document.getElementById("navClubsTitle");   //anchor element title
     var Lst = document.getElementById("navClubsMenuItems");   //menu list
    
    //Show items
    Anc.className="navTitle";
    Lst.style.display="block";
}

//Hide Clubs menu items 
function hideClubsItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
     var Anc = document.getElementById("navClubsTitle");   //anchor element title
     var Lst = document.getElementById("navClubsMenuItems");   //menu list
     
    //Hide items
    try{
        var CanCollapse = document.getElementById("txtCanCollapseClubsItems");
        
        if (CanCollapse.value == "true") {
            Anc.className="navTitleNormal";
            Lst.style.display="none";
        }
    }
    catch(e){
        //The Try block above throws an error when CanCollapse is null
    }
}

//Show Gear menu items 
function showGearItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
     var Anc = document.getElementById("navGearTitle");   //anchor element title
     var Lst = document.getElementById("navGearMenuItems");   //menu list
    
    //Show items
    Anc.className="navTitle";
    Lst.style.display="block";
}

//Hide Gear menu items 
function hideGearItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
     var Anc = document.getElementById("navGearTitle");   //anchor element title
     var Lst = document.getElementById("navGearMenuItems");   //menu list
    
    //Hide items
    try{
        var CanCollapse = document.getElementById("txtCanCollapseGearItems");
        
        if (CanCollapse.value == "true") {
            Anc.className="navTitleNormal";
            Lst.style.display="none";
        }
    }
    catch(e){
        //The Try block above throws an error when CanCollapse is null
    }
}

//Show Tutorial menu items 
function showTutorialItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
     var Anc = document.getElementById("navTutorialTitle");   //anchor element title
     var Lst = document.getElementById("navTutorialMenuItems");   //menu list
    
    //Show items
    Anc.className="navTitle";
    Lst.style.display="block";
}

//Hide Tutorial menu items 
function hideTutorialItems()
{
    //Object detection to avoid browser problems (ppk. p. 78-80)
    if (!W3CDOM) {return;}
    
    //Identify elements
     var Anc = document.getElementById("navTutorialTitle");   //anchor element title
     var Lst = document.getElementById("navTutorialMenuItems");   //menu list
    
    //Hide items
    try{
        var CanCollapse = document.getElementById("txtCanCollapseTutorialItems");
        
        if (CanCollapse.value == "true") {
            Anc.className="navTitleNormal";
            Lst.style.display="none";
        }
    }
    catch(e){
        //The Try block above throws an error when CanCollapse is null
    }
}
