/*
//SuckerTree Horizontal Menu (Sept 14th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/
*/
function buildMenus(){
    var ultags=document.getElementsByTagName("div");
    for (var i=0; i<ultags.length; i++){
        if(ultags[i].className == "hvvMenu") {
            buildHvvMenu(ultags[i],0, "T", "T");
        } else if(ultags[i].className == "vMenu") {
            buildVerticalMenu(ultags[i],0, "T", "T");
        }
    }
}

function buildHvvMenu(theObject, level, first, last){
    var first, last;
    var align, lastChild;
    var theChildren = theObject.childNodes;
    for(var u=0; u<theChildren.length; u++) {
        if(theChildren[u].nodeType == 1) {
            if (theChildren[u].tagName == "LI") {
                lastChild = theChildren[u];
            }
        }
    }
    for(var u=0; u<theChildren.length; u++) {
        if(theChildren[u].nodeType == 1) {
            if (theChildren[u].tagName == "UL") {

                buildHvvMenu(theChildren[u],level+1,  "T", "T");
                if (level == 1) {
                    //dynamically position first level submenus to be height of main menu item
                    //theChildren[u].style.top = theChildren[u].offsetParent.offsetHeight+"px";
                    //theChildren[u].style.left = theChildren[u].offsetParent.offsetLeft+"px";
                } else if (level > 1) {
                    //position menu to the right of menu item that activated it
                    /* theChildren[u].style.left=theChildren[u].parentNode.getElementsByTagName("a")[0].offsetWidth+"px"; */
                    //theChildren[u].style.top = theChildren[u].offsetParent.offsetHeight+"px";
                    theChildren[u].style.left = theChildren[u].offsetParent.offsetWidth+"px";
                }
                if (level > 0) {
                    theChildren[u].parentNode.onmouseover=function(){
                        var theElement = this.getElementsByTagName("UL")[0];
                        theElement.style.visibility="visible";
                    };
                    theChildren[u].parentNode.onmouseout=function(){
                        this.getElementsByTagName("UL")[0].style.visibility="hidden";
                    };
                }
            } else if (theChildren[u].tagName == "A" ) {
                if (level === 1) {
                    align = "H";
                } else {
                    align = "V";
                }
                buildDisplayItem(theChildren[u],align,first,last);
            } else if (theChildren[u].tagName == "LI") {
                if (u===0) {
                    first = "T";
                } else {
                    first = "F";
                }
                if (theChildren[u]==lastChild) {
                    last = "T";
                }  else {
                    last ="F";
                }
                buildHvvMenu(theChildren[u],level, first, last);
            } else {
                buildHvvMenu(theChildren[u],level, first, last);
            }
        }
    }
}

function buildVerticalMenu(theObject, level, first, last){
  var first, last;
  var align;
    var theChildren = theObject.childNodes;
    for(var u=0; u<theChildren.length; u++) {
        if(theChildren[u].nodeType == 1) {
            if (theChildren[u].tagName == "UL") {
                buildVerticalMenu(theChildren[u],level+1,  "T", "T");
                //position menu to the right of menu item that activated it
                /* theChildren[u].style.left=theChildren[u].parentNode.getElementsByTagName("a")[0].offsetWidth+"px"; */
                theChildren[u].style.left="0 px";
                if (level > 0) {
                    theChildren[u].parentNode.onmouseover=function(){
                        this.getElementsByTagName("ul")[0].style.visibility="visible";
                    };
                    theChildren[u].parentNode.onmouseout=function(){
                        this.getElementsByTagName("ul")[0].style.visibility="hidden";
                    };
                }
            } else if (theChildren[u].tagName.toString() == "A" ) {
                align = "V";
                buildDisplayItem(theChildren[u],align,first,last);
            } else if (theChildren[u].tagName == "LI") {
                if (u===0) {
                    first = "T";
                } else {
                    first = "F";
                }
                if (u==theChildren.length-1) {
                    last = "T";
                }  else {
                    last ="F";
                }
                buildVerticalMenu(theChildren[u],level, first, last);
            } else {
                buildVerticalMenu(theChildren[u],level, first, last);
            }
        }
    }
}

function buildDisplayItem(theItem,align,first,last) {
  /*
    theItem - a Dom object
    align - either horizontal "H", or vertical "V"
    first - either first "T" or "F"
    last - either last "T" or "F"
  */
  var  leftDiv, rightDiv;
  var  suffix;
  suffix = "";
   if(align == "H") {
    if(first == "T") {
      suffix = suffix+"L";
    }
    if(last == "T") {
      suffix = suffix+"R";
    }
    if(first == "F" && last == "F") {
      suffix = suffix+"C";
    }
  } else {
    if(first == "T") {
      suffix = suffix+"T";
    }
    if(last == "T") {
      suffix = suffix+"B";
    }
    if(first == "F" && last == "F") {
      suffix = suffix+"M";
    }
  }

  /* Create the objects needed for display */
  leftDiv = document.createElement("div");
  rightDiv = document.createElement("div");
  /* Build and assign the appropriate class names
     to the objects */
  leftDiv.className = theItem.className+"L"+suffix+" outer";
  rightDiv.className = theItem.className+"R"+suffix+" inner";
  theItem.className = theItem.className+"C"+suffix+ " link";
/*   alert(leftDiv.className+" "+rightDiv.className+" "+theItem.className);*/

  /* replace the item with the outer div to allow the
     item to be added to the inner div */
  theItem.parentNode.replaceChild(leftDiv,theItem);

  /* build the heirarchy */
  leftDiv.appendChild(rightDiv);
  rightDiv.appendChild(theItem);

}

  var oldOnLoad;

  oldOnLoad = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = function() {
      buildMenus();
    };
  } else {
    window.onload = function() {
      oldOnLoad();
      buildMenus();
    };
  }

