/*
Script: menu.class.js
	Contains <Menu>
 
Author:
	Olivier Gasc, <jahjah@mibhouse.org>
 
License:
	MIT-style license.
 
*/
 
/*
Class: Menu, simple lists menu
 
Arguments:
	id : the li id to apply the menu, default menu
*/

var Menu = new Class ({
	options: {
		id	: 'menu'
	},	

	initialize: function(options){
		this.setOptions(options);

		// Searching the li elements
		$ES('li', this.options.id).each(function(e, i) {
			// Events
			e.addEvents({
				'mouseover': this.show,
				'mouseout': this.hide,
				'click': this.hide
			});

			// Add an id for selector
			e.setAttribute( 'id', this.options.id + '_li_' + i );
		}.bind(this));
    },
    
	// Hide elements
	hide: function()
	{   
		// Select the sub_lists of the element
		var oUl = $E('ul', this.id);
		
		// Hide if exists
		if (oUl != null)
			oUl.setStyle('visibility', 'hidden');
	},
	
	// Show elements
	show: function()
	{
		// Select the sub_lists of the element
		var oUl = $E('ul', this.id);
		
		// Show if exists
		if (oUl != null)
		oUl.setStyle('visibility', 'visible');
	}
});

Menu.implement(new Options);

Element.extend({
	addMenu: function() {
		var CMenu = new Menu({
			id: this.id
		});
	}
});
