// this version closes the sub-menu when on the current page/section

// set this variable to the section you want to be displayed by default
var thissectionid = "thispage";
var sectionid = "s";
var indexpage = 'index.php';

sM = {
  init: function() {
  s=1;
  q=1;
    var uls = document.getElementsByTagName('ul');
    for (var u = 0; u < uls.length; u++) {
      if (uls[u].id.search(/\bmenulist\b/) == -1) continue;
       var lis = uls[u].getElementsByTagName('li');
      for (var i = 0; i < lis.length; i++) {
        var node = lis[i];
        if (node.nodeName.toLowerCase() == 'li' &&
            node.getElementsByTagName('ul').length > 0) {
          sM.addEvent(node, 'mouseover', sM.getMoverFor(node), false);
          sM.addEvent(node, 'mouseout', sM.getMoutFor(node), false);
          node.getElementsByTagName('a')[0].className += ' subheader';
          node.isIn = false;
          
        } // end if node
             //  get current section and page
          thissection = '';
            thissection = amHere(node,s);
          if(thissection == "y" ){
	//	  if(node.getElementsByTagName('ul')[0]){node.getElementsByTagName('ul')[0].id = thissectionid;}
	//	  else {
	//	  newdiv = document.createElement('div');
	//	  node.appendChild(newdiv);
	//	  node.getElementsByTagName('div')[0].id = thissectionid;
	//	  }
		  if(node.getElementsByTagName('a')[0].className.indexOf('thispage') == -1){
			  node.getElementsByTagName('a')[0].className += ' thispage';
			  }
	  	} // end if thissection
   } // end for  
      
      ulli = uls[u];

    } // end for
          for (var j = 0; j < ulli.childNodes.length; j++) {
          // give top level links classes  numbered section
          //alert(ulli.childNodes[j].nodeName.toLowerCase());
             if (ulli.childNodes[j].nodeName.toLowerCase() == 'li'){
             	for (f=0; f < ulli.childNodes[j].getElementsByTagName('a').length; f++){
		ulli.childNodes[j].getElementsByTagName('a')[f].className += ' s' + s;
		}
		s++;
		
	       }  // end if
	       
 	    } // end for
 	    
 // showThisMenu();
  },
  
  


  


  addEvent: function(elm, evType, fn, useCapture) {
    // cross-browser event handling for IE5+, NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener) {
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent) {
      var r = elm.attachEvent('on' + evType, fn);
      EventCache.add(elm, evType, fn);
      return r;
    } else {
      elm['on' + evType] = fn;
    }
  }
};

sM.addEvent(window, 'load', sM.init, false);
sM.addEvent(window, 'unload', EventCache.flush, false);

function amHere(node,s) {
thishref = document.location.href;
thisNode = node.getElementsByTagName('a').length;
foundpage = '';
for(var t=0; t<thisNode; t++) {
	thislink = node.getElementsByTagName('a')[t].href;
	// test for url with no page name, and add indexpage to href
	if(thishref.length == thishref.lastIndexOf('/') +1) {thishref += indexpage; }
	if (thishref != ''  && thishref.indexOf(thislink) != -1 && node.getElementsByTagName('a')[t].className.indexOf('thispage') == -1) {
	   node.getElementsByTagName('a')[t].className += ' thispage';
	   foundpage = "y";
	   }

	}
return foundpage;
}



