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);
		}

		if(this.childMenu) {
			this.childMenu.hide();
//			this.childMenu.setOpacity(0);

			this.container.setStyle({zIndex:200});
			this.duration = this.options.duration;
//setTimeout("Timer()",1000);

			var	fnShow	= function(){setTimeout(this.show.bind(this),200); this.currentEffect = 'show';}.bind(this);
			var	fnHide	= function(){setTimeout(this.hide.bind(this),300); this.currentEffect = 'hide';}.bind(this);


			if(!Prototype.Browser.IE) {
				Event.observe(this.container, 'mouseover', this.show.bind(this), false);
				Event.observe(this.container, 'mouseout', this.hide.bind(this), false);
			} else {
				Event.observe(this.container, 'mouseover', fnShow, false);
				Event.observe(this.container, 'mouseout', fnHide, false);
			}

			if(this.childMenu !== null) {
				if(!Prototype.Browser.IE) {
					Event.observe(this.childMenu, 'mouseover', this.show.bind(this), false);
					Event.observe(this.childMenu, 'mouseout', this.hide.bind(this), false);
				} else {
					Event.observe(this.childMenu, 'mouseover', fnShow, false);
					Event.observe(this.childMenu, 'mouseout', fnHide, false);
				}
			}

		}

//		alert(this.nameMenu);
	},

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

		if(!Prototype.Browser.IE) {
			new	Effect.Appear(this.childMenu,
				{
					delay		: this.options.delayShow,
					duration	: this.options.durationShow,
					to			: 1,
					beforeUpdate	: function() {
									this.childMenu.show();
								}.bind(this),
					queue		: {
									position	: 'end',
									scope		: this.nameMenu + 'open',
									limit		: 1
								}
				}
			);
		} else if(this.currentEffect == 'show') {
			this.childMenu.show();
		}

	},

	hide:	function() {

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

		if(!Prototype.Browser.IE) {
			new	Effect.Fade(this.childMenu,
				{
					delay		: this.options.delayHide,
					duration	: this.options.durationHide,
					to			: 0,
			      	queue		: {
									position	: 'end',
									scope		: this.nameMenu + 'close',
									limit		: 1
								},
					afterFinish	: function() {
									this.childMenu.hide();
								}.bind(this)
				}
			);
		} else if(this.currentEffect == 'hide') {
			this.childMenu.hide();
		}

		this.open	= false;

	}




}
