window.onload=function () { rollup('mainnav'); if (document.getElementById('subnav')) rollup('subnav'); };

var notWhitespace = /\S/;

function cleanWhitespace(node) {
   for (var x = 0; x < node.childNodes.length; x++) {
      var childNode = node.childNodes[x];
      if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
         node.removeChild(node.childNodes[x]);
         x--;
      }
      if (childNode.nodeType == 1) {
         cleanWhitespace(childNode);
      }
   }
}

function rollout(strMenu, objMenuitem, objEvent) {
   var iKeyCode, strDisplay, objMenu, objNested;

   if (document.getElementById('jsKeepOpen'))
      document.getElementById('jsKeepOpen').id = '';

   if (objEvent && objEvent.type == 'keypress') {
      if (objEvent.keyCode)
         iKeyCode = objEvent.keyCode;
      else if (objEvent.which)
         iKeyCode = objEvent.which;

      if (iKeyCode != 13 && iKeyCode != 32)
         return true;
   }

   if (objMenuitem.nextSibling.style.display == 'block') {
      strDisplay = 'none';
      strClass = 'inactive';                                         
   }
   else {
      strDisplay = 'block';
      strClass = 'active';
   }

   var objMenu = document.getElementById(strMenu);
   var objNested = objMenu.getElementsByTagName('ul');

   for (var i=0; i<objNested.length; i++)
      if (objNested[i].style.display == 'block') {
         objNested[i].style.display = 'none';
         objNested[i].parentNode.className = 'inactive';
      }

   objMenuitem.nextSibling.style.display = strDisplay;
   objMenuitem.parentNode.className = strClass;
    
   while (objMenuitem.parentNode.parentNode.id != strMenu) {
      objMenuitem = objMenuitem.parentNode.parentNode;
      objMenuitem.style.display = 'block';
      objMenuitem.parentNode.className = 'active';
   }

   return false;
}

function rollup(strMenu) {
   var strLocation, objMenu, objNested, bRollup, objLinks, objNode, objAnchor, objText, objKeepOpen;

   if (document.getElementById && document.createElement) {
      cleanWhitespace(document);

      strLocation = String(window.location);
      strLocation = strLocation.replace(/https?:\/\/(www.)?attac.de/, '');
      strLocation1 = strLocation;
      strLocation2 = strLocation.substring(0, strLocation.lastIndexOf('/') + 1);
      objMenu = document.getElementById(strMenu);
      objNested = objMenu.getElementsByTagName('ul');

         objLinks = objMenu.getElementsByTagName('a');
         for (var j=0; j<objLinks.length; j++) {
            strLink = String(objLinks[j].href);
            strLink = strLink.replace(/https?:\/\/(www.)?attac.de/, '');
            if (strLink == strLocation1 || strLink == strLocation2) {
               objLinks[j].id = 'jsKeepOpen';
            }
         }

      for (var i=0; i<objNested.length; i++) {
         bRollup = true;
         objLinks = objNested[i].getElementsByTagName('a');

         for (var j=0; j<objLinks.length; j++) {
            strLink = String(objLinks[j].href);
            strLink = strLink.replace(/https?:\/\/(www.)?attac.de/, '');
            if (strLink == strLocation1 || strLink == strLocation2) {
               bRollup = false;
               objLinks[j].id = 'jsKeepOpen';
            }
         }

         if (bRollup == true) {
            objNested[i].style.display = 'none';
            objNested[i].parentNode.className = 'inactive';
         }
         else {
            objNested[i].style.display = 'block';
            objNested[i].parentNode.className = 'active';
         }

         objNode = objNested[i].parentNode;
         objText = document.createTextNode('\u00bb');

         objAnchor = document.createElement('a');
         objAnchor.href = '#';       
         objAnchor.title = '\u00bb';             
         objAnchor.className = 'foldOut';
         objAnchor.onclick = function(event){return rollout(strMenu, this.nextSibling, event);}
         objAnchor.onkeypress = function(event){return rollout(strMenu, this.nextSibling, event);}
         objAnchor.appendChild(objText);

         objNode.insertBefore(objAnchor, objNested[i].previousSibling);
         objNested[i].previousSibling.className = 'subMenu';
      }

      if (document.getElementById('jsKeepOpen')) {
         objKeepOpen = document.getElementById('jsKeepOpen');
         if (objKeepOpen.nextSibling) {
            objKeepOpen.nextSibling.style.display = 'block';
            objKeepOpen.parentNode.className = 'active';
         }

         while (objKeepOpen.parentNode.parentNode.id != strMenu) {
            objKeepOpen = objKeepOpen.parentNode.parentNode;
            objKeepOpen.style.display = 'block';
            objKeepOpen.parentNode.className = 'active';
         }
      }   
   }     
}
