/* function to run a function on-load
 *	 this works even if a (or many) 'window.load' have already been set.
 */
function addLoadEvent(func) { 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      if (oldonload) { 
	        oldonload(); 
	      } 
	      func(); 
	    } 
	  } 
	} 


/*
 *	does all the initial hide stuff and builds the link...
 *
 */ 
function hideAll(){
  var obj, content, newstring

  // get all divs
  obj=document.getElementsByTagName('div')

  // run through them
  for (var i=0;i<obj.length;i++){

    // if it has a class of panel-holder
    if (obj[i].className=="panel-holder" ) {
		// hide the next div	
		obj[i+1].style.display='none'
		obj[i].className="panel-holder closed"
		
		// now get the h3		
		x=obj[i].getElementsByTagName("h3");
	 	
		// copy the content
	     content=x[0].innerHTML
	 
		// build ne string as link
		newstring = "<a href=\"javascript: showhide("+ i +")\">"+ content + "</a>"; 
		
		// replace the string	  
	    x[0].innerHTML = newstring; 
	  
    }
  }
}

/*
 * function to show / hide and also replace the class in the 'displayed' block. 
 *
 */
function showhide( element ) {

	blockelement=element+1;
	obj=document.getElementsByTagName('div')
	if( obj[blockelement].style.display=='none' ) {
		obj[blockelement].style.display=''; 
		obj[element].className="panel-holder";
	}
	else {
		obj[blockelement].style.display='none';	
		obj[element].className="panel-holder closed"
	}
}

addLoadEvent(hideAll)