// Menu class

var menuTimed = new Class({
	
	Implements: [Options],

	/**
	 * Options
	 *
	 */
	options : {
		in_tempo : 1000,
		out_tempo : 1000,
		position : 'element', // element or top
		trigger : 'hover' // hover or click
	},
	
	/**
	* Constructor
	* 
	* @param string id of menu
	* @param array options
	*/
	initialize: function(id, options)
	{
		//init options
		this.setOptions(options);
		
		if($(id))
		{
			this.elements = $(id).getChildren('li').getChildren('a');
			this.elements.each(function(item){
				if(this.options.trigger =='hover')
				{
					// Add mouse in event
					item.addEvent('mouseenter', function(item){
						this.showMenu(item.id);
					}.bind(this, item));
					
					// Add mouse out event
					/*
					item.addEvent('mouseleave', function(item){
						this.hideMenu(item.id);
					}.bind(this, item));*/
				}
				else
				{
					// Add mouse in event
					item.addEvent('click', function(item){
						this.showMenu(item.id);
					}.bind(this, item));
				}
			}.bind(this));
			this.showMenu(this.elements[0][0].id);
		}
	},
	showMenu: function(id)
	{
		if($('sous_' + this.oldblock))
			this.hideMenu(this.oldblock);
			
		if($(id))
		{
			this.oldblock = id;
			setTimeout(function(){
				$('sous_'+id).setStyle('display', 'block');
				$(id).addClass('selected');
				}, this.options.in_tempo);
		}
	},
	hideMenu: function(id)
	{
		if($(id))
		{
			setTimeout(function(){
				$('sous_'+id).setStyle('display', 'none');
				$(id).removeClass('selected');
				}, this.options.out_tempo);
		}
	}
});
