/*
collapsible menus
written by Kae Verens - kae@verens.com
you are free to use this. please retain these comments, though.
if there are any questions/suggestions for the code, please email me.

usage:
1. create your menu as a hierarchy of unordered lists. for example
 <ul>
  <li><a href="/">home</a>
   <ul>
    <li><a href="/aboutme">about me</a></li>
    <li><a href="/contact">contact me</a></li>
   </ul>
  </li>
  <li><a href="/gallery">photo gallery</a></li>
 </ul>
2. place this script in your directory
3. link this script into every page that has the menu:
 <script type="text/javascript" src="cm.js"></script>

*/

/*
slight tweaks and modifications added by Michael
*/

var parentLinkIsOpener=0; // whether to use parent link/text as opener, overriding its own link

if(window.attachEvent)window.attachEvent('onload',cm);
else if(window.addEventListener)window.addEventListener('load',cm,false);

function cm(){
 cmId=0;
 if(!document.getElementsByTagName)return; // reject non-compliant browsers
 a=document.getElementById('archivemenus').getElementsByTagName('ul');
 for(i=0;a[i];i++){
  if(a[i].getElementsByTagName('ul')){
   // a[i] is an object which has a collapsible list in it
   b=a[i].childNodes;
   for(j=0;b[j];j++){
    if(b[j].nodeName=='LI'){
     d=b[j].getElementsByTagName('ul');
     if(d.length){
      c=document.createElement('a');
      c.setAttribute('href','javascript:cmSwitch("cm'+(cmId)+'")');
      c.setAttribute('id','cm'+(cmId)+'a');
      c.setAttribute('title','click to expand');
      c.setAttribute('class','plusminuslinks');
      if(parentLinkIsOpener){
       // we've chosen to use the parent link as the opener
       var e=b[j].innerHTML;
       e=e.replace(/(\n|\r)/g,'');
       e=e.replace(/(<ul|<UL).*/,'');
       e=e.replace(/<[^>]*>/g,'');
       c.innerHTML=e;
       b[j].replaceChild(c,b[j].childNodes[0]);
      }else{
       // create a new [+] link as the opener
       c.style.display='inline';
       c.innerHTML='[+] ';
       b[j].insertBefore(c,b[j].firstChild);
      }
      d[0].setAttribute('id','cm'+(cmId++));
      d[0].style.display='none';
     }
    }
   }
  }
 }
}

function cmSwitch(id){
 a=document.getElementById(id);
 b=document.getElementById(id+'a');
 
 if (a.style.display=='block') {
    a.style.display = 'none';
    
     // switch_id.className = 'hideSwitch';
	//  menus_status_array[theid] = 'hide';
	//  document.cookie = theid+'=hide';
    b.setAttribute('class','hasitem plusminuslinks');
    b.setAttribute('title','click to expand');
    b.setAttribute('onfocus','this.blur();'); // removes dotted focus line
    
 } else {
    a.style.display = 'block';
    b.setAttribute('class','listexpand plusminuslinks');
    b.setAttribute('title','click to collapse');
    b.setAttribute('onfocus','this.blur();'); // removes dotted focus line
 }
 
 if(parentLinkIsOpener) { return; }

 b.innerHTML=(b.innerHTML=='[+] ')?'[-] ':'[+] ';
}