// function allows multiple on-load actions
function addEvent(func){
  if (!document.getElementById | !document.getElementsByTagName) return
  var oldonload=window.onload
  if (typeof window.onload != 'function') {window.onload=func}
  else {window.onload=function() {oldonload(); func()}}
}
addEvent(hideAll)
function hideAll(){
  var obj,nextdiv,anchor,content

// get all divs
  obj=document.getElementsByTagName('div')

// run through them
  for (var i=0;i<obj.length;i++){

// if it has a class of trigger
    if(/trigger/.test(obj[i].className)){

// get the adjacent div
      nextdiv=obj[i].nextSibling
      while(nextdiv.nodeType!=1) nextdiv=nextdiv.nextSibling

// hide it
      nextdiv.style.display='none'

//create a link
      anchor=document.createElement('a')

// copy original trigger text and add attributes
      content=document.createTextNode(obj[i].firstChild.nodeValue)
      anchor.appendChild(content)
      anchor.href='#trigger'
      anchor.title='Click to open.'
      anchor.className="trigger"
      anchor.nextdiv=nextdiv
      anchor.onclick= function(){
                        showHide(this.nextdiv);
                        changeTitle(this);
                        return false
                      }
// replace div with created link
         obj[i].replaceChild(anchor,obj[i].firstChild)
    }
  }
}
//Change the div links title attribute accordingly
function changeTitle(obj){
  if(obj)
    obj.title = obj.title=='Click to close' ? 'Click to open' : 'Click to close'
}

//Changes the visibility of an object, in this case the next adjacent div.
function showHide(obj){
  if(obj)
    obj.style.display = obj.style.display=='none' ? 'block' : 'none'
}