//----------------------------------------------------------------------

function extendFullWidth( menu, menuContainerWidth, menuBorderWidth )
{
  var arrayLI = menu.getElementsByTagName("li");
  var i = 0; var j = 0; var k = 0;
  
  for ( i=0; i<arrayLI.length; i++ ) {
    if ( arrayLI[i].className.match(/Tab/i) ) {
      j = getPageX(arrayLI[i]) + arrayLI[i].offsetWidth;
      k++;
    }
  }

  var filler = menuContainerWidth + getPageX(menu) - j;

  if ( filler > 0 ) {
    for ( i=0; i<arrayLI.length; i++ ) {
      if ( arrayLI[i].className.match(/Tab/i) ) {
        arrayLI[i].style.width = ( parseInt( getWidth(arrayLI[i]) ) + Math.round(filler / k) ) + "px";
        filler -= Math.round(filler / k);
        k--;
      }
    }
  }
}

//----------------------------------------------------------------------

function Menu()
{
  var menu = document.getElementById("Menu");
  var menuContainerWidth = 750;
  var menuBorderWidth = 2;
  
  if ( menu ) {
    extendFullWidth( menu, menuContainerWidth, menuBorderWidth );

    var arrayLI = menu.getElementsByTagName("li");

    for ( var i=0; i<arrayLI.length; i++ ) {
      if ( arrayLI[i].className.match(/Tab/i) ) {

        arrayLI[i].onmouseover = function() {
          this.className = "HiLite " + this.className;
          
          if ( this.getElementsByTagName("a")[0].parentNode.className.match(/Tab/i) )
            this.getElementsByTagName("a")[0].className = "HiLite";

          var menuDropDown = this.getElementsByTagName("ul")[0];

          if ( menuDropDown ) {
            menuDropDown.style.top = this.offsetHeight - menuBorderWidth;
            menuDropDown.style.display = "block";
            
            if ( parseInt( getWidth(menuDropDown) ) < this.offsetWidth )
              menuDropDown.style.width = this.offsetWidth + "px";

            var thisOffsetX = getPageX(this);

            if ( (thisOffsetX + menuDropDown.offsetWidth) > (menuContainerWidth + menu.offsetLeft - menuBorderWidth) )
              menuDropDown.style.left = ( (menuContainerWidth + menu.offsetLeft - menuBorderWidth) - (thisOffsetX + menuDropDown.offsetWidth) ) + "px";

            // Patch for IE6/5.x-Select-Ignore-zIndex-Problem
            if ( window.ActiveXObject )
              insertIE6iFrame( menuDropDown );
          }
        };

        arrayLI[i].onmouseout = function() {
          this.className = this.className.replace(/HiLite\s/, "");
          this.getElementsByTagName("a")[0].className = "";
          var menuDropDown = this.getElementsByTagName("ul")[0];

          if ( menuDropDown ) {
            menuDropDown.style.display = "none";

            // Patch for IE6/5.x-Select-Ignore-zIndex-Problem
            if ( window.ActiveXObject )
              removeIE6iFrame( menuDropDown );
          }
        };

      }
    }
  }
}

