function DynMenu() {
	// init
		// globals
		this.menuArr = new Array(); // complete submenu
		this.menuArrCount = 0; // elements length 
		this.timeout = 500;
		this.smbreite = 180;
		this.testing = false;
		// build menuArr
		this.add = function(childof, name, href, id) { // method name must be short
			this.menuArr[this.menuArrCount] = new Array(childof, name, href, id);
			this.menuArrCount++;
		}
		this.init = function(hitId) {
			this.hitId = hitId;
		}



	// terzmenu

		// globals
		this.aktSubId;
		this.hitSubId;
		this.holdSubId;
		
		this.subover = function(id, mid) {
			this.hold(id);
			if (this.checkForTerz(mid)) {
				this.remSubmenu("jsTerzmenu");
				this.aktSubId = mid;
				this.makeSubmenu("sm" + mid, "jsTerzmenu", "tm");
				// this.test(document.body.innerHTML);
			} else {
				this.aktSubId = 0;
				this.remSubmenu("jsTerzmenu");
			}
			this.test2();
		}
		this.subout = function() {
			this.close();
		}

		this.terzover = function(id) {
			this.hold(id);
		}
		this.terzout = function() {
			this.close();
		}

		this.checkForTerz = function(mid) {
			for (var i = 0; i < this.menuArr.length; i++) {
				if (this.menuArr[i][0] == mid) {
					return true;
				}
			}
		}




	// submenu

		// globals
		this.aktId;
		this.hitId;
		this.holdId;
		this.left;
		
		this.over = function(id) {
			this.demarkMainmenu();
			this.remSubmenu("jsTerzmenu");
			this.remSubmenu("jsSubmenu");
			this.hold(id);
			if (id != this.hitId && this.checkForChilds(id)) {
				this.makeSubmenu(id, "jsSubmenu", "sm");
				this.markMainmenu(id);
			}
		}
		this.out = function() {
			this.close();
			window.setTimeout('dynm.remSubmenuAfterTime()', this.timeout);
		}
		this.hold = function(id) {
			this.holdId = id;
		}
		this.close = function() {
			this.holdId = 0;
		}
		this.markMainmenu = function(id) {
			this.aktId = id;
			document.getElementById(id).className = "myover";
		}
		this.remSubmenuAfterTime = function() {
			if (this.holdId == 0) {
				this.demarkMainmenu();
				this.remSubmenu("jsSubmenu");
				this.remSubmenu("jsTerzmenu");
			} else {
				window.setTimeout('dynm.remSubmenuAfterTime()', this.timeout);
			}
		}
		this.demarkMainmenu = function() {
			if (document.getElementById(this.aktId)) {
				if (this.aktId == this.hitId) {
					document.getElementById(this.aktId).className = "hit";
				} else {
					document.getElementById(this.aktId).className = "myout";
				}
			}
		}



	// share
		this.checkForChilds = function(id) {
			var parent = id.substr(2);
			for (var i = 0; i < this.menuArr.length; i++) {
				if (this.menuArr[i][0] == parent) {
					return true;
				}
			}
			return false;
		}


		this.makeSubmenu = function(id, name, type) {
			var parent = id.substr(2);
			var div = document.createElement("div");
			div.setAttribute("id", name);
			if (type == "tm") {
				var top = document.getElementById(id).offsetTop +68;
				var myleft =this.left + this.smbreite + 1;
				div.setAttribute("style", "top:"+top+"px;left:"+myleft+"px");
			} else {
				this.left = document.getElementById(id).offsetLeft - 1;
				div.setAttribute("style", "left:"+this.left+"px");
			}
			for (var i = 0; i < this.menuArr.length; i++) {
				if (this.menuArr[i][0] == parent) {
					div.appendChild(this.makeAnchor(this.menuArr[i][1], this.menuArr[i][2], id, type, this.menuArr[i][3]));
				}
			}
			document.body.appendChild(div);
			if (type == "tm") {
				document.getElementById(name).style.top = top;
				document.getElementById(name).style.left = myleft;
			} else {
				document.getElementById(name).style.left = this.left;
			}
			this.test(div.innerHTML);
		}
		this.remSubmenu = function(name) {
			if (document.getElementById(name)) {
				document.body.removeChild(document.getElementById(name));
			}
		}

		this.makeAnchor = function(name, href, id, type, mid) {
			var link = document.createElement("a");
			link.setAttribute("href", href);
			link.setAttribute("id", "sm" + mid);
			if (type == "sm") {
				link.onmouseover = function (evt) { dynm.subover(id, mid); };
				link.onmouseout = function (evt) { dynm.subout(); };
			} else if (type == "tm") {
				link.onmouseover = function (evt) { dynm.terzover(id); };
				link.onmouseout = function (evt) { dynm.terzout(); };
			}
			//link.nodeValue = name + " -- " + id;
			var txt = document.createTextNode(name);
			link.appendChild(txt);
			return link;
		}



		// testing

		this.testform = false;
		this.initTest = function() { // geht im IE noch nicht
			var form = document.createElement("form");
			form.setAttribute("method", "post");
			form.setAttribute("name", "test");
			form.setAttribute("id", "testform");
			form.setAttribute("style", "position:absolute;top:500px;z-index:2000");

			var textarea = document.createElement("textarea");
			textarea.setAttribute("name", "tb");
			textarea.setAttribute("rows", "10");
			textarea.setAttribute("cols", "50");

			var input = document.createElement("input");
			input.setAttribute("type", "text");
			input.setAttribute("name", "tbb");

			form.appendChild(textarea);
			form.appendChild(input);

			document.body.appendChild(form);
			this.testform = true;
			document.getElementById("testform").style.position = "absolute";
			document.getElementById("testform").style.top = "500px";

			// <form method=post action="" name="test" style="position:absolute;top:500px;">
			// <textarea name="tb" rows="10" cols="50"></textarea>
			// <input type="text" name="tbb">
		}
		this.test = function(str) {
			if (this.testing){
				if (!this.testform){
					this.initTest();
				}
				var f = document.forms.test.elements.tb;
				f.value = str;
			}
		}
		this.test2 = function() {
			if (this.testing){
				if (!this.testform){
					this.initTest();
				}
				var f  = document.forms.test.elements.tbb;
				f.value = this.aktSubId;
			}
		}

}
loadDynMenu();