/*
** class js_trail_menu()
*/
function js_trail_menu()
{
  this.on	= null;
  this.classes	= { 'LI': 'jtm_mark',
		    'UL': 'jtm_unhide',
		     'A': 'jtm_mark'};
  this.lookup	=
    function (name)
    {
      return this.classes[name];
    };

  this.build_options  = build_options;
  this.build_menu     = build_menu;

  /*
  ** first grab 'our' menus, (divs with id="css_menu"), then traverse
  ** the elements to set the mouse over and mouse out properties for
  ** the respective 'li' elements of the menus.
  */
  this.setup = 
    function ()
    {
      var divs = document.getElementsByTagName('div');

      for (var ind = 0; divs[ind]; ind++)
      {
	if ('css_menu' == divs[ind].id)
	{
	  this.build_menu(divs[ind]);
	}
      }
    };
}

/*
** this function finds 'ul' elements (menus) in the passed object obj,
** which should be either a 'div' or an 'li'.  When found, it builds its
** options by calling build_options.
*/
function build_menu(obj)
{
  for (var ind = 0; obj.childNodes[ind]; ind++)
  {
    var son = obj.childNodes[ind];

    if ('UL' == son.tagName)
    {
      this.build_options(son);
    }
  }
}

/*
** this function finds 'li' elements (menu options) in the passed object
** obj, which should be a 'ul' element.  When found, it sets the mouse
** over and out event handlers and recursively searches for sub-'ul' 
** elements by calling build_menu.
*/
function build_options(obj)
{
  for (var ind = 0; obj.childNodes[ind]; ind++)
  {
    daughter = obj.childNodes[ind];

    if ('LI' == daughter.tagName)
    {
      daughter.onmouseover	= over;
      daughter.onmouseout	= out;
      this.build_menu(daughter);
    }
  }
}

/*
** local namespace in new object.
*/
var jtm = new js_trail_menu();

if (typeof window.onload == 'function')
{
  jtm.on	= onload;     //store it
  window.onload =
    function()	    //setup handler
    {
      jtm.on();	    //call it
      jtm.setup();  //call startup function
    };
}
else //if there's no existing load function
{
  window.onload = jtm.setup; //setup handler to call startup func
}

/*
** function jtm_toggle()
** either adds the appropriate 'roll-over' class to the object and its
** children or removes the same.
*/
function jtm_toggle (obj, add)
{
  if (jtm.lookup(obj.tagName))
  {
    change_class(obj, jtm.lookup(obj.tagName), add);
  }

  for (var ind = 0; obj.childNodes[ind]; ind++)
  {
    var baby = obj.childNodes[ind];

    if (jtm.lookup(baby.tagName))
    {
      change_class(baby, jtm.lookup(baby.tagName), add);
    }
  }
}

/*
** over()
** roll over function, uses jtm_toggle in add mode.
*/
function over()
{
  jtm_toggle(this, 1);
}

/*
** out()
** roll out function, uses jtm_toggle in remove mode.
*/
function out()
{
  jtm_toggle(this, 0);
}
