
window.menus = new menuClass();
window.menus.init();

window.m2 = new menuClass();
window.m2.init();




function menuClass() {
	this.menus = new Array();
	this.offset = new menuOffset(0, 0);
	this.timeout = 1200;
	this.menuid = 0;

	this.macX = this.macY = 0;

	var ua = navigator.userAgent.toLowerCase();
	this.isIE5 = (ua.indexOf('msie 5') > -1) ? 1 : 0;
	this.isMac = (ua.indexOf('mac') > -1) ? 1 : 0;


	if(window._menulib == null) {
		window._menulib = new menuLibClass();
		window._menulib.init();
	}
	this.lib = window._menulib;

	this.init = function() {
		if(window._menusCounter == null) window._menusCounter = 0;
		this.menuid = window._menusCounter++;
		if(window._menus == null) window._menus = new Array();
		window._menus[this.menuid] = this;

		this.lib.init();
	}
	this.setMacX = function() {
		if(this.isIE5 && this.isMac) {
			this.offset.x = 55;
			this.offset.y = -4;

			var mnulinkabout = document.getElementById('menuLink-About');
			this.macX = this.lib.getRight(mnulinkabout);

		}

	}

	this.show = function(that) {
		var thismenu = this.getMenuByTrigger(that);
		thismenu.show(that);
	}
	this.hide = function(that) {
		var thismenu = this.getMenuByTrigger(that);
		thismenu.startHide();
	}

	this.getMenuByTrigger = function(that) {
		var menuname = that.id.substr(9);
		if(this.menus[menuname] == null) {
			this.menus[menuname] = new menuClassMenu(this, menuname);
		}
		return this.menus[menuname];
	}

	this.doHideAllMenus = function() {
		for(var a in this.menus) {
			this.menus[a].doHide();
		}
	}

// 	this.mouseMove = function() {
// 		for(var a in this.menus) {
// 			if(this.menus[a].visible) this.menus[a].mouseMove();
// 		}
// 	}

	this.subOver = function() {
		for(var a in this.menus) {
			if(this.menus[a].visible) clearTimeout(this.menus[a].timer);
		}
	}

	this.subOut = function() {
		for(var a in this.menus) {
			if(this.menus[a].visible) this.menus[a].startHide();
		}
	}

	function menuClassMenu(parent, menuname) {
		this.parent = parent;
		this.menuname = menuname;

		this.divname = 'menuDiv-' + menuname;
		this.div = document.getElementById(this.divname);
		if(!this.div) this.div = false;

		this.trigger;
		this.timer;
		this.visible = false;
		this.overTrigger = false;

		this.show = function(trigger) {
			this.trigger = trigger;
			this.parent.doHideAllMenus();

			var posx = this.parent.lib.getRight(this.trigger);
			var posy = this.parent.lib.getMidY(this.trigger);
			posy -= Math.round(this.div.offsetHeight / 2);


			if(this.div) {

				if(false) { //parent.isIE5 && parent.isMac) {

				}
				else {
					if(this.parent.macX) {
						var posleft = (this.parent.macX + this.parent.offset.x);
						//alert(posleft);
						this.div.style.left = posleft + 'px';
					}
					else {
						this.div.style.left = (posx + this.parent.offset.x) + 'px';
					}
					this.div.style.top = (posy + this.parent.offset.y) + 'px';
				}
				this.div.style.visibility = 'visible';
			}

			this.visible = true;
			this.overTrigger = true;
			this.trigger.className = 'hover';
		}

		this.startHide = function() {
			this.timer = setTimeout('window._menus['+this.parent.menuid+'].menus[\''+this.menuname+'\'].doHide()', this.parent.timeout);
			this.overTrigger = false;
		}

		this.doHide = function() {
			clearTimeout(this.timer);

			if(this.div) {
				this.div.style.visibility = 'hidden';
			}

			this.trigger.className = '';
			this.visible = false;
		}
// 		this.mouseMove = function() {
// 			if(!this.div) {
// 				if(this.overTrigger) clearTimeout(this.timer);
// 				else this.startHide();
// 			}
// 			else {
// 				if(this.overTrigger || parent.lib.curPos.isOver(this.div)) clearTimeout(this.timer);
// 				else this.startHide();
// 			}
// 		}

	}
}

function menuLibClass() {
	this.initflag = false;
	this.displayMouseCoords = true;
	this.curPos;

	this.init = function() {
// 		this.curPos = new mouseCoords(this.displayMouseCoords);
// 		if(this.isIE()) document.onmousemove = window._menulib.eTrackCoords;
// 		else {
// 			window.captureEvents(Event.MOUSEMOVE);
// 			window.onmousemove = window._menulib.eTrackCoords;
// 		}

		this.initflag = true;
	}

	this.isIE = function() {
		return navigator.appName.indexOf('Microsoft') >= 0;
	}
	this.isIE5 = function() {
		if(document.all) {
			if(navigator.appVersion.toLowerCase().indexOf('msie 5.') != -1) return true;
		}
		return false;
	}
	this.isMac = function() {
		return (navigator.userAgent.toLowerCase().indexOf('mac') > -1) ? 1 : 0;
	}

	this.getLeft = function(obj) {
		return (obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft + this.getLeft(obj.offsetParent));
	}

	this.getTop = function(obj) {
		return (obj.offsetParent==null ? obj.offsetTop : obj.offsetTop + this.getTop(obj.offsetParent));
	}
	this.getRight = function(obj) {
		return (this.getLeft(obj) + obj.offsetWidth);
	}
	this.getBot = function(obj) {
		return (this.getTop(obj) + obj.offsetHeight);
	}

	this.getMidX = function(obj) {
		return (this.getLeft(obj) + Math.round(obj.offsetWidth/2));
	}
	this.getMidY = function(obj) {
		return (this.getTop(obj) + Math.round(obj.offsetHeight/2));
	}

	this.in_array = function(needle, haystack) {
		for(var i in haystack) {
			if(haystack[i] == needle) return true;
		}
		return false;
	}

	this.eTrackCoords = function(e) {
		window._menulib.curPos.x = (window._menulib.isIE()) ? event.clientX : e.pageX;
		window._menulib.curPos.y = (window._menulib.isIE()) ? event.clientY : e.pageY;
		if(window._menulib.curPos.display) self.status = window._menulib.curPos.x + ' x ' + window._menulib.curPos.y;


//		for(var i=0; i<window._menus.length; ++i) {
//			window._menus[i].mouseMove();
//		}
	}

 	function mouseCoords(display) {
 		this.x = this.y = 0;
 		this.display = display;
 	
// 		this.isOver = function(that) {
// 			if(typeof(that) == 'undefined') return;
// 			if(that.style.visibilty == 'hidden') return;
// 			var left = window._menulib.getLeft(that);
// 			var top = window._menulib.getTop(that);
// 			if(window._menulib.isIE()) {
// 				left -= document.body.scrollLeft;
// 				top -= document.body.scrollTop;
// 			}
// 			var right = left + that.offsetWidth;
// 			var bot = top + that.offsetHeight;
// 			return (this.x > left) && (this.x < right) && (this.y > top) && (this.y < bot);
// 		}
 	}
}

function menuOffset(x, y) {
	this.x = x;
	this.y = y;
}






