//onload function, from http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function hideLists() {
	//get into the div
	var linksDiv = document.getElementById('collapsingLinks');
	//get an array of the uls in that div
	var linksDivUls = linksDiv.getElementsByTagName('ul');
	//cycle through that array and set each on to display none
	for (var i = linksDivUls.length - 1; i >= 0; i--){
		linksDivUls[i].style.display = 'none';
  		//set an id for the next function
  		linksDivUls[i].id = 'ul'+i;
	};
}
function h3Links() {
	//get into the div
	var linksDiv = document.getElementById('collapsingLinks');
	//get the h3s in the div
	var linksDivh3s = linksDiv.getElementsByTagName('h3');
	//add a show function (defined below) to the h3s
	for (var i = linksDivh3s.length - 1; i >= 0; i--){
		//this grabs the text from the h3
		var h3text = linksDivh3s[i].innerHTML;
		//this replaces everything in the h3, hence the h3text var being between the a tags
		linksDivh3s[i].innerHTML ='<a id="h3a'+i+'" href="#" onclick="showList(\'ul'+i+'\', \'h3a'+i+'\');return false;">'+h3text+'</a>';
	};
}
function showList(list, h3) {
	//list is the id of the ul, then display it as block
	var toshow = document.getElementById(list);
	toshow.style.display = 'block';
	//set the onclick function on the h3 to a hide function
	var h3link = document.getElementById(h3);
	h3link.onclick = function() { hideList(list, h3);return false; };
	//set the background offset on the h3 to show the minus sign
	h3link.parentNode.style.backgroundPosition = "-200px 0";
}
function hideList(list, h3) {
	//list is the id of the ul, then display it as none
	var tohide = document.getElementById(list);
	tohide.style.display = 'none';
	//set the onclick function on the h3 to a show function
	var h3link = document.getElementById(h3);
	h3link.onclick = function() { showList(list, h3);return false; };
	//set the background offset on the h3 to show the minus sign
	h3link.parentNode.style.backgroundPosition = "0 0";
}
addLoadEvent(function() {
//call the function, needs the class to do it
	hideLists();
	h3Links();
});