/* xactmenu building instructions */

/*  Adding a new menu group */

    // And the menu group to the listgroup array listed in this file add i.e. **GroupName**
    //-------------------------------------------------------------------------------------
    //
    //Add the html to create the menu
    //-------------------------------
    //
    // Example and template
    // <div class="top_menu_bar" id="menu_list">
    //  <div class="top_menu_linker" id="**GroupName**">
    //    <span class="top_menu_link" id="**GroupName**_header">**Whatever the title is for this menu**</span>
    //    <div class="top_menu" id="**GroupName**_list" style="top: **px; left: **px; width: **px; height: **px;">
    //      <div class="menu_item" onclick="window.location='**LinkLocation**'">
    //        <a href="**LinkLocation**">**Link in Menu**</a>
    //      </div>
    //      <div class="menu_item" onclick="window.location='**LinkLocation**'">
    //        <a href="**LinkLocation**">**Link in Menu**</a>
    //      </div>
    //      ..
    //    </div>
    //  </div>
    //..
    // </div>
    //
    //To add an item to the list simply place the
    //-------------------------------------------
    //      <div class="menu_item" onclick="window.location='**LinkLocation**'">
    //        <a href="**LinkLocation**">**Link in Menu**</a>
    //      </div>
    //in the place where you would want it.
    //-------------------------------------
    //

		//Gets the id for each of the menus
    var listgroup = new Array;

    // a holder for each menu to keep track if the menu is moused over long enough to display it.
		var still_on = new Array;

	var menulist = document.getElementById('menu_list');
	var listnames = "";
	if(typeof menulist == 'undefined' || menulist == null)
	{
     listnames = "";
	}
	else
	{
     listnames = document.getElementById('menu_list').childNodes;
	}
    
        j= 0;
		for(i = 0; i < listnames.length; i++)
		{
			if(listnames[i].nodeName.toUpperCase() == 'DIV')
			{
				listgroup[j] = listnames[i].id;
		    // Initially none of the menus are moused over
	      still_on[listgroup[j]] = false;
	      j++;
	    }
    }


    // add the event handlers to the menu list
    for(i=0; i < listgroup.length; i++)
		{
      list_header = document.getElementById(listgroup[i]);
      if(list_header.addEventListener)
			{
       list_header.addEventListener('mouseover', headerMouseOver, false);
        list_header.addEventListener('mouseout', headerMouseOut, false);
        list_header.addEventListener('click', headerClick, false);
      }
			else
			{
        list_header.onmouseover = headerMouseOver;
        list_header.onmouseout = headerMouseOut;
        list_header.onclick = headerClick;
      }
      list = document.getElementById(listgroup[i] + '_list');
      for(j=0; j < list.childNodes.length; j++)
			{
        list_item = list.childNodes[j];
				if(list_item.nodeName.toUpperCase() == 'DIV')
				{
	        if(list_item.addEventListener)
					{
						list_item.addEventListener('mouseover', itemMouseOver, false);
  	        list_item.addEventListener('mouseout', itemMouseOut, false);
	        }
					else
					{
	          list_item.onmouseover = itemMouseOver;
	          list_item.onmouseout = itemMouseOut;
	        }
	      }
      }
    }


/* Menu functionality  */

    // displays the menu after a delay if the person has not moused-off of it
    function startShow(menu)
		{
      enqueuList(menu)
      setTimeout('showMenu(\''+menu+'\')', 125);
    }

    // marks this menu as moused-over for when the delay is up
    function enqueuList(menu)
		{
      for(i = 0; i < listgroup.length; i++)
			{
        still_on[listgroup[i]] = false;
      }
      still_on[menu] = true;
    }

    // show the menu
    function showMenu(menu)
		{
      if(still_on[menu])
			{
        if(document.getElementById)
				{
          list = document.getElementById(menu+'_list');
          list.style.visibility = 'visible';
          header = document.getElementById(menu+'_header');
          header.style.color = '#000000';
          if(header.id == listgroup[0]+'_header')
          {
          	header.style.borderColor = '#DF912D';
          }
        }
      }
    }

    // hide the menu after a delay if a person doesn't mouse back over it again
    function startHide(menu)
		{
      still_on[menu] = false;
      setTimeout('hideMenu(\''+menu+'\')', 500);
    }

    // if still moused off of the menu, hide the menu
    function hideMenu(menu)
		{
      if(!still_on[menu])
			{
        doHide(menu);
      }
    }

    // hide the menu
    function doHide(menu)
		{
      if(document.getElementById)
			{
        list = document.getElementById(menu+'_list');
        list.style.visibility = 'hidden';
          header = document.getElementById(menu+'_header');
          header.style.color = '#6E6E6E';
          if(header.id == listgroup[0]+'_header')
          {
          	header.style.borderColor = '#FFFFFF';
          }
      }
    }

    // hides all the menues, called before startShow so that multiple menues are not opened
    function hide_all(menu)
		{
      for(i = 0; i < listgroup.length; i++)
			{
        if(listgroup[i] != menu)
				{
          doHide(listgroup[i]);
          still_on[listgroup[i]] = false;
        }
      }
    }


/* This section moves all the event handles in here so that the HTML is more readable. */

    //Wrapper for the mouseover event on the header
    function headerMouseOver()
		{
      hide_all(this.id);
      if(document.getElementById(this.id+'_list').childNodes.length > 0)//only show if there are menu items
      {
	      startShow(this.id);
	  }
    }

    //Wrapper for the mouseout event on the header
    function headerMouseOut()
		{
      startHide(this.id);
    }

    //Wrapper for the mouseclick event on the header
    function headerClick()
		{
      hide_all(this.id);
      if(document.getElementById(this.id+'_list').childNodes.length > 0)//only show if there are menu items
      {
      still_on[this.id] = true;
      showMenu(this.id);
    }
    }

    //Wrapper for the mouseover event on a list item
    function itemMouseOver()
		{
      showMenu(this.parentNode.parentNode.id);

      for(i=0; i < this.childNodes.length; i++)
			{
      	if(this.childNodes[i].nodeName.toUpperCase() == 'A')
      	{
		      this.style.backgroundColor = '#757575';
      		this.childNodes[i].style.color = '#FFFFFF';
				}
      }

    }

    //Wrapper for the mouseout event on a list item
    function itemMouseOut()
		{
      startHide(this.parentNode.parentNode.id);
      this.style.backgroundColor = '#FFFFFF';
      for(i=0; i < this.childNodes.length; i++)
			{
      	if(this.childNodes[i].nodeName.toUpperCase() == 'A')
      	{
      		this.childNodes[i].style.color = '#666666';
				}
      }
    }