/*  Functions to deal with the new template for the University 
*/

additionalScripts = function() {
  if (_("tabs")) { // Puts in mouseover for tabs
    for (x=0; x<_("tabs").childNodes.length; x++) {
      if (_("tabs").childNodes[x].tagName) { if (_("tabs").childNodes[x].tagName.match(/^li$/i)) {
        if (_("tabs").childNodes[x].className!="active") {
          _("tabs").childNodes[x].onmouseover = function() { showTabMenu(this, true); }
          _("tabs").childNodes[x].onmouseout = function() { showTabMenu(this); }
        }
      } }
    }
  }

  if (_("menu")) { // Adds in the expand bar for submenu items
    addSubmenuExpand();
  }
}

function showTabMenu(parent, show) {
  for (x=0; x<parent.childNodes.length; x++) {
    if (parent.childNodes[x].tagName) { if (parent.childNodes[x].tagName.match(/^span$/i)) {
      for (y=0; y<parent.childNodes[x].childNodes.length; y++) {
        if (parent.childNodes[x].childNodes[y].tagName) { if (parent.childNodes[x].childNodes[y].tagName.match(/^ul$/i)) {
          parent.childNodes[x].childNodes[y].style.display = show ? "block" : "none";
        } }
      }
    } }
  }
  return;
}

function addSubmenuExpand() {
return; // Existing scripts from DPM already insert these.
  for (x=0; x<_("menu").childNodes.length; x++) {
    if (_("menu").childNodes[x].tagName) { if (_("menu").childNodes[x].tagName.match(/dl/i)) {
      for (y=0; y<_("menu").childNodes[x].childNodes.length; y++) {
        if (_("menu").childNodes[x].childNodes[y].tagName) { if (_("menu").childNodes[x].childNodes[y].tagName.match(/dd/i)) {
          for (z=0; z<_("menu").childNodes[x].childNodes[y].childNodes.length; z++) {
            if (_("menu").childNodes[x].childNodes[y].childNodes[z].tagName) { if (_("menu").childNodes[x].childNodes[y].childNodes[z].tagName.match(/ul/i)) {
              for (a=0; a<_("menu").childNodes[x].childNodes[y].childNodes[z].childNodes.length; a++) {
                if (_("menu").childNodes[x].childNodes[y].childNodes[z].childNodes[a].tagName) { if (_("menu").childNodes[x].childNodes[y].childNodes[z].childNodes[a].tagName.match(/li/i)) {
                  for (b=0; b<_("menu").childNodes[x].childNodes[y].childNodes[z].childNodes[a].childNodes.length; b++) {
                    var menuItem = _("menu").childNodes[x].childNodes[y].childNodes[z].childNodes[a].childNodes[b];
                    if (menuItem.tagName) { if (menuItem.tagName.match(/ul/i)) {
                      var expand = document.createElement("span");
                      expand.className = "hide_text expander closed"; expand.innerHTML = "expand"; expand.style.padding = "2px 2px 2px 2px";
                      expand.onclick = function() { expandSubmenu(this, true); }
                      var container = document.createElement("div");
                      container.style.margin = "0px"; container.style.overflow = "hidden"; container.style.position = "relative"; container.height = "0px";
                      menuItem.parentNode.appendChild(expand);
                      menuItem.parentNode.appendChild(container);
                      menuItem.parentNode.removeChild(menuItem);
                      container.appendChild(menuItem);
                    } }
                  }
                } }
              }
            } }
          }
        } }
      }
    } }
  }
  return;
}

function expandSubmenu(obj, on) {
  obj.className = on ? "hide_text expander open" : "hide_text expander closed";
  obj.onclick = function() { expandSubmenu(this, (on ? false : true)); };
  obj.nextSibling.style.height = on ? "auto" : "0px";

  for (x=0; x<obj.nextSibling.childNodes.length; x++) {
    if (obj.nextSibling.childNodes[x].tagName) { if (obj.nextSibling.childNodes[x].tagName.match(/ul/i)) {
      obj.nextSibling.childNodes[x].className = on ? "unstatic" : "static";
    } }
  }
}

