/* 
	MyMenu 2 (2008.2)
	Carsten Ruppert
	2008/04/10
	
	Copyright 2008 by HEAD. MARKETING-PARTNER
	http://www.headmarketing.de/
	
	>>> This software is not Open Source or Public Domain. You are not allowed to use, modify or redistribute this software without the permission of HEAD. MARKETING-PARTNER! <<<

	Revision 2008/04/14
	- Set the css classname of the dropdown container to "mymenuDropdown" to avoid css conflicts
	
*/

function myMenuNode(node){
	// the menu Object
	
	var mynode = this;
	this.dropnode = undefined;
	
	// Object Properties:
	
	this.align = undefined; // horizontal or vertical
	this.dir = undefined; // ltor or rtol 
	this.w = undefined;
	this.h = undefined;
	this.x = undefined;
	this.y = undefined;
	
	// Object Methods:
	
	this.engage = function(){
		// show the dropdown div
		mynode.dropnode.style.display = 'block';
		if(mynode.dir == "ltor"){
			if(mynode.align == 'horizontal'){
				mynode.dropnode.style.left = '100%' //mynode.w + 'px';
				mynode.dropnode.style.top = 0; //mynode.y + 'px';
				}else{
				mynode.dropnode.style.left = 0;
				mynode.dropnode.style.top = '100%'; //mynode.h + 'px';
				}
			}else{
			if(mynode.align == 'horizontal'){
				mynode.dropnode.style.right = '100%'; //mynode.w + 'px';
				mynode.dropnode.style.top = 0; //mynode.y + 'px';
				}else{
				mynode.dropnode.style.left = 0;
				mynode.dropnode.style.top = '100%'; //mynode.h + 'px';
				}
			}
		
		return true;
		}
	this.disengage = function(){
		// Hide the dropdown div
		mynode.dropnode.style.display = 'none';	
		return true;
		}
	this.getDropdown = function(){
		// Get the "div" element to show on mouseover
		var child;
		for(i = 0; i < this.node.childNodes.length; i++){
			child = this.node.childNodes[i];
			if(child && child.nodeName.toLowerCase() == 'div'){
				child.id = "mydrop"+i;
				this.dropnode = child;
				return true;
				}
			}
		return false;
		}
	this.setEventListeners = function(){
		if(this.node.attachEvent){
			this.node.attachEvent('onmouseover',this.engage);
			this.node.attachEvent('onmouseout',this.disengage);
			return true;
			}
		else if(this.node.addEventListener){
			this.node.addEventListener('mouseover',this.engage,false);
			this.node.addEventListener('mouseout',this.disengage,false);
			return true;
			}
		else{
			return false;
			}
		}

	// "Constructor":
	if(node){
		this.node = node;

		
		this.firsta = this.node.getElementsByTagName('a')[0]; // first anchor in menu
					
		
		//alert(b);
		
		
//		this.node.style.width = b +'px';
		
		this.w = this.firsta.offsetWidth; // width for horizontal align
		this.h = this.firsta.offsetHeight; // height
		this.x = this.firsta.offsetLeft; // x axis from top left corner
		this.y = this.firsta.offsetTop; // y axis from top left corner
		
		
		
		
		
		this.align = this.node.getAttributeNode('menualign');
		if(this.align){
			this.align = this.align.nodeValue;
			}
		this.dir = this.node.getAttribute('menudir');
		this.dir = this.dir ? this.dir.nodeValue : "ltor";
		this.node.className = 'mymenuContainer';
		if(this.getDropdown()){
			this.dropnode.className = 'mymenuDropdown';
			this.as = new Array();
			
			for(i = 0; i < this.dropnode.childNodes.length; i++){
				if(this.dropnode.childNodes[i].nodeName.toLowerCase() == 'a'){
					this.as[this.as.length] = this.dropnode.childNodes[i];
					}
				else if(this.dropnode.childNodes[i].nodeName.toLowerCase() == 'div' && this.dropnode.childNodes[i].getAttributeNode('mymenu')){
					this.as[this.as.length] = this.dropnode.childNodes[i].childNodes[1];
					}
				}
			
			var b = 0;
			for(i = 0; i < this.as.length; i++){
				b = this.as[i].offsetWidth > b ? this.as[i].offsetWidth : b;
				}
			
			this.dropnode.style.width = b+'px';
			void(this.setEventListeners());
			}
		
		//if(this.engage()){
			//this.disengage()
		//	}
		}
	}


function myMenu(){
	// The menu initializer object

	var mymen = this;
	this.nodes = new Array();
	void(this.getNodes());
	}
	myMenu.prototype.getNodes = function(){
			var c = 0; var div = null;
			// Init myMenuNodes:
			while(div = document.getElementsByTagName('div')[c]){
				var ismenu = div.getAttributeNode('mymenu');
				if(ismenu && ismenu.nodeValue == 'yes'){
					this.nodes[this.nodes.length] = new myMenuNode(div);
					}
				++c;
				}
			for(i = 0; i < this.nodes.length; i++){
				this.nodes[i].engage();
				// Hide all myMenuNodes
				this.nodes[i].disengage();
				}
			}
