﻿// Author: Chris Smith
// Date: 17 July 2009
// Filename: dropdown.js
//
// Purpose: Change button displayed on rollover


/* *****************************************************
   *                Function dropdownInit()            *
   ***************************************************** */
   
// Purpose:  The purpose of this function is to search all
//           links on the page and then check to see if the
//           link has the menuLink class associated with it.
//           For each link that has the menuLink class associated
//           with it, the function toggleMenu is called.  The function
//           toggleMenu will display the drop down menu items when the
//           mouse is over the link, and will disapear when the mouse is
//           not over the link.
//
//  Input:  All Links on a page - see for loop
//
//  Output: Send the Links that are associated with the menuLink class
//          to the function toggleMenu.

function dropdownInit(){
    var allLinks = document.getElementsByTagName("a");
    for (var ctr = 0; ctr < allLinks.length; ctr++) {
        if (allLinks[ctr].className.indexOf("menuLink") > -1) {
            allLinks[ctr].onclick = toggleMenu;
        } // end if (allLinks[ctr].className.indexOf("menuLink" > -1)
    } // end for (var ctr=0; ctr < allLinks.length; ctr++)
} // end function




/* *****************************************************
   *                   Function toggleMenu()           *
   ***************************************************** */

function toggleMenu() {


  var currMenu = this.href;
  var startMenu = currMenu.lastIndexOf("/")+1;
  var stopMenu = currMenu.lastIndexOf(".");
  var thisMenuName = currMenu.substring(startMenu, stopMenu);



  var thisMenu = document.getElementById(thisMenuName);

  if (thisMenu.style.display == "block") {
      thisMenu.style.display = "none";
  }
  else {
      thisMenu.style.display = "block";
  }

  return false; 

}
