/*
	MyMenu 0.4(a) - Trunk version!
	Copyright 2006 - 2008 by Carsten Ruppert - carsten.ruppert at web.de
	
	>> You are not allowed to use, modify or distribute this code in any way without the permission of the author! <<
	
	Fuer tegos...

	- IE 6 + 7, Firefox 0.6+, Safari 2.0+
*/
var openmenu = false;function myMenu (mid,direction,customAnchorClass,subdirection,classprefix) {	var mymen = this;	this.menu = mid;	//this.menu = document.getElementById(mid);	this.submenus;	this.anchors;	this.dir = direction;
	this.subdir = subdirection;
	this.customAClass = customAnchorClass;
	
	this.classprefix = '.mymenu';
	this.skin = new Array();

	this.debug = false;
	if ( this.debug ) {
		this.out = document.getElementById('debug');
		}

	this.removePx = function (val) { 
		if ( val.indexOf('px') ) {
			val = Number(val.substr(0,val.indexOf('px')));
			}
		return val;
		}

	this.getSkin = function () {
		//Aus myWindow 1.0.2 kopiert
		var cssnode;
		for(i = 0; i < document.styleSheets.length; i++){
			if(document.styleSheets[i].cssRules){
				//DOM
				for(x = 0; x < document.styleSheets[i].cssRules.length; x++){
					cssnode = document.styleSheets[i].cssRules[x];
					if ( cssnode.selectorText ) {
						if ( cssnode.selectorText.indexOf(this.classprefix) > -1 ) {
							this.skin[cssnode.selectorText] = cssnode; // this.skin['.' + this.classprefix + 'SELECTORNAME'].style.PROPERTY;
							}
						}
					}
				}
			else {
				// Microsoft
				for ( x = 0; x < document.styleSheets[i].rules.length; x++ ) {
					cssnode = document.styleSheets[i].rules[x];
					if ( cssnode.selectorText.indexOf(this.classprefix) > -1 ) {
						this.skin[cssnode.selectorText] = cssnode; // this.skin['.' + this.classprefix + 'SELECTORNAME'].style.PROPERTY;
						}
					}
				}
			}
		return;
		}

	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.getSubMenuNodes = function (submenu,name) {		if (submenu && submenu.childNodes.length > 1) {			var ch;			var nodes = new Array();			for ( i = 0; i < submenu.childNodes.length; i++ ) {				ch = submenu.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; var subwidth; var nx; var br; var xo;		for ( i = 0; i < mymen.submenus.length; i++ ) {	
			parent = mymen.submenus[i].parentNode;
			//mymen.submenus[i].style.visibility = 'visible';
			mymen.submenus[i].style.display = 'block';
			mymen.subs[i][1] = mymen.submenus.offsetWidth;
			mymen.subs[i][2] = mymen.submenus.offsetTop;
			if ( i != 0 ) {
				x = mymen.subs[i-1][1];
				y = mymen.subs[i-1][2];
				w = parent.offsetWidth;				h = parent.offsetHeight;
				}
			else {
				x = parent.offsetLeft;						y = parent.offsetTop;
				w = parent.offsetWidth;				h = parent.offsetHeight;
				}
			
			
			if ( mymen.debug ) {
				smx = document.createTextNode('Offset left: '+x);
				br = document.createElement('br');
				mymen.out.appendChild(smx);
				mymen.out.appendChild(br);
				}
						
			switch(mymen.subdir) {
				case 'ltor' : // left to right
					switch(mymen.dir) {						case 'horizontal' :	
							mymen.submenus[i].style.left = w + 'px';							mymen.submenus[i].style.top = 0 + 'px';						break;						case 'vertical' :							mymen.submenus[i].style.left = 0 + 'px';							mymen.submenus[i].style.top = h + 'px';
						break;						}
				break;
				case 'rtol' : // right to left 
					switch(mymen.dir) {
						case 'horizontal' :	
							mymen.submenus[i].style.right = '-' + w + 'px';							mymen.submenus[i].style.top = 0 + 'px';						break;						case 'vertical' :
							mymen.submenus[i].style.left = "-" + w + 'px';							mymen.submenus[i].style.top = h + 'px';						break;						}
				break;
				}
			}		}		this.disable = function () {		if ( openmenu && openmenu != mymen ) {			openmenu.activate();			}		for ( i = 0; i < mymen.submenus.length; i++ ) {			//mymen.submenus[i].style.visibility = 'hidden';			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.className = 'mymenuSubMenu';
			//ch.style.visibility = 'hidden';			ch.style.display = 'none';
			ch.style.position = 'absolute';			ch.style.zIndex = z;			}		}				if ( this.menu ) {		this.menu.className = 'mymenuContainer';
		this.submenus = this.getNodes('div');
		
		if(!this.submenus.length > 0){
			return;
			}
		
		this.subs = new Array();
		for ( i = 0; i < this.submenus.length; i++ ) {
			this.subs[this.subs.length] = new Array(this.submenus[i],0,0);
			}
		this.getSkin(); // Getting all in the document embedded CSS rules
		this.subAnchors = this.getSubMenuNodes(this.submenus[0],'a');
		var subw = 0;
		for ( i = 0; i < this.subAnchors.length; i++) {
			subw += this.subAnchors[i].offsetWidth;
			subw += this.removePx(this.skin['.mymenuSubMenuAnchor'].style.paddingLeft);
			subw += this.removePx(this.skin['.mymenuSubMenuAnchor'].style.paddingRight);
			subw += this.removePx(this.skin['.mymenuSubMenuAnchor'].style.marginLeft);
			subw += this.removePx(this.skin['.mymenuSubMenuAnchor'].style.marginRight);
			}

		
		if ( this.submenus.length > 0 ) {			this.setSubMenus(100);			this.submenus[0].style.width = subw + 'px';
			}
		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,true);				this.menu.addEventListener('mouseout',this.disable,true);				}			}		}	}function initMyMenu(){	var c = 0;	var div = document.getElementsByTagName('div')[c];	var men;	if(div){		var atr; var dir;		while(div){			atr = div.getAttributeNode("mymenu");
			dir = div.getAttributeNode("dir");
			if(atr && atr.nodeValue == "yes"){
				if(dir && dir.nodeValue != ""){					men = new myMenu(div,dir.nodeValue,"","ltor","");
					}else{
					men = new myMenu(div,"vertical","","ltor","");
					}				}			++c;			div = document.getElementsByTagName('div')[c];			}		}	}