function initmenus() {
 initmenu('pageblock',document.getElementById('currentpagelink').href,"white");
 initmenu('sectionblock',document.getElementById('currentsectionlink').getAttribute("href"),"#FFFFCF");
 inittabs();
 initopenmenu('foldermenublock');
}

function inittabs() {
 var theSpecElement=document.getElementById("tabselection"),theTabElement;
 if (!theSpecElement) return;
 theTabElement=document.getElementById(theSpecElement.value);
 if (theTabElement) {
  theTabElement.className="selected";
 }
}

function initopenmenu(blockname) {
 var theBlockElement=document.getElementById(blockname);
 if (!theBlockElement) return;
 var thelist=theBlockElement.getElementsByTagName('li');
 var theLength=thelist.length,theSublist,theElement,theParent,theChild;
 for (var i=0;i<theLength;i++) {
  theElement=thelist[i];
  theSublist=theElement.getElementsByTagName('ul');
  var theNewNode = document.createElement('div');
  if (theSublist.length>0) {
    theNewNode.style.backgroundImage='url(/common/graphics/arrowdown.gif)';
  } else {
    theNewNode.style.backgroundImage='url(/common/graphics/disc.gif)';
  }
  theNewNode.className='icon';
  theElement.insertBefore(theNewNode,theElement.firstChild);
 }
}

function initmenu(blockname,hrefspec,theColor) {
 var theBlock=document.getElementById(blockname);
 if (!theBlock) return;
 var thelist=theBlock.getElementsByTagName('li');
 var theLength=thelist.length,theSublist,theElement,theParent,theChild;
 for (var i=0;i<theLength;i++) {
  theElement=thelist[i];
  theSublist=theElement.getElementsByTagName('ul');
  if (!(theElement.firstChild.tagName=='DIV')) {
   var theNewNode = document.createElement('div');
   if (theSublist.length>0) {
    theNewNode.style.backgroundImage='url(/common/graphics/plus.gif)';
    theNewNode.setAttribute('dlmenustatus',"closed");
    theNewNode.style.cursor='pointer';
    theNewNode.onclick=togglesubmenu;
   } else {
    theNewNode.style.backgroundImage='url(/common/graphics/disc.gif)';
    theNewNode.setAttribute('dlmenustatus',"leaf");
   }
   theNewNode.className='icon';
   theElement.insertBefore(theNewNode,theElement.firstChild);
  }
 }
 var thelist=document.getElementById(blockname).getElementsByTagName('a');
 theLength=thelist.length
 for (var i=(theLength-1);i>=0;i--) {
  theElement=thelist[i];
  if (theElement.href==hrefspec) {
   theElement.className = "selected";
   theElement.style.backgroundColor=theColor;
   if (blockname=='pageblock') {
    var theSelectedElement=theElement;
   }
   theParent=theElement.parentNode;
   while (!(theParent.tagName=="LI")) {
    theParent=theParent.parentNode;
   }
   for (var i=0;i<theParent.childNodes.length;i++) {
    theChild=theParent.childNodes[i];
    if (theChild.tagName=='UL') {
     theChild.style.display='block';
     theParent.firstChild.style.backgroundImage='url(/common/graphics/arrowdown.gif)';
     theParent.firstChild.setAttribute('dlmenustatus',"selectionnode");
     theParent.firstChild.style.cursor='default';
    }
   }
   var theTestElement=theElement;
   while (!((theTestElement.id) && (theTestElement.id==blockname))) {
    theTestElement=theTestElement.parentNode;
    if (theTestElement.tagName=='UL') {
     theTestElement.style.display='block';
     theParent=theTestElement.parentNode;
     if (theParent.tagName=="LI") {
      theParent.firstChild.style.backgroundImage='url(/common/graphics/arrowdown.gif)';
      theParent.firstChild.setAttribute('dlmenustatus',"selectionnode");
      theParent.firstChild.style.cursor='default';
     }
    }
   }
   break;
  }
 }
 if (theSelectedElement) {
  theElement=theSelectedElement;
  theElement.id="menubridgeselection";
  var theCoords=getCoords(theElement);
  var theNewElement = document.createElement('div');
  theNewElement.style.position="absolute";
  theNewElement.id="menubridge";
  theNewElement.style.top=theCoords.y+"px";
  theNewElement.style.left="151px";
  theNewElement.style.width="20px";
  theNewElement.style.height=theCoords.height+"px";
  theNewElement.style.backgroundColor=theColor;
  var theInsertElement = document.getElementById('page-context');
  theInsertElement.style.position="relative";
  theInsertElement.insertBefore(theNewElement,theInsertElement.firstChild);
 }
}

function togglesubmenu(evt) {
 var theElement=this;
 var theParent=theElement.parentNode,theChild;
 var theDisplayValue;
 if (theElement.getAttribute('dlmenustatus')=='open') {
  theElement.setAttribute('dlmenustatus','closed');
  theElement.style.backgroundImage='url(/common/graphics/plus.gif)';
  theDisplayValue='none';
 } else if (theElement.getAttribute('dlmenustatus')=='closed'){
  theElement.setAttribute('dlmenustatus','open');
  theElement.style.backgroundImage='url(/common/graphics/minus.gif)';
  theDisplayValue='block';
 } else return;
 for (var i=0;i<theParent.childNodes.length;i++) {
  theChild=theParent.childNodes[i];
  if (theChild.tagName=='UL') {
   theChild.style.display=theDisplayValue;
  }
 }
 var theSelectedElement=document.getElementById("menubridgeselection");
 if (theSelectedElement) {
  var theBridgeElement=document.getElementById("menubridge");
  if (theBridgeElement) {
   var theCoords=getCoords(theSelectedElement)
   theBridgeElement.style.top=theCoords.y+"px";
  }
 }
 // for IE 7 to force correct placement of submenu items
 var theBlockElement=document.getElementById('pageblock');
 if (!theBlockElement) return;
 var thelist=theBlockElement.getElementsByTagName('ul');
 var theElement,theDisplay;
 for (var i=0; i<thelist.length-1;i++) {
  theElement=thelist[i];
  theDisplay=theElement.style.display;
  theElement.style.display='none';
  theElement.style.display=theDisplay;
 }
}

function getCoords (element) {
 var coords = { x: 0, y: 0, width: element.offsetWidth, height: element.offsetHeight };
 while (element) {
  coords.x += element.offsetLeft;
  coords.y += element.offsetTop;
  element = element.offsetParent;
 }
 var theUserAgent=navigator.userAgent.toLowerCase();
 var ie6=theUserAgent.indexOf("msie 6.")!=-1;
 if (ie6) {
  coords.y+=1;
 }
 return coords;
}

