var hoverMenu = function(config){
	// internal reference to each object instance
	var self = this;
	/**
	 * Public config vars
	 */
	var vars = {
			id : '',
			dir : 'y', // display menu below ('y') or to right ('x') of title parent element
			y : 0, // Y axis pixel offest
			x : 0, // X axis pixel offest
			del : 50 // milliseconds delay to hide menu on mouseout
		};
	/**
	 * Set config vars
	 */
	for(var x in vars){
		if(config==null) this[x] = vars[x];
		else this[x] = (typeof config[x] != 'undefined')? config[x] : vars[x];
	}
	/**
	 * Public function to attach sub menus to a menu block
	 * @param String - ID of Menu Title ( must end in _title and menu contents id must be without '_title' )
	 * @Description <div id="contacts_title">Contacts</div> <div id="contacts"><a href="/">Contacts 1</a><br/><a href..... </div>
	 */
	this.attach = function(menuTitleId){
		var p = document.getElementById(menuTitleId);
		if(p){
			p.childId = menuTitleId.replace('_title','');
			p.parentId = p.id;
			eventAdd(p,'mouseover',show);
			eventAdd(p,'mouseout',hide);
			eventAdd(p,'mouseup',hide);
		}
		var c = document.getElementById(p.childId);
		if(c){
			c.childId = c.id;
			c.parentId = p.id;
			eventAdd(c,'mouseover',show);
			eventAdd(c,'mouseout',hide);
			eventAdd(c,'mouseup',hide);
		}
	}
	/**
	 * Private Methods
	 */ 
	var display = function (p,c){
		var top  = (self.dir == "y") ? p.offsetHeight : 0;
		var left = (self.dir == "x") ? p.offsetWidth : 0;
		for(; p; p = p.offsetParent){
			top  += p.offsetTop;
			left += p.offsetLeft;
		}
		c.style.position	= "absolute";
		c.style.top			= top + self.y +'px';
		c.style.left		= left + self.x +'px';
		c.style.display		= "block";
	}
	var hide = function(){
		var c = document.getElementById(this.childId);
		if(c) c.hideTimeout = setTimeout("document.getElementById('"+ c.id +"').style.display = 'none'", self.del);
	}
	var show = function(){
		var p = document.getElementById(this.parentId);
		var c = document.getElementById(this.childId);
		if(c){
			display(p,c);
			clearTimeout(c.hideTimeout);
		}
	}
};
