/**
 * @author Adrian Philipp
 */
Menu = Class.create();
Menu.prototype = {

	initialize: function(elementName, options) {
		this.callerObject = $(elementName);
		this.menu         = $(elementName + '_list');
		this.firstCall    = true;

		Element.hide(this.menu);
		Element.setOpacity(this.menu, 0);

		this.showListener     = this.showMenu.bindAsEventListener(this);
		this.showFadeListener = this.showMenuFade.bindAsEventListener(this);
		this.hideListener     = this.mouseOutListener.bindAsEventListener(this);

		Event.observe(this.callerObject, 'mouseout',  this.hideListener);
		Event.observe(this.callerObject, 'mouseover', this.showFadeListener);

		var aTags = this.menu.getElementsByTagName('A');
		for (i=0; i<aTags.length; i++) {
			Event.observe(aTags[i], 'mouseout',  this.hideListener);
			Event.observe(aTags[i], 'mouseover', this.showListener);
		}

	},


	showMenuFade: function () {
		this.showMenu();
		new Effect.Opacity(this.menu, {duration:0.2, from:0, to:1.0});
	},


	showMenu: function() {
		clearTimeout(this.timeout);
		this.callerObject.className = "actorsNameActive";
		Element.show(this.menu);
	},

	mouseOutListener: function(event) {
		clearTimeout(this.timeout);
		this.hideMenuListener = this.hideMenu.bindAsEventListener(this);
		this.timeout = setTimeout(this.hideMenuListener, 300);
	},

	hideMenu: function () {
		clearTimeout(this.timeout);
		new Effect.Opacity(this.menu, {duration:0.1, from:1.0, to:0, afterFinishInternal: function(effect) {Element.hide(effect.element);}});
		this.callerObject.className = "actorsName";
	}

}
