if (window.attachEvent) {
	window.attachEvent("onload",toc_init);
}
else if (window.addEventListener) {
	window.addEventListener("load",toc_init,true);
}

function toc_init() {
	//add the show/hide link
	var div = document.createElement("div");
		div.id = "toc_toggle";
	var link = document.createElement("a");
		link.onclick = function() {
			toc_toggle();
			return false;
		}
		link.href = "#";
		link.setAttribute("title","hide table of contents");
		
	link.appendChild(document.createTextNode("hide table of contents"));	
	
	div.appendChild(link);
	var toc = document.getElementById("toc");
	toc.insertBefore(div,toc.firstChild);
}

function toc_toggle() {
	var link = document.getElementById("toc_toggle").getElementsByTagName("a")[0];
	var curValue = link.firstChild.nodeValue;
	var newValue = (curValue.indexOf("hide") >= 0) ? "show table of contents" : "hide table of contents";
	link.replaceChild(document.createTextNode(newValue),link.firstChild);
	link.setAttribute("title",newValue);
	
	var ul = document.getElementById("toc").getElementsByTagName("ul")[0];
	ul.style.display = (curValue.indexOf("hide") >= 0) ? "none" : "block";
}