var Menu = Class.create(false);
Menu.prototype = {
	initialize: function() {
		this.timeout	= 500;
		this.closetimer	= 0;
		this.ddmenuitem	= 0;

		var parents = $$('a.parent');

		for (var i=0;i<parents.length ;i++ )
		{
			Event.observe(parents[i], 'mouseover', this.mopen.bind(this));
			Event.observe(parents[i], 'mouseout', this.mclosetime.bind(this));
		}

		Event.observe(document, 'click', this.mclose.bind(this));

	},

	mopen: function(e)
	{	
		// cancel close timer
		this.mcancelclosetime();

		// close old layer
		if(this.ddmenuitem) this.ddmenuitem.style.visibility = 'hidden';

		// get new layer and show it
		this.ddmenuitem = e.element().next('div.sub');
		// alert(this.ddmenuitem);

		if (this.ddmenuitem != undefined)
			this.ddmenuitem.style.visibility = 'visible';
	},

	mclose: function(e)
	{
		if(this.ddmenuitem) this.ddmenuitem.style.visibility = 'hidden';
	},

	mcancelclosetime: function()
	{
		if(this.closetimer)
		{
			window.clearTimeout(this.closetimer);
			this.closetimer = null;
		}
	},

	mclosetime: function()
	{
		this.closetimer = window.setTimeout(this.mclose, this.timeout);
	}
}

