// JavaScript Document

// -- cascading menu library tied into crashcourse.js and as 
//    demonstrated in Dynamic HTML Weekend Crash Course:
// Demonstration cross-browser compatibility API
// only tested for Netscape 6 and IE5.5
// Written by Dave Taylor - taylor@intuitive.com - for the
// book "Dynamic HTML Weekend Crash Course"
//    online at  http://www.intuitive.com/dhtml/
// These menus have been enhanced and some shortcomings (probably intended by Dave Taylor as student exercises) have been eliminated

var maxDepth = 4;
var menuItemId = 1;
var menunames  = new Array;
menunames[0] = new Array("");
menunames[1] = new Array("");
menunames[2] = new Array("");
menunames[3] = new Array("");
var menucounts = new Array(0,0,0,0,0);
// Stylesheet classes mi and mt set starting colors and class menu sets x and y size but bgcolor is controled below
// the mouseover and mouseout variables carry colors for the menu bars
var mouseover= "#FFFFFF"
var mouseout= "#BBFFFF"
var mouseoversub= "#FFFFFF"
var mouseoutsub= "#BBFFFF"


function menuOn(id)
{ 
  var myMenu = getObj(id);
  myMenu.display="block";
}

function menuOff(id)
{
  obj = getObj(id);
  obj.display='none';
}

function closeMenus(level)
{
  // closes all menus at any level higher than that specified
  for (var lvls = level; lvls < maxDepth; lvls++) {
    for (var i=0; i < menucounts[lvls]; i++) {
      menuOff(menunames[lvls][i]);
    }
  }
}

function newMenu(level, id, xVal, yVal)
{
  // create a new menu element. Call this with level specifying the relative
  // depth of the menu (1 = topmost, 2 = submenu, etc), id indicating the name
  // you'll use for future references to the menu, and xVal, yVal for the 
  // absolute position of the menu on the screen.
  
  if (level > maxDepth)
    return( alert("Too deep: newMenu("+id+") called with level > max depth") );
    
  menunames[level][ menucounts[level]++ ] = id; // remember new ID in level array
  currentLevel = level+1;						//  and increment counter
  
  document.write  ("<SPAN CLASS=\"menu\" ID=\"" + id + "\" ");
  document.writeln("STYLE=\"top:"+yVal+"px; left:"+xVal+"px\">");
}

function endMenu()
{
  document.writeln("</SPAN>");
}

function addMenuItem(url, label)
{
  // call this with a url and display label for all regular menu entries.
  // use addSubmenu() to add submenu items to a menu instead.
  
  var id = "menuItem" + menuItemId;
  menuItemId++;
  
  document.writeln("<DIV CLASS=\"mi\" ID='" + id + "'");
  document.write  (" onMouseOver=\"setBgColor('" + id + "', mouseover);");
  document.write  (" window.status='" + label + " at " + url + "';");
  document.writeln(" closeMenus(" + currentLevel + ");\"");
  document.writeln(" onClick=\"location.href=\'" + url + "'\"");
  document.writeln(" onMouseOut=\"setBgColor('" + id + "', mouseout)\">");
  document.writeln(label + "\n</DIV>");
}

function addSubmenu(submenuId, label)
{
  // call this to add a submenu link to a menu. submenuId should be the
  // ID name that'll be used to create the new menu, and label is the
  // display text for the menu. It's encouraged that submenu labels have
  // an ellipses (...) or similar visual element to denote their status.
  
  var id = "menuItem" + menuItemId;
  menuItemId++;
  
  document.writeln("<DIV CLASS=\"mi\" ID='" + id + "'");
  document.write  (" onMouseOver=\"setBgColor('" + id + "', mouseoversub);");
  document.write  (" window.status='" + label + "';");
  document.write  (" closeMenus(" + currentLevel + ");");
  document.writeln(" menuOn('" + submenuId + "');\"");
  document.writeln(" onMouseOut=\"setBgColor('" + id + "', mouseoutsub)\">");
  document.writeln(label + "\n</DIV>");
}
  
function addMenuTitle(label)
{
  // add an inactive menu element (title) to the menu
  var id = "menuTitle" + menuItemId;
  menuItemId++;
  
  document.writeln("<DIV CLASS=\"mt\" ID='" + id + "'>");
  document.writeln(label + "\n</DIV>");
}

