	function MenuItem(title, url) {
		this.title = title;
		this.url = url;
	}
	
	MenuItem.prototype.getTitle = function() {
		return this.title;
	}
	
	MenuItem.prototype.getUrl = function() {
		return this.url;
	}
	
	function MenuActive() {
	}
	
	MenuActive.showMenu = function(newMenuImpl) {
		if (this.menuImpl)
			this.menuImpl.forceHide();
			
		this.menuImpl = newMenuImpl;
	}
	
	MenuActive.hideMenu = function() {
		this.menuImpl = null;
	}
	
	function Menu(menuA) {
		var menuImpl = this;
		var menuAC = new CrossBrowserControl(menuA);

		menuAC.addEventListener('mouseover', function(e) { menuImpl.onMouseOver(); } , false);
		menuAC.addEventListener('mouseout', function(e) {
				menuImpl.timeout = window.setTimeout(function() { menuImpl.onMouseOut(); menuImpl.timeout = null; }, 100);
		}, false);			
		
		this.items = new Array();
		this.divMenu = null;
		this.menuA = menuA;
		this.menuAC = menuAC;
	}
	
	Menu.prototype.addMenuItem = function(title, url) {
		this.items.push(new MenuItem(title, url));
	}
	
	function CrossBrowserControl(elm) {
		this.element = elm;
	}
	
	CrossBrowserControl.prototype.setAttribute = function(attrName, attrValue) {
		switch (attrName) {
			case 'style':
				if (this.element.style.setAttribute) {
					// IE
					this.element.style.setAttribute('cssText', attrValue);
					this.element.setAttribute(attrName, attrValue);					
				} else {
					// Normal browsers
					this.element.setAttribute(attrName, attrValue);
				}
				
				break;
				
			case 'class':
				// Normal browsers
				this.element.setAttribute(attrName, attrValue);
				// IE
				this.element.setAttribute('className', attrValue);				
				
				break;
			
			default:
				this.element.setAttribute(attrName, attrValue);			
		}
	}

	CrossBrowserControl.prototype.getLeft = function() {
 		  objParent = this.element;
 		  objLeft = 0;
		
          while( objParent.tagName.toUpperCase() != "BODY" && objParent != null )
          {
            objLeft  += objParent.offsetLeft;
            objParent = objParent.offsetParent;
          }
		return objLeft;
	}
	
	CrossBrowserControl.prototype.getWidth = function() {
		return this.element.offsetWidth;
	}
	
	CrossBrowserControl.prototype.getTop = function() {
 		  objParent = this.element;
 		  objLeft = 0;
		
          while( objParent.tagName.toUpperCase() != "BODY" && objParent != null )
          {
            objLeft  += objParent.offsetTop;
            objParent = objParent.offsetParent;
          }
		return objLeft;
	}
	
	CrossBrowserControl.prototype.getHeight = function() {
		return this.element.offsetHeight;
	}
	CrossBrowserControl.prototype.addEventListener = function(e,b,c) {
		if (this.element.addEventListener)
			this.element.addEventListener(e,b,c);
		else
			this.element.attachEvent('on' + e, b);
	}
	CrossBrowserControl.prototype.getAttribute = function(attr) {
		return this.element.getAttribute(attr);
	}

	Menu.prototype.createDivMenu = function() {
		var menuImpl = this;

		this.divMenu = document.createElement('div');
		this.divMenuC = new CrossBrowserControl(this.divMenu)

		this.divMenuC.addEventListener( 'mouseover', function() {
			if (menuImpl.timeout) {
				window.clearTimeout(menuImpl.timeout);
				menuImpl.timeout = null;
			}
		}, false);

		this.divMenuC.addEventListener( 'mouseout',  function(e) {
				menuImpl.timeout = window.setTimeout(function() { menuImpl.onMouseOut(); menuImpl.timeout = null; }, 100);
			}, false);
		
		for (x = 0; x < this.items.length; x++) {
			var A = document.createElement('A');
			A.appendChild(document.createTextNode(this.items[x].getTitle()));
			A.setAttribute('href', this.items[x].getUrl());
			this.divMenu.appendChild(A);
		}
		
		this.divMenuC.setAttribute('style',
			'left: ' + new String(this.menuAC.getLeft() + this.menuAC.getWidth()) + 'px;' +
			'top:' + new String(this.menuAC.getTop() - 1) + 'px;' +
			'position: absolute;');
			
		this.divMenuC.setAttribute('class', 'submenu');
		document.getElementsByTagName('body')[0].appendChild(this.divMenu);
	}
	
	Menu.prototype.onMouseOver = function() {
		if (this.items.length == 0)
			return ;
		if (this.timeout) {
			window.clearTimeout(this.timeout);
			return ;
		}
		
		if (this.divMenu == null) {
			this.createDivMenu();
		} else {
			document.getElementsByTagName('body')[0].appendChild(this.divMenu);
		}
		
		MenuActive.showMenu(this);
	}
	
	Menu.prototype.onMouseOut = function() {
		if (this.divMenu != null)
			document.getElementsByTagName('body')[0].removeChild(this.divMenu);

		MenuActive.hideMenu();
	}
	
	Menu.prototype.forceHide = function() {
		if (this.timeout)
			window.clearTimeout(this.timeout);
			
		this.onMouseOut();
		this.timeout = null;
	}
	


