/* ********************************************************************
Dieses JavaScript-Include implementiert einen Menübaum auf
objekt-orientierte Art und Weise. Damit kann die Verwaltung 
einer Webseite sehr vereinfacht werden.

Die Definition des Menübaumes findest du ganz unten.

Thomas Chmielewski, 11. November 2004
******************************************************************** */


function Leaf( _name, _url ) {
	this.type = "leaf";
	this.name = _name;
	this.url  = _url;

	this.draw     = drawLeaf;
	this.isInside = insideLeaf;
}


function Menu( _name ) {
	this.type   = "menu";
	this.name   = _name;
	this.nodes  = new Array();

	this.draw     = drawMenu;
	this.add      = addNode;
	this.length   = menuLength;
	this.isInside = insideMenu;
	this.firstUrl = firstUrl;
}



function drawMenu( n ) {
	if (!n) { 
		n=0; 
		if (location.href.indexOf( ".htm" ) == "-1") {
//			alert( "Hallo, man kommt von außen." );
			// sonsst funzt das ganze Anzeigen des Menü nicht bei Adressen
			// wie schottburg.de, www.schottburg.de usw. 
			// Dann sieht man nur den ersten Button ohne Text
			location.href = "http://www.schottburg.de/index.htm";
		}
	}

//	alert( "drawMenu " + this.name + ', ' + n );
        document.writeln( "<table border=0 cellspacing=0 cellpadding=0 class=\"Nav0\">" );
	if (this.isInside()) {
		if (!n) {
			if (this.name) {
				document.writeln( "<tr><th >" + this.name + "</th></tr>" );  // Das ist der Menütitel!
			}
			for ( var i = 0; i < this.nodes.length; i++ ) {
				if (this.nodes[i].type == "leaf") {
					document.writeln( "<tr><td class=\"Nav0\" >" );
				} else {
					document.writeln( "<tr><td > " );
				}
				this.nodes[i].draw( n+1 );
				document.writeln( "</td></tr>" );
			}
		} else {
			if (this.name) {
				if (n < 2) {
					document.writeln( "<tr><th colspan=2 class=\"Nav0\" ><span class=\"Here\">" + this.name + "</span></th></tr>" );
				} else {
					document.writeln( "<tr><th colspan=2 class=\"Nav1 \" >" + this.name + "</th></tr>" );
				}
			}
			for ( var i = 0; i < this.nodes.length-1; i++ ) {
				document.writeln( "<tr><td class=\"NavConT\"> <td class=\"Nav1\">" );
				this.nodes[i].draw( n+1 );
				document.writeln( "</td></tr>" );
			}

			document.writeln( "<tr><td class=\"NavConL\"> <td class=\"Nav1\">" );
			this.nodes[i].draw( n+1 );
			document.writeln( "</td></tr>" );

		}
	} else {
		document.writeln( "<tr><td class=\"Nav0\" ><a href=\"" + this.firstUrl() + "\" "
				+ " >" + this.name + "</a>" );
	}	
	document.writeln( "</table>" );
}



function drawLeaf( n ) {
	if (!n) { 
		n=0; 
	} 

//	alert( "drawLeaf " + this.name  );
	if ("-1" == location.href.indexOf( this.url )) {
		document.writeln( "<a href=\"" + this.url + "\" >" + this.name + " </a>" );
	} else {
		document.writeln( "<span class=\"Here\">" + this.name + "</span> " );
	}
}



function firstUrl( n ) {
	if (!n) { n=0; }
	
//	alert( this.name + ".firstUrl( " + n + " )" );

	for ( var i = 0; i < this.nodes.length; i++ ) {
//		alert( this.name + ".checking( " + this.nodes[i].name + " )" );
		if (this.nodes[i].type == "leaf") {
//			alert( "gotcha! " + this.nodes[i].url );
			return  this.nodes[i].url;
		}
	}
	for ( var i = 0; i < this.nodes.length; i++ ) {
		if (this.nodes[i].type == "leaf") {
			var fu = this.nodes[i].firstUrl( n );
			if (fu) {
//				alert( "gotcha down below!" );
				return fu;
			}
		}
	}
	return "#";

}



function insideMenu( n ) {
	if (!n) { n=0; }
	
//	alert( this.name + ".insideMenu( " + n + " )" );

	for ( var i = 0; i < this.nodes.length; i++ ) {
		if (this.nodes[i].isInside( n+1 )) {
			return true;
		}
	}
	return false;
}


function insideLeaf( n ) {
//	alert( this.name + ".insideLeaf( " + n + " ), location.href=" + location.href );
	if ("-1" != location.href.indexOf( this.url )) {
		return true;
	}
	return false;
}


function addNode( n ) {
//	alert( "addNode." + this.name + "(" + n.name + ")"  );
	this.nodes[this.nodes.length] = n;
}



function menuLength(  ) {
	alert( "menuLength." + this.name + "=" + this.nodes.length );
	return this.nodes.length;
}



var myMenu  = new Menu( "" );
myMenu.add( new Leaf( "Homepage", "index.htm"  ) ); // umgestellt

var subMenu1 = new Menu( "&Uuml;ber uns" );
subMenu1.add( new Leaf( "Eingang",             "ueberuns.htm"  ) );  // umgestellt
subMenu1.add( new Leaf( "Leben im Freien",     "ueberuns1.htm"  ) ); // umgestellt
subMenu1.add( new Leaf( "Schottburger Straße", "ueberuns2.htm"  ) ); // umgestellt
subMenu1.add( new Leaf( "Motorrad fahren",     "ueberuns3.htm" ) );  // umgestellt
myMenu.add( subMenu1 );

var subMenu2 = new Menu( "&Uuml;ber diese Site" );
subMenu2.add( new Leaf( "&Uuml;berblick",               "site.htm"  ) );        // umgestellt
subMenu2.add( new Leaf( "Digitale Fotos",               "digital.htm"  ) );     // umgestellt
subMenu2.add( new Leaf( "HTML-Tools",                   "htmltool.htm"  ) );    // umgestellt
subMenu2.add( new Leaf( "Andere Homepage",              "start.htm"  ) );       // kein Menü
subMenu2.add( new Leaf( "US-Wahl 2004",                 "uswahl2004/index.htm"  ) );  // kein Menü
myMenu.add( subMenu2 );

var subMenu3 = new Menu( "Graffiti" );
subMenu3.add( new Leaf( "Entr&eacute;",   "graffiti.htm" ) );  // umgestellt
subMenu3.add( new Leaf( "Priesterweg",    "graff_1.htm" ) );   // umgestellt
subMenu3.add( new Leaf( "Alexanderplatz", "graff_2.htm" ) );   // umgestellt
myMenu.add( subMenu3 );

var subMenu4 = new Menu( "G&auml;stebuch" );
subMenu4.add( new Leaf( "Alle Eintr&auml;ge",           "gaestebuch.htm"  ) );  // umgestellt
subMenu4.add( new Leaf( "Eintragen",                    "gaesteeintr.htm"  ) ); // umgestellt
myMenu.add( subMenu4 );

myMenu.add( new Leaf( "Favoriten",   "favoriten.htm" ) );  // umgestellt
myMenu.add( new Leaf( "Impressum",   "impressum.htm" ) );  // umgestellt



