function ie7 () {
  if (typeof document.body.style.maxHeight != "undefined") {
    // IE 7, mozilla, safari, opera 9
    return true;
  } else {
    // IE6, older browsers
    return false
  }
}

function getWidth(obj) { return obj.offsetWidth; }

function setWidth(obj, newWidth) {
  //alert("setting width of "+obj+" to "+newWidth);
  if (document.all&&document.getElementById) {
    //newWidth -= 3;
    obj.style.width = newWidth;
  } else {
    //newWidth -= 1;
    obj.style['width'] = newWidth+"px";
  }
}

function setLeftMargin(obj, newLeftMargin) {
  //obj.style.marginLeft = newLeftMargin;
}


startList = function() {
  if (document.all&&document.getElementById) {
    navRootHeader = document.getElementById("header_nav_ul");
    assignMouseOvers(navRootHeader, false, false, true, false);
    navRootFooterMain = document.getElementById("footer_nav_main_ul");
    assignMouseOvers(navRootFooterMain, false, false, false, true);
    navRootFooterCases = document.getElementById("footer_nav_cases_ul");
    assignMouseOvers(navRootFooterCases, false, false, false, true);
  }
}

var liWidth = null;
var ulOffset = null;

function assignMouseOvers(navRoot, inSubmenu, inSubSubmenu, updateCSS, updateHeight) {
  /*if (inSubSubmenu) {
    alert("in sub sub menu & liwidth: "+liWidth);
  } else if (inSubmenu) {
    alert("in sub menu & liwidth: "+liWidth);
  }*/
  //alert(navRoot.childNodes.length+"\n"+navRoot.innerHTML);
  for (var i=0; i<navRoot.childNodes.length; i++) {
    node = navRoot.childNodes[i];
    if (node.nodeName=="LI") {
      if (updateCSS) {
        if (!inSubmenu) {
          liWidth = getWidth(node);
          //alert("liwidth: "+liWidth);
        } else if (!inSubSubmenu) {
          // set the width of the sub menus to width of parent LI minus
          if (ie7()) {
            setWidth(node, liWidth-25);
          } else {
            setWidth(node, liWidth-28);
          }
        }
      }
      //if (!inSubmenu && !inSubSubmenu) node.style.zIndex = '-5';
      if (updateHeight) {
        node.onmouseover=function() {
          this.className+=" over";
          if (this.childNodes.length > 1) {
            this.childNodes[1].style.height = 'auto';
            // ie6, older browsers
            if (typeof document.body.style.maxHeight == 'undefined') {
              this.childNodes[1].style.marginBottom = '-1';
            }
          }
        }
      } else {
        node.onmouseover=function() {
          this.className+=" over";
        }
      }
      node.onmouseout=function() {
        this.className=this.className.replace(" over", "");
      }
      //alert(node.childNodes.length);
      for (var j=0; j<node.childNodes.length; j++) {
        subNode = node.childNodes[j];
        if (subNode.nodeName=="UL") {
          if (inSubmenu) {
            if (updateCSS) {
              if (ie7) {
                setWidth(subNode, 178);
              } else {
                setWidth(subNode, 180);
              }
            }
            assignMouseOvers(subNode, true, true, updateCSS, updateHeight);
          } else {
            // if the following value is small enough, it doesn't affect ie6,
            // unless it's not set
            if (updateCSS) {
              if (ie7()) {
                setWidth(subNode, liWidth-28);
              } else {
                setWidth(subNode, 1);
              }
            }
            assignMouseOvers(subNode, true, false, updateCSS, updateHeight);
          }
          //alert(subNode.childNodes.length);
        }
      }
    }
  }
  return;
}

//window.onload=startList;
addLoadEvent(startList);
