
// Determine browser type
var ns4 = (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) == 4);
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
if (ie4) {
	var docRoot = 'document.body';
}

if (ns4) {
	var oW = window.innerWidth;
	var oH = window.innerHeight;
	window.onresize = function () {if (oW!=window.innerWidth||oH!=window.innerHeight) location.reload();}
}

if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		if(document.compatMode && document.compatMode == 'CSS1Compat') {
			docRoot = 'document.documentElement';
		}
	}
	if (ns6) {
		ns6 = false;
	}
}

var oCenter = document.getElementById("center");

var oContent = _getFirstChildElementWithAttribute(oCenter, "class", "content");

var oHeadings = _getHeadings(oContent);

var oNewChild = document.createElement("DIV");
oNewChild.setAttribute("id", "content-headings");
var isFirstH3 = false;
var indexOfFirstH3 = 0;
for (var i = 0; i < oHeadings.length; i++) {
	var o = oHeadings[i];
	var id = o.getAttribute("id");
	var level = o.nodeName.charAt(1);
	/*
	if (!isFirstH3) {
		if (level == 3) {
			isFirstH3 = true;
			indexOfFirstH3 = i;
		}
		continue;
	}
	*/
	var oInner = o.firstChild;
	var heading = "";
	while (oInner) {
		if (oInner.nodeName == "#text") {
			heading += oInner.nodeValue;
		}
		oInner = oInner.nextSibling;
	}
	var oDiv = document.createElement("DIV");
        if (ie4) {
		oDiv.setAttribute("className", "level-" + level);
	}
	else {
		oDiv.setAttribute("class", "level-" + level);
	}
	var oAnchor = document.createElement("A");
	oAnchor.setAttribute("href", "#" + id);
	oAnchor.appendChild(document.createTextNode(heading));
	oDiv.appendChild(oAnchor);
	oNewChild.appendChild(oDiv);
}


document.getElementById("listHeaders").appendChild(oNewChild);
/*
if (indexOfFirstH3 < oHeadings.length - 1) {
	var oRefChild = oHeadings[0];
	oContent.insertBefore(oNewChild, oRefChild);
}
*/

function _getFirstChildElementWithAttribute(oParentNode, attrName, attrValue) {
	var oChild = oParentNode.firstChild;
	while (oChild) {
		if (oChild.nodeType == 1) {
			var value0 = oChild.getAttribute(attrName);
			var value1 = oChild.getAttribute(attrName + "Name");
			if (value0 == attrValue || value1 == attrValue) {
				return oChild;
				break;
			}
		}
		oChild = oChild.nextSibling;
	}
}

function _getHeadings(oParentNode) {
	var oRegExp = new RegExp("H[1-6]");
	var oHeadings = new Array();
	var n = 0;
	var oChild = oParentNode.firstChild;
	while (oChild) {
		if (oChild.nodeType == 1) {
			if (oChild.nodeName.match(oRegExp)) {
				oChild.setAttribute("id", "heading-" + n);
				oHeadings[n] = oChild;
				n++;
			}
		}
		oChild = oChild.nextSibling;
	}
	return oHeadings;
}

