if(typeof(Eon)!="object")
throw"Please import Eon.js for contextmenu.js";else if(typeof(Prototype)!="object")
throw"Please import prototype.js for contextmenu.js";else if(parseInt(Prototype.Version.replace(new RegExp('\\.',"g"),""))<161)
throw"Please upgrade your prototype.js to 1.6.1 version or greater";else if(typeof(Eon.ContextMenu)!="object")
{Eon.ContextMenuScript={Version:1.21}
Eon.ContextMenu=function(menuDiv,fade,fadeCoef)
{var p_html_menu_elt;var p_current_attachement=null;var p_attachements=new Array();var p_this=this;var p_decay_timeout=null;Eon.EventSender.call(this);this.menuElement=function()
{return p_html_menu_elt;}
this.currentAttachement=function()
{return p_current_attachement;}
this.getAttachement=function(i)
{return p_attachements[i];}
this.getAttachementCount=function()
{return p_attachements.length;}
this.attach=function(htmlElement,options,attachToSubElts,positionFromParent)
{if(options!=null)
options=Object.clone(options);if(Eon.ContextMenu.HasContextMenu(htmlElement,this))
return false;htmlElement=Eon.Type.extendDOMElement(htmlElement);options=p_initOptions(options);if(Eon.ContextMenu.IsMouseOverType(options.type))
{htmlElement.observe("mouseover",Eon.ContextMenu.onShow);if(options.type!=Eon.ContextMenu.T_MOUSE_OVER_KEEP)
htmlElement.observe("mouseout",Eon.ContextMenu.onHide);}
else
{htmlElement.observe("contextmenu",Eon.DOMEvent.StopEventDefaultBehavior);htmlElement.observe("mouseup",Eon.ContextMenu.onShow);}
if(options.position==Eon.ContextMenu.P_MOUSE_MOVE)
htmlElement.observe("mousemove",function(){p_this.computePosition();});htmlElement.contextMenu={menu:this,options:options};p_attachements.push(htmlElement);if(attachToSubElts)
{if(attachToSubElts==2&&positionFromParent==null)
positionFromParent=true;var children=htmlElement.childNodes;for(var i in children)
{if(children[i].nodeType!=1)
continue;this.attach(children[i],options,attachToSubElts,positionFromParent);if(positionFromParent)
children[i].contextMenu.parent=htmlElement;}}}
this.detach=function(htmlElement,detachToSubElts)
{htmlElement=Eon.Type.extendDOMElement(htmlElement);if(!Eon.ContextMenu.HasContextMenu(htmlElement,this))
return false;if(Eon.ContextMenu.IsMouseOverType(type))
{htmlElement.stopObserving("mouseover",Eon.ContextMenu.onShow);if(htmlElement.contextMenu.options.type!=Eon.ContextMenu.T_MOUSE_OVER_KEEP)
htmlElement.stopObserving("mouseout",Eon.ContextMenu.onHide);}
else
{htmlElement.stopObserving("contextmenu",Eon.DOMEvent.StopEventDefaultBehavior);htmlElement.stopObserving("mouseup",Eon.ContextMenu.onShow);}
htmlElement.contextMenu=null;index=p_attachements.indexOf(htmlElement);if(index>-1)
p_attachements.splice(index,1);if(attachToSubElts)
{var children=htmlElement.childNodes;for(var i in children)
if(children[i].nodeType==1)
this.detach(children[i],detachToSubElts);}}
this.setVisibility=function(visible)
{p_html_menu_elt.style.display=(visible?"block":"none");}
this.display=function(attachement,decay)
{if(!attachement||!attachement.contextMenu||attachement.contextMenu.menu!=this)
throw"Given attachement does not belong to this context menu";p_removeDecay();if(decay)
{decay=parseInt(decay*1000);p_decay_timeout=window.setTimeout(function(){p_this.display(attachement);p_decay_timeout=null;},decay);return;}
p_current_attachement=attachement;this.computePosition();if(!this.isRegisteredEvent(Eon.ContextMenu.E_SHOW))
this.setVisibility(true);this.triggerEvent(new Eon.Event(Eon.ContextMenu.E_SHOW));}
this.hide=function()
{p_removeDecay();if(p_current_attachement)
this.triggerEvent(new Eon.Event(Eon.ContextMenu.E_HIDE));if(!this.isRegisteredEvent(Eon.ContextMenu.E_HIDE))
this.setVisibility(false);p_current_attachement=null;}
this.isDisplayed=function()
{return(p_html_menu_elt.style.display=="block");}
p_initMenuElement(menuDiv,fade,fadeCoef);Eon.ContextMenu.instances.push(this);function p_initMenuElement(menuElement,fade,fadeCoef)
{p_html_menu_elt=Eon.Type.extendDOMElement(menuElement);p_html_menu_elt.style.display="none";p_html_menu_elt.style.position="absolute";p_html_menu_elt.style.zIndex="7777777";p_html_menu_elt.contextMenuObject=p_this;document.body.insertBefore(p_html_menu_elt,document.body.firstChild);if(fade)
{var imagesCount=Math.ceil(parseFloat(fade)*30);var animation=new Eon.OpacityAnimation();if(fadeCoef<=0)
fadeCoef=1;animation.attach(p_html_menu_elt,0);animation.addEventMonitor("animation:finish",function(event){if(animation.getCurrentValue(0)==0)
p_this.setVisibility(false);});p_this.addEventMonitor(Eon.ContextMenu.E_SHOW,function(event){animation.goTo(1,30,imagesCount,Math.pow,fadeCoef);p_this.setVisibility(true);p_html_menu_elt.style.display="block";});p_this.addEventMonitor(Eon.ContextMenu.E_HIDE,function(event){animation.goTo(0,30,imagesCount,Math.pow,fadeCoef);});}}
function p_removeDecay()
{if(p_decay_timeout)
window.clearTimeout(p_decay_timeout);p_decay_timeout=null;}
function p_initOptions(options)
{if(options==null)
options=new Object();if(options.type==null)
options.type=Eon.ContextMenu.T_RIGHT_CLICK;options.offsetX=(options.offsetX?parseInt(options.offsetX):0);options.offsetY=(options.offsetY?parseInt(options.offsetY):0);options.showDecay=(options.showDecay?parseFloat(options.showDecay):0);if(options.showDecay<0)
options.showDecay=0;return options;}}
Eon.ContextMenu.prototype=new Eon.EventSender();Eon.ContextMenu.prototype.construct=Eon.ContextMenu;Eon.ContextMenu.T_LEFT_CLICK="leftClick";Eon.ContextMenu.T_RIGHT_CLICK="rightClick";Eon.ContextMenu.T_MOUSE_OVER="mouseOver";Eon.ContextMenu.T_MOUSE_OVER_KEEP="mouseOverKeep";Eon.ContextMenu.P_MOUSE="mouse";Eon.ContextMenu.P_MOUSE_MOVE="mouseMove";Eon.ContextMenu.P_CORNER_LEFT_TOP="leftTop";Eon.ContextMenu.P_CORNER_RIGHT_TOP="rightTop";Eon.ContextMenu.P_CORNER_LEFT_BOTTOM="leftBottom";Eon.ContextMenu.P_CORNER_RIGHT_BOTTOM="rightBottom";Eon.ContextMenu.A_LEFT_TOP="leftTop";Eon.ContextMenu.A_RIGHT_TOP="rightTop";Eon.ContextMenu.A_LEFT_BOTTOM="leftBottom";Eon.ContextMenu.A_RIGHT_BOTTOM="rightBottom";Eon.ContextMenu.E_SHOW="contextMenu:show";Eon.ContextMenu.E_HIDE="contextMenu:hide";Eon.ContextMenu.instances=new Array();Eon.ContextMenu.IsMouseOverType=function(type)
{return(type==Eon.ContextMenu.T_MOUSE_OVER||type==Eon.ContextMenu.T_MOUSE_OVER_KEEP);}
Eon.ContextMenu.GetMenu=function(menuElement){try{menuElement=Eon.Type.extendDOMElement(menuElement);}
catch(e){}
if(menuElement==null)
return null;var index=Eon.ContextMenu.instances.indexOf(menuElement);if(index>-1)
return Eon.ContextMenu.instances[index];if(Eon.Type.attributeToBoolean(menuElement,"cm-is-menu"))
return new Eon.ContextMenu(menuElement,menuElement.getAttribute("cm-fade"),menuElement.getAttribute("cm-fade-coef"));return null;}
Eon.ContextMenu.HasContextMenu=function(element,contextMenu)
{return(element.contextMenu&&element.contextMenu.menu&&element.contextMenu.menu instanceof Eon.ContextMenu&&(!contextMenu||contextMenu==element.contextMenu.menu));}
Eon.ContextMenu.onShow=function(event)
{var ref=event.target;if(!Eon.ContextMenu.HasContextMenu(ref))
throw"Try to show a menu from an element which is not an attachement.";var type=ref.contextMenu.options.type;var menu=ref.contextMenu.menu;var isMouse=Eon.ContextMenu.IsMouseOverType(type);if(!isMouse&&(type==Eon.ContextMenu.T_LEFT_CLICK&&!event.isLeftClick()||type!=Eon.ContextMenu.T_LEFT_CLICK&&!event.isRightClick()))
return true;Eon.ContextMenu.hideAll(menu);menu.display(ref,ref.contextMenu.options.showDecay);if(isMouse)
return true;event.stopPropagation();return Eon.DOMEvent.StopEventDefaultBehavior(event);}
Eon.ContextMenu.onHide=function(event)
{var ref=event.target;if(!Eon.ContextMenu.HasContextMenu(ref))
Eon.ContextMenu.hideAll();else
ref.contextMenu.menu.hide();}
Eon.ContextMenu.hideAll=function(exception)
{for(var i=0;i<Eon.ContextMenu.instances.length;i++)
{if(Eon.ContextMenu.instances[i]==exception)
continue;Eon.ContextMenu.instances[i].hide();}}
Eon.ContextMenu.createInstanceIfNeeded=function(event)
{var element=event.target;if(element.contextMenu)
return;var menu=element.getAttribute("cm-attached-menu");if(!menu)
return;menu=document.getElementById(menu);var menuObj=Eon.ContextMenu.GetMenu(menu);if(menuObj)
{if(Eon.Type.attributeToBoolean(element,"cm-as-clone"))
menuObj=menuObj.clone();menu=menuObj.menuElement();var attachChildren=element.getAttribute("cm-attach-children");var fromParent;if(attachChildren!="2")
{attachChildren=Eon.Type.attributeToBoolean(element,"cm-attach-children");fromParent=Eon.Type.attributeToBoolean(element,"cm-attach-fromParent");}
else
fromParent=true;var options={type:element.getAttribute("cm-option-type"),position:element.getAttribute("cm-option-position"),anchor:element.getAttribute("cm-option-anchor"),offsetX:element.getAttribute("cm-option-offsetX"),offsetY:element.getAttribute("cm-option-offsetY"),adaptiveAnchor:Eon.Type.attributeToBoolean(element,"cm-option-adaptiveAnchor"),adaptiveOffset:Eon.Type.attributeToBoolean(element,"cm-option-adaptiveOffset"),showDecay:element.getAttribute("cm-option-showDecay")};menuObj.attach(element,options,attachChildren,fromParent);if(Eon.ContextMenu.IsMouseOverType(options.type))
menuObj.display(element);return;}
element.contextMenu={menu:"not found",options:null};throw"Element is attached to a context menu which does not exists";}
Eon.ContextMenu.prototype.computePosition=function()
{var menuElement=this.menuElement();var ref=this.currentAttachement();if(ref==null)
return;while(ref.contextMenu.parent)
ref=ref.contextMenu.parent;var options=ref.contextMenu.options;var pos=ref.cumulativeOffset();var dim=ref.getDimensions();var menuDim=menuElement.getDimensions();var offsetX=options.offsetX?options.offsetX:0;var offsetY=options.offsetY?options.offsetY:0;var position=(options.position?options.position:null);var anchor=(options.anchor?options.anchor:null);if(position==Eon.ContextMenu.P_CORNER_LEFT_TOP){offsetX+=pos.left;offsetY+=pos.top;}
else if(position==Eon.ContextMenu.P_CORNER_RIGHT_TOP){offsetX+=pos.left+dim.width;offsetY+=pos.top;}
else if(position==Eon.ContextMenu.P_CORNER_LEFT_BOTTOM){offsetX+=pos.left;offsetY+=pos.top+dim.height;}
else if(position==Eon.ContextMenu.P_CORNER_RIGHT_BOTTOM){offsetX+=pos.left+dim.width;offsetY+=pos.top+dim.height;}
else{offsetX+=Eon.Mouse.x;offsetY+=Eon.Mouse.y;}
var offsetIsAdaptive=(options.adaptiveAnchor&&options.adaptiveOffset);if(options.adaptiveAnchor)
{var docDim=document.viewport.getDimensions();var docScroll=document.viewport.getScrollOffsets();docDim={width:docDim.width+docScroll.left,height:docDim.height+docScroll.top};var x=(anchor==Eon.ContextMenu.A_RIGHT_TOP||anchor==Eon.ContextMenu.A_RIGHT_BOTTOM?"RIGHT":"LEFT");var y=(anchor==Eon.ContextMenu.A_LEFT_BOTTOM||anchor==Eon.ContextMenu.A_RIGHT_BOTTOM?"BOTTOM":"TOP");if(offsetX+menuDim.width>docDim.width)
x="RIGHT";else if(offsetX-menuDim.width-(offsetIsAdaptive?2*options.offsetX:0)<docScroll.left)
x="LEFT";if(offsetY+menuDim.height>docDim.height)
y="BOTTOM";else if((offsetY-menuDim.height-(offsetIsAdaptive?2*options.offsetY:0))<docScroll.top)
y="TOP";eval("anchor = Eon.ContextMenu.A_"+x+"_"+y);}
if(anchor==Eon.ContextMenu.A_LEFT_BOTTOM)
offsetY-=menuDim.height+(offsetIsAdaptive?2*options.offsetY:0);else if(anchor==Eon.ContextMenu.A_RIGHT_TOP)
offsetX-=menuDim.width+(offsetIsAdaptive?2*options.offsetX:0);else if(anchor==Eon.ContextMenu.A_RIGHT_BOTTOM)
{offsetX-=menuDim.width+(offsetIsAdaptive?2*options.offsetX:0);offsetY-=menuDim.height+(offsetIsAdaptive?2*options.offsetY:0);}
menuElement.style.left=offsetX+"px";menuElement.style.top=offsetY+"px";}
Eon.ContextMenu.prototype.clone=function()
{var menu=this.menuElement();var num=0;while(document.getElementById(menu.id+"_"+num))
num++
menu2=menu.clone(true);menu2.id+="_"+num;return new Eon.ContextMenu(menu2,menu.getAttribute("cm-fade"),menu.getAttribute("cm-fade-coef"));}
document.observe("mouseup",Eon.ContextMenu.onHide);document.observe("mouseover",Eon.ContextMenu.createInstanceIfNeeded);Eon.Animation=function()
{var p_is_running=false;var p_paused=false;var p_elements=new Array();var p_origs=new Array();var p_values=new Array();var p_coefs=new Array();var p_dest=0;var p_direction=1;var p_interval=0;var p_current=0;var p_total=0;var p_coef_func=null;var p_func_params=null;var p_this=this;this.attach=function(element,eltParam,pattern,defaultValue,asInt)
{var index=p_retrieveElementIndex(element,eltParam);if(index>-1)
{p_elements[index].pattern=pattern;if(defaultValue!=null)
p_elements[index].defaultValue=defaultValue;if(asInt!=null)
p_elements[index].asInt=(asInt?true:false);}
else
{p_elements.push({object:element,param:eltParam,pattern:pattern,defaultValue:(defaultValue?defaultValue:0),asInt:(asInt?true:false)});if(p_is_running)
p_init(p_elements.length-1);}}
this.detach=function(element,eltParam)
{eltParam=eltParam.toLowerCase();var index=p_retrieveElementIndex(element,eltParam);if(index==-1)
return false;p_elements.splice(index,1);if(p_origs.length);p_origs.splice(index,1);}
this.goTo=function(destValue,imgPerSec,imgCount,coefFunc,coefFuncParams)
{if(typeof(this._browserTransformValue)=="function")
destValue=this._browserTransformValue(destValue);p_dest=parseFloat(destValue);p_current=0;p_direction=1;p_total=parseInt(imgCount);p_interval=parseInt(1000/parseInt(imgPerSec));p_coef_func=(typeof(coefFunc)=="function"?coefFunc:null);p_func_params=coefFuncParams;for(var i=0;i<p_elements.length;i++)
p_init(i);p_is_running=true;this.triggerEvent(new Eon.Event("animation:start"));p_animateAll();}
this.pause=function()
{p_paused=true;}
this.resume=function()
{if(!p_is_running||!p_paused)
return;p_paused=false;p_animateAll();}
this.reverse=function()
{p_direction=-p_direction;}
this.stop=function()
{p_origs=new Array();p_is_running=false;p_paused=false;}
this.isRunning=function()
{return(p_is_running&&!p_paused);}
this.isPaused=function()
{return p_paused;}
this.isStopped=function()
{return(!p_is_running);}
this.getCurrentImage=function()
{return p_current;}
this.getImagesCount=function()
{return p_total;}
this.getCurrentCoef=function(i)
{return p_coefs[i];}
this.getCurrentValue=function(i)
{return p_values[i];}
this._browserTransformValue=null;function p_init(i)
{eval("var value = p_elements[i].object."+p_elements[i].param);if(value&&p_elements[i].pattern)
{var regExp=new RegExp("([\\(\\)||[\\]])","g");var valuePattern=p_elements[i].pattern.replace(regExp,"\\$1");regExp=new RegExp("\\{n\\}");valuePattern=valuePattern.replace(regExp,"([0-9]+\\.*[0-9]*)");regExp=new RegExp(valuePattern);value=parseFloat(regExp.exec(value.toString())[1]);}
if(value==""||value==null)
value=p_elements[i].defaultValue;p_origs[i]=parseFloat(value);}
function p_animateAll()
{if(!p_is_running||p_paused)
return;var length=p_elements.length;for(var i=0;i<length;i++)
p_animate(i);if(p_direction>0&&p_current<p_total||p_direction<0&&p_current>0)
{p_current+=p_direction;setTimeout(function(){p_animateAll();},p_interval);}
else
{p_is_running=false;p_this.triggerEvent(new Eon.Event("animation:finish"));}}
function p_animate(i)
{var diff=p_dest-p_origs[i];p_coefs[i]=p_current/p_total;if(p_coef_func)
p_coefs[i]=p_coef_func(p_coefs[i],p_func_params);var value=(p_current==p_total?p_dest:(p_current==0?p_origs[i]:p_origs[i]+p_coefs[i]*diff));var valueStr=(p_elements[i].asInt?parseInt(value):value);p_values[i]=valueStr;if(p_elements[i].pattern)
{var regExp=new RegExp("\\{n\\}","g");valueStr=p_elements[i].pattern.replace(regExp,valueStr);}
eval("p_elements[i].object."+p_elements[i].param+" = valueStr;");}
function p_retrieveElementIndex(element,eltParam)
{for(var i=0;i<p_elements.length;i++)
if(p_elements[i].object==element&&p_elements[i].param==eltParam)
return i;return-1;}}
Eon.Animation.prototype=new Eon.EventSender();Eon.Animation.prototype.constructor=Eon.Animation;Eon.OpacityAnimation=function()
{Eon.Animation.call(this);this._browserTransformValue=function(value)
{if(document.all)
return Math.floor(value*100);return value;}
var p_superAttach=this.attach;this.attach=function(element,defaultValue)
{if(document.all)
p_superAttach(element,"style.filter","alpha(opacity={n})",defaultValue*100,true);else
p_superAttach(element,"style.opacity",null,defaultValue,false);}}
Eon.OpacityAnimation.prototype=new Eon.Animation();Eon.OpacityAnimation.prototype.constructor=Eon.OpacityAnimation;}
