function addDropdownMenuBarHandlers()
{
  // get all dropdown menu bars
  var menuBars = resetMenubars();

  for (var i = 0; i < menuBars.length; i ++)
  {
    for (var j = 0; j < menuBars[i].items.length; j ++)
    {
      menuBars[i].items[j].dropdown = document.getElementById("webUI_dropdownmenu" + menuBars[i].items[j].id.substr("webUI_menubaritem".length,menuBars[i].items[j].id.length));

      if (menuBars[i].items[j].id && !menuBars[i].items[j].dropdown)
      {
        alert("Initialisation error:\nOne or more of the menu bar items don't have a dropdown menu associated");
        return false;
      }

      menuBars[i].items[j].closeHandler=resetItem(menuBars[i].items[j]);

      menuBars[i].items[j].onclick=function(e)
      {
        this.className = "webUI_menubaritem hover";
        if(this.dropdown)
        {
          openSubmenu(this.dropdown
                     ,getLeftPosition(this) + this.offsetWidth
                     ,getTopPosition(this)
                     ,this.closeHandler
                     );
        }
        this.parentNode.openMenu = this.dropdown;
        return this.href != '' && this.href.split('#')[0] != location.href.split('#')[0];
      }
      menuBars[i].items[j].onmousedown=function(e)
      {
        this.onclick();
        if (document.attachEvent) //IE
          window.event.cancelBubble = true;
        else
          e.stopPropagation();
      }
      menuBars[i].items[j].onmouseover=function()
      {
        this.className = "webUI_menubaritem hover";

        //find out if there is an open menu, NOT belonging to this item.
        if (this.parentNode.openMenu && this.parentNode.openMenu != this.dropdown && this.parentNode.openMenu.style.visibility == "visible")
        {
          // close the menu
          closeSubmenu(this.parentNode.openMenu);
        }

          // open the menu beloging to the current item
          this.onclick();

          // reset all the appearance of all menu items
          for (var i=0; i < this.parentNode.items.length; i++)
            this.parentNode.items[i].className = "webUI_menubaritem";

          // make the current item beautiful
          this.className = "webUI_menubaritem hover";
//        }
      }
      menuBars[i].items[j].onmouseout=function()
      {
        if (this.parentNode.openMenu == null || this.parentNode.openMenu.style.visibility != "visible")
          this.className = "webUI_menubaritem";
      }
    }
  }
}

function resetItem(item)
{
  return function(e)
  {
    item.className = "webUI_menubaritem";
  }
}

function resetMenubars()
{
  // get all dropdown menu bars
  var menuBars = getElementsByClass(document,"webUI_menubar","DIV");
  for (var i = 0; i < menuBars.length; i ++)
  {
    menuBars[i].openMenu = null;
    menuBars[i].items = getElementsByClass(menuBars[i],"webUI_menubaritem","A");
    for (var j = 0; j < menuBars[i].items.length; j++)
      menuBars[i].items[j].className = "webUI_menubaritem";
  }
  return menuBars;
}
