/*
	Project_CMS
	Copyright (c) 2005 by Phillip Berndt [www.pberndt.com]
	
	Fügt ein Menü in die aktuelle Seite ein
	
	Lizenz:
		This program is free software; you can redistribute it and/or modify
		it under the terms of the GNU General Public License as published by
		the Free Software Foundation; either version 2 of the License, or
		(at your option) any later version.
		
		This program is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
		GNU General Public License for more details.
		
		You should have received a copy of the GNU General Public License
		along with this program; if not, write to the Free Software
		Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
		
*/
function cms_getNodeText(myNode, level)
{
	retVal = "";
	for(myNode.tmpCtr=0; myNode.tmpCtr<myNode.childNodes.length; myNode.tmpCtr++)
	{
		if(myNode.childNodes[myNode.tmpCtr].nodeType == 1)
			retVal += cms_getNodeText(myNode.childNodes[myNode.tmpCtr]);
		else
			retVal += myNode.childNodes[myNode.tmpCtr].nodeValue;
	}
	myNode.tmpCtr = null;
	
	return retVal;
}

function cms_createMenu()
{
	// Überschriften laden
	h3Elements = document.getElementsByTagName("h3");
	
	if(h3Elements.length < 3)
		return;
	
	// Liste erstellen
	divElement = document.createElement("div");
	ulElement = document.createElement("ul");
	divElement.appendChild(document.createTextNode("Inhalt"));
	divElement.appendChild(ulElement);
	divElement.id = "toc_menu";
	
	// Liste füllen
	for(i=0; i<h3Elements.length; i++)
	{
		liElement = document.createElement("li");
		aElement = document.createElement("a");
		liElement.appendChild(aElement);
		aElement.href = document.location.href + "#" + h3Elements[i].id;
		aElement.targetElement = h3Elements[i];
		aElement.onclick = function()
		{
			window.scrollTo(this.targetElement.offsetLeft, this.targetElement.offsetTop);
			return false;
		}
		aElement.appendChild(document.createTextNode(cms_getNodeText(h3Elements[i])));
		
		ulElement.appendChild(liElement);
	}
	
	// Liste einfügen
	content = document.getElementById("content");
	h2Tag = content.childNodes[1].nodeName.toLowerCase() == "h2" ? content.childNodes[2] : content.childNodes[1];
	content.insertBefore(divElement, h2Tag);
}
if(!(navigator.appVersion.indexOf("MSIE") > 0 &! window.opera))
	window.setTimeout("cms_createMenu()", 100);

