
var ContextMenu=new Class({Implements:[Options,Events],options:{actions:{},menu:'contextmenu',stopEvent:true,targets:'body',trigger:'contextmenu',offsets:{x:0,y:0},onShow:$empty,onHide:$empty,onClick:$empty,fadeSpeed:100},initialize:function(options){this.setOptions(options)
this.menu=$(this.options.menu);this.targets=this.options.targets;this.fx=new Fx.Tween(this.menu,{property:'opacity',duration:this.options.fadeSpeed});this.hide().startListener();this.menu.setStyles({'position':'absolute','top':'-900000px','display':'block'});},startListener:function(){this.targets.each(function(el){el.addEvent(this.options.trigger,function(e){if(!this.options.disabled){if(this.options.stopEvent){e.stop();}
this.options.element=$(el);this.menu.setStyles({top:(e.page.y+this.options.offsets.y),left:(e.page.x+this.options.offsets.x),position:'absolute','z-index':'2000'});this.show();}}.bind(this));},this);this.menu.getElements('a').each(function(item){item.removeEvents('click');item.addEvent('click',function(e){if(!item.hasClass('disabled')){this.execute(item.get('href').split('#')[1],$(this.options.element));this.fireEvent('click',[item,e]);this.hide();}
return false;}.bind(this));},this);if(Browser.Engine.presto)
theEvent="mouseup";else
theEvent="click";$(document.body).addEvent(theEvent,function(){this.hide();}.bind(this));},show:function(){this.fx.start(1);this.fireEvent('show',$(this.options.element));this.shown=true;return this;},hide:function(){if(this.shown)
{this.fx.start(0);this.fireEvent('hide');this.shown=false;}
return this;},disableItem:function(item){this.menu.getElements('a[href$='+item+']').addClass('disabled');return this;},hideItem:function(item){this.menu.getElement('a[href$='+item+']').getParent().addClass('hide');return this;},enableItem:function(item){this.menu.getElements('a[href$='+item+']').removeClass('disabled');return this;},showItem:function(item){this.menu.getElement('a[href$='+item+']').getParent().removeClass('hide');return this;},disable:function(){this.options.disabled=true;return this;},enable:function(){this.options.disabled=false;return this;},execute:function(action,element){if(this.options.actions[action]){this.options.actions[action](element,this);}
return this;}});