
function initExpand()
{
 var h2s,i,tohide,tohideobj,isexpanded;
// grab all second level headlines and loop over them
 h2s=document.getElementsByTagName('h4');
 for (i=0;i<h2s.length;i++)
 {
// check for class
	if (h2s[i].className=="showhide") {
// get next sibling (the element to hide, check that it is an element
  tohide=h2s[i].nextSibling;
  while(tohide.nodeType!=1)
  {
   tohide=tohide.nextSibling;
  }
  h2s[i].tohideobj=tohide;
// add the hover function onmouseover and onmouseout
  h2s[i].onmouseover=function(){hover(this,this.tohideobj,1);}
  h2s[i].onmouseout=function(){hover(this,this.tohideobj,0);}
// hide next element and add onclick event to the header to show and hide it
  juggleClass(tohide,'hidden',1);
  juggleClass(h2s[i],'normal',1);
  h2s[i].onclick=function(){collapse(this,this.tohideobj);return false}
  }
 }
 setTimeout('fixBrand()',100);
}
// hover function, adds the hover colour
// unless the headline is an active trigger
function hover(o,ho,state)
{
 if(checkClass(ho,'hidden'))
 {
  if(state==1)
  {
   juggleClass(o,'normal',0);
   juggleClass(o,'hover',1);
  } else {
   juggleClass(o,'normal',1);
   juggleClass(o,'hover',0);
  }
 }
}
// collapse function, shows and hides the element and sets the highlight
// colour of the headline
function collapse(o,ho)
{
 if(checkClass(ho,'hidden'))
 {
  juggleClass(ho,'hidden',0);
  juggleClass(o,'normal',0);
  juggleClass(o,'highlight',1);
 }else{
  juggleClass(ho,'hidden',1);
  juggleClass(o,'highlight',0);
  juggleClass(o,'normal',1);
 }
 //setTimeout('fixBrand()',100);
}
	function juggleClass(o,c,s)
	{
		if(s==0)
		{
			o.className=o.className.replace(c,'');	
		}
		if (s==1 && !checkClass(o,c))
		{
			o.className+=' '+c
		}
	}

function checkClass(o,c)
{
	var re=new RegExp('\\b'+c+'\\b');
	return re.test(o.className);
}

function fixBrand() {
	// This function forces the brand to move when they browser doesn't
	//   feel like recalculating its position automatically.
	// Always call with setTimeout, to move it after the initial 'collapse' repaint
	//document.getElementById("brand").style.bottom="0";
	//document.getElementById("brand").style.bottom="6px";
}

function expandAll() {
	// This function will force all items to expand.  Note that
	//   setTimeout has no issue here because we're not calling collapse
	x=document.getElementsByTagName('h4');
	for(var i=0; i<x.length; i++) {
	  juggleClass(x[i].tohideobj, 'hidden', 0);
	}
	//setTimeout('fixBrand()',100);
}

addEvent(window, 'load', initExpand);
