if (typeof Effect == 'undefined')
	throw("menu.js requires including script.aculo.us' effects.js library!");


var protoMenu = Class.create();
protoMenu.prototype = {

	//
	//  Setup the Variables
	//
	listElement		: [],
	container		: false,
	open			: false,
	noClose			: false,
	nameMenu		: '',
	childMenu		: null,
	oldClass		: '',
	currentMenu		: null,
	count			: 0,
	nbItem			: 0,

	//
	//  Initialize
	//
	initialize: function(container, options) {

		this.nameMenu	= container;
		this.container	= $(container);

		if (!this.container) {
			throw(container+" doesn't exist!");
			return false;
		}

		this.options = Object.extend({
			onEvent			: 'mouseover',
			onEventClose	: 'mouseout',
			idContent		: false,
			offsetY			: 0,
			durationShow	: 0.3,
			durationHide	: 0.5,
			delayShow		: 0,
			delayHide		: 0,
			zIndexHide		: 100,
			zIndexShow		: 110,
			classNames 		: {
				open	:	'open',
				close	:	'close',
				over	:	'over'
			}
		}, options || {});

		if(this.options.idContent != false) {
			this.childMenu	= $(this.options.idContent);
			this.childMenu.hide();
			this.childMenu.setOpacity(0);

			var	position	= ($('menuBesoins').cumulativeOffset().top + $('menuBesoins').getHeight() + this.options.offsetY) + 'px';
			this.childMenu.setStyle({top: position});
		}

		this.container.setStyle({zIndex:200});
		this.duration = this.options.duration;
		
		Event.observe(this.container, 'mouseenter', this.show.bind(this), true);
		Event.observe(this.container, 'mouseleave', this.hide.bind(this), true);
	
		Event.observe(this.childMenu, 'mouseenter', this.show.bind(this), true);
		Event.observe(this.childMenu, 'mouseleave', this.hide.bind(this), true);

	},

	show:	function() {

		var queue = Effect.Queues.get(this.nameMenu + 'close');
		queue.each(function(e) { e.cancel() });

		new	Effect.Opacity(this.childMenu,
			{
				delay		: this.options.delayShow,
				duration	: this.options.durationShow,
				to			: 1.0,
				beforeUpdate	: function() {
								this.childMenu.show();
							}.bind(this),
		      	queue		: {
								position: 'end',
								scope: this.nameMenu + 'open'
				      		}
			}
		);

	},

	hide:	function() {

			var queue = Effect.Queues.get(this.nameMenu + 'open');
			queue.each(function(e) { e.cancel() });
			new	Effect.Opacity(this.childMenu,
				{
					delay		: this.options.delayHide,
					duration	: this.options.durationHide,
					to			: 0.0,
			      	queue		: {
									position: 'end',
									scope: this.nameMenu + 'close'
								},
					afterFinish	: function() {
									this.childMenu.hide();
								}.bind(this)
				}
			);

		this.open	= false;

	}




}
