Event.observe(window, "load", initToc);
function initToc() {
	if(!$("toc-container")) return;
	var toc = document.getElementsByClassName("toc")[0];
	var newToc = toc.cloneNode(true);
	newToc.id = "toc";
	$("body").appendChild(newToc);
	hideToc();
	//Element.hide("toc-container");
	Event.observe("toc", "click", hideToc);
	Event.observe("wrapper", "mouseover", gHideToc);
	var anchors = document.getElementsByClassName("toc-anchor");
	for(var i=0;i<anchors.length;i++) {
		Event.observe( anchors[i], "click", showToc );
	}
}
function gHideToc(e) {
	var firstDiv = Event.findElement(e, "div");
	if(firstDiv.id == "toc") return;
	else hideToc();
}
function hideToc(e) {
	Element.hide("toc");
}
function showToc(e) {
	var theAnchor = Event.element(e);
	var anchorPos = Position.cumulativeOffset(theAnchor);
	$("toc").style.top = ( anchorPos[1] + Element.getHeight(theAnchor) - 5 ).toString() + "px";
	$("toc").style.left = anchorPos[0].toString() + "px";
	Element.show("toc");
	theAnchor.blur();
	Event.stop(e);
}