//### INCLUDE WHITE.JS

/*#############################################################################
# Show submenu
#############################################################################*/
function showSubMenu(){
  var oElement     = this;
  var sMarginIE    = "0em";
  var sMarginNS    = "0em";
  var iButtonWidth = 120;
  var iMarginTop   = -1;
  var bMarginTop   = false;
  var bOpensDown   = true;
  var iExplorerVersion = parseFloat(navigator.appVersion.split("MSIE")[1]);

  if ('object' == typeof oElement)
  {
    for(var iTel = 0; iTel < oElement.childNodes.length; iTel++)
    {
      if(oElement.childNodes.item(iTel).nodeName == "A")
      {
        //# Set margins on intro submenu
        if (WHITE_HasClassName(oElement.childNodes.item(iTel), "intro_mainitem"))
        {
          WHITE_AddClassName(oElement.childNodes.item(iTel), 'intro_mainitem_on');
          sMarginIE = "42px 0px 0px -" + (oElement.childNodes.item(iTel).offsetWidth+3) + "px";
          sMarginNS = "-1px 0px 0px 0px";
          iButtonWidth = (oElement.childNodes.item(iTel).offsetWidth);
          bMarginTop = false;
          bOpensDown = false;
        }
        //# Set margins on intro subsubmenu
        if (WHITE_HasClassName(oElement.childNodes.item(iTel), "intro_subitem"))
        {
          WHITE_AddClassName(oElement.childNodes.item(iTel), 'intro_subitem_on');
          sMarginIE = "-24px 0px 0px " + (oElement.childNodes.item(iTel).offsetWidth/2) + "px";
          sMarginNS = "-24px 0px 0px " + (oElement.childNodes.item(iTel).offsetWidth) + "px";
          bMarginTop = true;
          bOpensDown = false;
        }
        //# Set margins on submenu
        if (WHITE_HasClassName(oElement.childNodes.item(iTel), "mainitem"))
        {
          WHITE_AddClassName(oElement.childNodes.item(iTel), 'mainitem_on');
          sMarginIE   = "24px 0px 0px -" + (oElement.childNodes.item(iTel).offsetWidth+3) + "px";
          sMarginNS   = (iExplorerVersion >= 8) ? "-2px 0px 0px 0px":"-1px 0px 0px 0px";
          iButtonWidth = (oElement.childNodes.item(iTel).offsetWidth);
        }
        //# Set margins on subsubmenu
        if (WHITE_HasClassName(oElement.childNodes.item(iTel), "subitem"))
        {
          WHITE_AddClassName(oElement.childNodes.item(iTel), 'subitem_on');
          sMarginIE = "-25px 0px 0px " + (oElement.childNodes.item(iTel).offsetWidth/2) + "px";
          sMarginNS = "-25px 0px 0px " + (oElement.childNodes.item(iTel).offsetWidth) + "px";
        }
      }

      if(oElement.childNodes.item(iTel).nodeName == "UL")
      {
        if ('Microsoft Internet Explorer' == navigator.appName && 8 > iExplorerVersion)
        {
          oElement.childNodes.item(iTel).style.margin = sMarginIE;
          oElement.childNodes.item(iTel).style.left = "auto";
          if (!bMarginTop)
          {
            iMarginTop = 0;
          }
        }
        else if('Netscape' == navigator.appName || ('Microsoft Internet Explorer' == navigator.appName && 8 <= iExplorerVersion))
        {
          oElement.childNodes.item(iTel).style.margin = sMarginNS;
          if(8 <= iExplorerVersion) {
            oElement.childNodes.item(iTel).style.left = "auto"; /* IE8 still needs this part */
          }
          if (!bMarginTop)
          {
            iMarginTop = 43;
          }
        }

        //# Submenu opens to top of mainitem
        if (!bOpensDown)
        {
          oElement.childNodes.item(iTel).style.marginTop = '-' + (oElement.childNodes.item(iTel).offsetHeight + iMarginTop) + 'px';
        }

        //### Change width of submenu to fit mainitem buttonwidth
        if (iButtonWidth > oElement.childNodes.item(iTel).offsetWidth)
        {
          oElement.childNodes.item(iTel).style.width = iButtonWidth + 'px';
        }
      }
    }
  }
}

/*#############################################################################
# Hide submenu
#############################################################################*/
function hideSubMenu()
{
  var oElement = this;

  if ('object' == typeof oElement)
  {
    for(var iTel = 0; iTel < oElement.childNodes.length; iTel++)
    {
      if('UL' == oElement.childNodes.item(iTel).nodeName)
      {
        if ('Microsoft Internet Explorer' == navigator.appName) {
          oElement.childNodes.item(iTel).style.left = "-9999px";
        }
      }

      if('A' == oElement.childNodes.item(iTel).nodeName)
      {
        if (WHITE_HasClassName(oElement.childNodes.item(iTel), 'intro_mainitem_on'))
        {
          WHITE_RemoveClassName(oElement.childNodes.item(iTel), 'intro_mainitem_on');
        }
        if (WHITE_HasClassName(oElement.childNodes.item(iTel)), 'intro_subitem_on')
        {
          WHITE_RemoveClassName(oElement.childNodes.item(iTel), 'intro_subitem_on');
        }
        if (WHITE_HasClassName(oElement.childNodes.item(iTel), 'mainitem_on'))
        {
          WHITE_RemoveClassName(oElement.childNodes.item(iTel), 'mainitem_on');
        }
        if (WHITE_HasClassName(oElement.childNodes.item(iTel)), 'subitem_on')
        {
          WHITE_RemoveClassName(oElement.childNodes.item(iTel), 'subitem_on');
        }
      }
    }
  }
}

/*#############################################################################
# Initialize submenu
#############################################################################*/
function initialiseMenu()
{
  var oMainMenu = WHITE_GetElementsByClass(document, 'listmenu');
  if (oMainMenu)
  {
    for(var iTelX = 0; iTelX < oMainMenu.length; iTelX++)
    {
      var oListItems = oMainMenu[iTelX].getElementsByTagName("LI");
      for(var iTelY = 0; iTelY < oListItems.length; iTelY++)
      {
        var oListItem = oListItems[iTelY];
        for(var iTelZ = 0; iTelZ  < oListItem.childNodes.length; iTelZ++)
        {
          if('UL' == oListItem.childNodes.item(iTelZ).nodeName)
          {
            oListItem.onmouseout  = hideSubMenu;
            oListItem.onmouseover = showSubMenu;
          }
        }
      }
    }
  }
}

/*#############################################################################
# Start initializing on onload of body
#############################################################################*/
if ('function' == typeof WHITE_AddLoadEvent)
{
  WHITE_AddLoadEvent(initialiseMenu);
}
