function initPage(subtopic)
{
	var elements = getElementsByClassName(document.getElementById('topics'), "li", "topic");
	for(i = 0; i < elements.length; i++)
	{
		elements[i].onclick = click;
	}	
	
	
	if(subtopic != null)
	{
		unfold(subtopic);
	}
}

function click(e)
{
	//Event handling garbage
	if (!e){var e = window.event;}
	if (e.target){t = e.target;}
	else if (e.srcElement){t = e.srcElement;}
	if (t.nodeType == 3) {t = t.parentNode;} // safari bug
	//OK can we get to calling the method yet
	
	//If they clicked on a topic heading and not a link within the list
	if (t.className == "topic" || t.className == "topic-selected")
	{
		toggleNode(t.id);
	}
}

function toggleNode(id)
{

		if(node = document.getElementById(id))
		{
			cssclass = node.getAttribute('class');
			
			// IE/Firefox differences
			if (cssclass == null)
			{
				cssclass = node.attributes['class'].nodeValue;
				//alert(cssclass);
			}
		
			if (cssclass == "topic")
			{
				node.className = "topic-selected";
				if (childNode = node.getElementsByTagName("li")[0])
				{
					changeText(childNode.getAttribute("id").split("-")[1]);
				}
			}
			else
			{
				node.className = "topic";
			}
		}

}

function unfold(id)
{
	topicId = id.split(".")[0];
	if(node = document.getElementById("link-" + topicId))
	{
		node.className = "topic-selected";
	}
	changeText(id);
}





function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
