var openmenu;
function myMenu (mid,direction,classprefix) {
	var mymen = this;
	//this.menu = mid;
	this.menu = document.getElementById(mid);
	this.submenus;
	this.anchors;
	this.dir = direction;

	this.getNodes = function (name) {
		if ( mymen.menu.childNodes.length > 1 ) {
			var ch;
			var nodes = new Array();
			for ( i = 0; i < mymen.menu.childNodes.length; i++ ) {
				ch = mymen.menu.childNodes[i];
				if ( ch.nodeName.toLowerCase() == name ) {
					nodes[nodes.length] = ch;
					}
				}
			}
		return nodes;
		}
	
	this.activate = function () {
		if ( openmenu ) {
			openmenu.disable();
			}
		
		var parent; var x; var y; var w; var h;
		for ( i = 0; i < mymen.submenus.length; i++ ) {
			parent = mymen.submenus[i].parentNode;
			x = parent.offsetLeft;
			y = parent.offsetTop;
			w = parent.offsetWidth;
			h = parent.offsetHeight;
			mymen.submenus[i].style.display = 'block';
		
			var tmp;
			switch(mymen.dir) {
				case 'horizontal' :
					mymen.submenus[i].style.left = w + 'px';
					mymen.submenus[i].style.top = y + 'px';
				break;
				case 'vertical' :
					mymen.submenus[i].style.left = (x - 1) + 'px';
					mymen.submenus[i].style.top = y + parent.offsetHeight -1 + 'px';
				break;
				}
			}
		}
	
	this.disable = function () {
		if ( openmenu && openmenu != mymen ) {
			openmenu.activate();
			}
		for ( i = 0; i < mymen.submenus.length; i++ ) {
			mymen.submenus[i].style.display = 'none';
			}
		}
	
	this.setSubMenus = function (z) {
		var ch;
		for ( i = 0; i < mymen.submenus.length; i++ ) {
			ch = this.submenus[i];
			ch.style.display = 'none';
			ch.style.position = 'absolute';
			ch.style.zIndex = z;
			ch.style.left = '0';
			ch.style.top = '0';
			ch.className = 'mymenuSubMenu';
			}
		}
	
	this.setAnchors = function () {
		for ( i = 0; i < mymen.anchors.lenght; i++ ) {
			mymen.anchors[i].className = 'mymenuAnchor';
			}
		}
	
	if ( this.menu ) {
		this.submenus = this.getNodes('div');
		if ( this.submenus.length > 0 ) {
			this.setSubMenus(100);
			}
		
		this.anchors = this.getNodes('a');
		if ( this.anchors.length > 0 ) {
			this.setAnchors();
			}

		this.isopen = this.menu.getAttributeNode('isopen');
		if ( this.isopen && this.isopen.nodeValue == 'yes' ) {
			this.setSubMenus(10);
			this.activate();
			openmenu = this;
			}
		else {
			if ( this.menu.attachEvent ) {
				this.menu.attachEvent('onmouseover',mymen.activate);
				this.menu.attachEvent('onmouseout',mymen.disable);			
				}
			else {
				this.menu.addEventListener('mouseover',this.activate,false);
				this.menu.addEventListener('mouseout',this.disable,false);
				}
			}
		}
	}


function initMyMenu () {
	// Das funktioniert so nicht.
	var c = 0;
	var div = document.getElementsByTagName('div')[c];
	var men;
	
	if ( div ) {
		var atr;
		while(div) {
			atr = div.getAttributeNode('mymenu');
			if ( atr && atr != '' ) {
				atr.nodeValue.split(',');
				men = new myMenu (div,atr[0],'');
				}
			++c;
			div = document.getElementsByTagName('div')[c];
			}
		}
	}