//Script created by Erik Peterson 6/2005
//Very slight modifications by Dave Moore 3/2006

	function addListeners() {
		var els = document.getElementsByTagName('li');
		for (i=0; i < els.length; i++) {
			// we search through all the <li> elements and anything that has the class: supertopic
			// we will add an onclick event for the "showHideSubTop" function and then 
			// we will add the 'hidden' class to have it start closed.
			if (els[i].className.search(/supertopic/) != -1) {
				var newlink = document.createElement('a');
				newlink.innerHTML = els[i].firstChild.data;
				newlink.href = '#';
				addEvent(newlink,'click', showHideSubTop, false);
				els[i].replaceChild(newlink,els[i].firstChild);
			}			
		}
	}

	function addEvent(elm, evType, fn, useCapture) {
		//cross-browser event handling by Scott Andrew
		// this is a generic function that will add event handlers 
		// correctly for various browsers (stock library)
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		}
		else if (elm.attachEvent) {
			var r = elm.attachEvent('on'+evType, fn);
			return r
		}
		else {
			elm['on'+evType] = fn;
		}
	}

	function showHideSubTop(e) {
	// this function will add or remove the hidden class from the element
	// and the list will hide/show as expected.
	// note that we use a style selector of ".hidden ul", so that we don't hide
	// the whole list including supertopic li text
		
		var t = window.event ? window.event.srcElement : e ? e.target: null;

		if (!t) return;
		
		var els = document.getElementsByTagName('li');
		for (i=0; i < els.length; i++) {
			if (els[i].className.search(/\bsupertopic\b/) != -1 && els[i].className.search(/\bhidden\b/)==-1 && els[i].id!=t.parentNode.id) {
				els[i].className += ' hidden';
			}
		}

		if (t.parentNode.className.search(/\bhidden\b/) != -1)  {
			t.parentNode.className = t.parentNode.className.replace(/\b ?hidden\b/,'');
		}
		
		else {
			t.parentNode.className += ' hidden';
		}
		
		if (window.event) {
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
		if (e && e.stopPropagation && e.preventDefault) {
			e.stopPropagation();
			e.preventDefault();
		} 
	}
	
	// crossbrowser event loading for the window.onload which calls the initializing function
	addEvent(window, 'load', addListeners, false);