var IceMenu=new Class({Implements:Options,options:{id:"nav",subMenusContainerId:"subMenusContainer",effect:"slide and fade",duration:600,physics:Fx.Transitions.Pow.easeOut,hideDelay:1000,stretchMainMenu:false,matchWidthMode:false,orientation:"horizontal",direction:{x:"right",y:"down"},tweakInitial:{x:0,y:0},tweakSubsequent:{x:0,y:0},center:false,opacity:95,mmbFocusedClassName:null,mmbClassName:null,killDivider:null,fixHasLayoutBug:false,onHideAllSubMenusNow_begin:(function(){}),onHideAllSubMenusNow_complete:(function(){}),onInit_begin:(function(){}),onInit_complete:(function(){})},hideAllMenusTimeout:null,allSubMenus:[],subMenuZindex:1,initialize:function(d){this.setOptions(d);
this.options.onInit_begin();
if(this.options.opacity>99){this.options.opacity=99.9}this.options.opacity=this.options.opacity/100;
Element.implement({getId:function(){if(!this.id){var a=this.get("tag")+"-"+$time();
while($(a)){a=this.get("tag")+"-"+$time()}this.id=a}return this.id}});
this.options.direction.x=this.options.direction.x.toLowerCase();
this.options.direction.y=this.options.direction.y.toLowerCase();
if(this.options.direction.x==="right"){this.options.direction.xInverse="left"}else{if(this.options.direction.x==="left"){this.options.direction.xInverse="right"}}if(this.options.direction.y==="up"){this.options.direction.yInverse="down"}else{if(this.options.direction.y==="down"){this.options.direction.yInverse="up"}}var e=$(this.options.id).getElements("a");
e.each(function(a,c){a.store("parentLinks",a.getParent().getParents("li").getFirst("a"));
//a.store("parentLinks",a.retrieve("parentLinks").erase(a.retrieve("parentLinks").getFirst()));
a.store("childMenu",a.getNext("ul")||a.getNext("ol"));
theSubMenuType="subsequent";
if($(a.getParent("ul")||a.getParent("ol")).id===this.options.id){theSubMenuType="initial"}a.store("subMenuType",theSubMenuType);
if(theSubMenuType==="initial"&&$(a.getNext("ul")||a.getNext("ol"))){a.addClass("mainMenuParentBtn")}else{if($(a.getNext("ul")||a.getNext("ol"))){a.addClass("subMenuParentBtn")}}}.bind(this));
var g=new Element("div",{"id":this.options.subMenusContainerId}).inject($(document.body),"bottom");
$(this.options.id).getElements("ul, ol").each(function(a,c){new Element("div",{"class":"smOW"}).inject(g).grab(a)}.bind(this));
g.getElements("a").set("tabindex","-1");
e.each(function(a,c){if(!a.retrieve("childMenu")){return}a.store("childMenu",a.retrieve("childMenu").getParent("div"));
this.allSubMenus.include(a.retrieve("childMenu"));
//a.store("parentSubMenus",a.retrieve("parentLinks").retrieve("childMenu"));
var b=new MenuMaticSubMenu(this.options,this,a)}.bind(this));
var h=$(this.options.id).getElements("a").filter(function(a,c){return!a.retrieve("childMenu")});
h.each(function(b,f){b.addEvents({"mouseenter":function(a){this.hideAllSubMenusNow();
if(this.options.mmbClassName&&this.options.mmbFocusedClassName){$(b).retrieve("btnMorph",new Fx.Morph(b,{"duration":(this.options.duration/2),transition:this.options.physics,link:"cancel"})).start(this.options.mmbFocusedClassName)}}.bind(this),"focus":function(a){this.hideAllSubMenusNow();
if(this.options.mmbClassName&&this.options.mmbFocusedClassName){$(b).retrieve("btnMorph",new Fx.Morph(b,{"duration":(this.options.duration/2),transition:this.options.physics,link:"cancel"})).start(this.options.mmbFocusedClassName)}}.bind(this),"mouseleave":function(a){if(this.options.mmbClassName&&this.options.mmbFocusedClassName){$(b).retrieve("btnMorph",new Fx.Morph(b,{"duration":(this.options.duration*5),transition:this.options.physics,link:"cancel"})).start(this.options.mmbClassName)}}.bind(this),"blur":function(a){if(this.options.mmbClassName&&this.options.mmbFocusedClassName){$(b).retrieve("btnMorph",new Fx.Morph(b,{"duration":(this.options.duration*5),transition:this.options.physics,link:"cancel"})).start(this.options.mmbClassName)}}.bind(this),"keydown":function(a){var c=new Event(a);
if(a.key==="up"||a.key==="down"||a.key==="left"||a.key==="right"){a.stop()}if(a.key==="left"&&this.options.orientation==="horizontal"||a.key==="up"&&this.options.orientation==="vertical"){if(b.getParent("li").getPrevious("li")){b.getParent("li").getPrevious("li").getFirst("a").focus()}else{b.getParent("li").getParent().getLast("li").getFirst("a").focus()}}else{if(a.key==="right"&&this.options.orientation==="horizontal"||a.key==="down"&&this.options.orientation==="vertical"){if(b.getParent("li").getNext("li")){b.getParent("li").getNext("li").getFirst("a").focus()}else{b.getParent("li").getParent().getFirst("li").getFirst("a").focus()}}}}.bind(this)})},this);
this.stretch();
this.killDivider();
this.center();
this.fixHasLayoutBug();
this.options.onInit_complete()},fixHasLayoutBug:function(){if(Browser.Engine.trident&&this.options.fixHasLayoutBug){$(this.options.id).getParents().setStyle("zoom",1);
$(this.options.id).setStyle("zoom",1);
$(this.options.id).getChildren().setStyle("zoom",1);
$(this.options.subMenusContainerId).setStyle("zoom",1);
$(this.options.subMenusContainerId).getChildren().setStyle("zoom",1)}},center:function(){if(!this.options.center){return}$(this.options.id).setStyles({"left":"50%","margin-left":-($(this.options.id).getSize().x/2)})},stretch:function(){if(this.options.stretchMainMenu&&this.options.orientation==="horizontal"){var b=parseFloat($(this.options.id).getCoordinates().width);
var f=0;
var d=$(this.options.id).getElements("a");
d.setStyles({"padding-left":0,"padding-right":0});
d.each(function(a,c){f+=a.getSize().x}.bind(this));
if(b<f){return}var e=(b-f)/d.length;
d.each(function(a,c){a.setStyle("width",a.getSize().x+e)}.bind(this));
d.getLast().setStyle("width",d.getLast().getSize().x-1)}},killDivider:function(){if(this.options.killDivider&&this.options.killDivider.toLowerCase()==="first"){$($(this.options.id).getElements("li")[0]).setStyles({"background":"none"})}else{if(this.options.killDivider&&this.options.killDivider.toLowerCase()==="last"){$($(this.options.id).getElements("li").getLast()).setStyles({"background":"none"})}}},hideAllSubMenusNow:function(){this.options.onHideAllSubMenusNow_begin();
$clear(this.hideAllMenusTimeout);
$$(this.allSubMenus).fireEvent("hide");
this.options.onHideAllSubMenusNow_complete()}});
var MenuMaticSubMenu=new Class({Implements:Options,Extends:IceMenu,options:{onSubMenuInit_begin:(function(a){}),onSubMenuInit_complete:(function(a){}),onMatchWidth_begin:(function(a){}),onMatchWidth_complete:(function(a){}),onHideSubMenu_begin:(function(a){}),onHideSubMenu_complete:(function(a){}),onHideOtherSubMenus_begin:(function(a){}),onHideOtherSubMenus_complete:(function(a){}),onHideAllSubMenus_begin:(function(a){}),onHideAllSubMenus_complete:(function(a){}),onPositionSubMenu_begin:(function(a){}),onPositionSubMenu_complete:(function(a){}),onShowSubMenu_begin:(function(a){}),onShowSubMenu_complete:(function(a){})},root:null,btn:null,hidden:true,myEffect:null,initialize:function(d,e,g){this.setOptions(d);
this.root=e;
this.btn=g;
this.childMenu=this.btn.retrieve("childMenu");
this.subMenuType=this.btn.retrieve("subMenuType");
this.childMenu=this.btn.retrieve("childMenu");
this.parentSubMenus=$$(this.btn.retrieve("parentSubMenus"));
this.parentLinks=$$(this.btn.retrieve("parentLinks"));
this.parentSubMenu=$(this.parentSubMenus[0]);
if(this.parentSubMenu){this.parentSubMenu=this.parentSubMenu.retrieve("class")}this.childMenu.store("class",this);
this.btn.store("class",this);
this.childMenu.store("status","closed");
this.options.onSubMenuInit_begin(this);
this.childMenu.addEvent("hide",function(){this.hideSubMenu()}.bind(this));
this.childMenu.addEvent("show",function(){this.showSubMenu()}.bind(this));
if(this.options.effect){this.myEffect=new Fx.Morph($(this.childMenu).getFirst(),{duration:this.options.duration,transition:this.options.physics,link:"cancel"})}if(this.options.effect==="slide"||this.options.effect==="slide and fade"){if(this.subMenuType=="initial"&&this.options.orientation==="horizontal"){this.childMenu.getFirst().setStyle("margin-top","0")}else{this.childMenu.getFirst().setStyle("margin-left","0")}}else{if(this.options.effect==="fade"||this.options.effect==="slide and fade"){this.childMenu.getFirst().setStyle("opacity",0)}}if(this.options.effect!="fade"&&this.options.effect!="slide and fade"){this.childMenu.getFirst().setStyle("opacity",this.options.opacity)}var h=$(this.childMenu).getElements("a").filter(function(a,c){return!a.retrieve("childMenu")});
h.each(function(b,f){$(b).addClass("subMenuBtn");
b.addEvents({"mouseenter":function(a){this.childMenu.fireEvent("show");
this.cancellHideAllSubMenus();
this.hideOtherSubMenus()}.bind(this),"focus":function(a){this.childMenu.fireEvent("show");
this.cancellHideAllSubMenus();
this.hideOtherSubMenus()}.bind(this),"mouseleave":function(a){this.cancellHideAllSubMenus();
this.hideAllSubMenus()}.bind(this),"blur":function(a){this.cancellHideAllSubMenus();
this.hideAllSubMenus()}.bind(this),"keydown":function(a){var c=new Event(a);
if(a.key==="up"||a.key==="down"||a.key==="left"||a.key==="right"||a.key==="tab"){a.stop()}if(a.key==="up"){if(b.getParent("li").getPrevious("li")){b.getParent("li").getPrevious("li").getFirst("a").focus()}else{if(this.options.direction.y==="down"){this.btn.focus()}else{if(this.options.direction.y==="up"){b.getParent("li").getParent().getLast("li").getFirst("a").focus()}}}}else{if(a.key==="down"){if(b.getParent("li").getNext("li")){b.getParent("li").getNext("li").getFirst("a").focus()}else{if(this.options.direction.y==="down"){b.getParent("li").getParent().getFirst("li").getFirst("a").focus()}else{if(this.options.direction.y==="up"){this.btn.focus()}}}}else{if(a.key===this.options.direction.xInverse){this.btn.focus()}}}}.bind(this)})},this);
$(this.btn).removeClass("subMenuBtn");
if(this.subMenuType=="initial"){this.btn.addClass("mainParentBtn")}else{this.btn.addClass("subParentBtn")}$(this.btn).addEvents({"mouseenter":function(a){this.cancellHideAllSubMenus();
this.hideOtherSubMenus();
this.showSubMenu();
if(this.subMenuType==="initial"&&this.options.mmbClassName&&this.options.mmbFocusedClassName){$(this.btn).retrieve("btnMorph",new Fx.Morph($(this.btn),{"duration":(this.options.duration/2),transition:this.options.physics,link:"cancel"})).start(this.options.mmbFocusedClassName)}}.bind(this),"focus":function(a){this.cancellHideAllSubMenus();
this.hideOtherSubMenus();
this.showSubMenu();
if(this.subMenuType==="initial"&&this.options.mmbClassName&&this.options.mmbFocusedClassName){$(this.btn).retrieve("btnMorph",new Fx.Morph($(this.btn),{"duration":(this.options.duration/2),transition:this.options.physics,link:"cancel"})).start(this.options.mmbFocusedClassName)}}.bind(this),"mouseleave":function(a){this.cancellHideAllSubMenus();
this.hideAllSubMenus()}.bind(this),"blur":function(a){this.cancellHideAllSubMenus();
this.hideAllSubMenus()}.bind(this),"keydown":function(a){a=new Event(a);
if(a.key==="up"||a.key==="down"||a.key==="left"||a.key==="right"){a.stop()}if(!this.parentSubMenu){if(this.options.orientation==="horizontal"&&a.key===this.options.direction.y||this.options.orientation==="vertical"&&a.key===this.options.direction.x){if(this.options.direction.y==="down"){this.childMenu.getFirst().getFirst("li").getFirst("a").focus()}else{if(this.options.direction.y==="up"){this.childMenu.getFirst().getLast("li").getFirst("a").focus()}}}else{if(this.options.orientation==="horizontal"&&a.key==="left"||this.options.orientation==="vertical"&&a.key===this.options.direction.yInverse){if(this.btn.getParent().getPrevious()){this.btn.getParent().getPrevious().getFirst().focus()}else{this.btn.getParent().getParent().getLast().getFirst().focus()}}else{if(this.options.orientation==="horizontal"&&a.key==="right"||this.options.orientation==="vertical"&&a.key===this.options.direction.y){if(this.btn.getParent().getNext()){this.btn.getParent().getNext().getFirst().focus()}else{this.btn.getParent().getParent().getFirst().getFirst().focus()}}}}}else{if(a.key==="tab"){a.stop()}if(a.key==="up"){if(this.btn.getParent("li").getPrevious("li")){this.btn.getParent("li").getPrevious("li").getFirst("a").focus()}else{if(this.options.direction.y==="down"){this.parentSubMenu.btn.focus()}else{if(this.options.direction.y==="up"){this.btn.getParent("li").getParent().getLast("li").getFirst("a").focus()}}}}else{if(a.key==="down"){if(this.btn.getParent("li").getNext("li")){this.btn.getParent("li").getNext("li").getFirst("a").focus()}else{if(this.options.direction.y==="down"){this.btn.getParent("li").getParent().getFirst("li").getFirst("a").focus()}else{if(this.options.direction.y==="up"){this.parentSubMenu.btn.focus()}}}}else{if(a.key===this.options.direction.xInverse){this.parentSubMenu.btn.focus()}else{if(a.key===this.options.direction.x){if(this.options.direction.y==="down"){this.childMenu.getFirst().getFirst("li").getFirst("a").focus()}else{if(this.options.direction.y==="up"){}}}}}}}}.bind(this)});
this.options.onSubMenuInit_complete(this)},matchWidth:function(){if(this.widthMatched||!this.options.matchWidthMode||this.subMenuType==="subsequent"){return}this.options.onMatchWidth_begin(this);
var e=this.btn.getCoordinates().width;
$(this.childMenu).getElements("a").each(function(a,c){var b=parseFloat($(this.childMenu).getFirst().getStyle("border-left-width"))+parseFloat($(this.childMenu).getFirst().getStyle("border-right-width"));
var f=parseFloat(a.getStyle("padding-left"))+parseFloat(a.getStyle("padding-right"));
var d=b+f;
if(e>a.getCoordinates().width){a.setStyle("width",e-d);
a.setStyle("margin-right",-b)}}.bind(this));
this.width=this.childMenu.getFirst().getCoordinates().width;
this.widthMatched=true;
this.options.onMatchWidth_complete(this)},hideSubMenu:function(){if(this.childMenu.retrieve("status")==="closed"){return}this.options.onHideSubMenu_begin(this);
if(this.subMenuType=="initial"){if(this.options.mmbClassName&&this.options.mmbFocusedClassName){$(this.btn).retrieve("btnMorph",new Fx.Morph($(this.btn),{"duration":(this.options.duration),transition:this.options.physics,link:"cancel"})).start(this.options.mmbClassName).chain(function(){$(this.btn).removeClass("mainMenuParentBtnFocused");
$(this.btn).addClass("mainMenuParentBtn")}.bind(this))}else{$(this.btn).removeClass("mainMenuParentBtnFocused");
$(this.btn).addClass("mainMenuParentBtn")}}else{$(this.btn).removeClass("subMenuParentBtnFocused");
$(this.btn).addClass("subMenuParentBtn")}this.childMenu.setStyle("z-index",1);
if(this.options.effect&&this.options.effect.toLowerCase()==="slide"){if(this.subMenuType=="initial"&&this.options.orientation==="horizontal"&&this.options.direction.y==="down"){this.myEffect.start({"margin-top":-this.height}).chain(function(){this.childMenu.style.display="none"}.bind(this))}else{if(this.subMenuType=="initial"&&this.options.orientation==="horizontal"&&this.options.direction.y==="up"){this.myEffect.start({"margin-top":this.height}).chain(function(){this.childMenu.style.display="none"}.bind(this))}else{if(this.options.direction.x==="right"){this.myEffect.start({"margin-left":-this.width}).chain(function(){this.childMenu.style.display="none"}.bind(this))}else{if(this.options.direction.x==="left"){this.myEffect.start({"margin-left":this.width}).chain(function(){this.childMenu.style.display="none"}.bind(this))}}}}}else{if(this.options.effect=="fade"){this.myEffect.start({"opacity":0}).chain(function(){this.childMenu.style.display="none"}.bind(this))}else{if(this.options.effect=="slide and fade"){if(this.subMenuType=="initial"&&this.options.orientation==="horizontal"&&this.options.direction.y==="down"){this.myEffect.start({"margin-top":-this.height,opacity:0}).chain(function(){this.childMenu.style.display="none"}.bind(this))}else{if(this.subMenuType=="initial"&&this.options.orientation==="horizontal"&&this.options.direction.y==="up"){this.myEffect.start({"margin-top":this.height,opacity:0}).chain(function(){this.childMenu.style.display="none"}.bind(this))}else{if(this.options.direction.x==="right"){this.myEffect.start({"margin-left":-this.width,opacity:0}).chain(function(){this.childMenu.style.display="none"}.bind(this))}else{if(this.options.direction.x==="left"){this.myEffect.start({"margin-left":this.width,opacity:0}).chain(function(){this.childMenu.style.display="none"}.bind(this))}}}}}else{this.childMenu.style.display="none"}}}this.childMenu.store("status","closed");
this.options.onHideSubMenu_complete(this)},hideOtherSubMenus:function(){this.options.onHideOtherSubMenus_begin(this);
//if(!this.btn.retrieve("otherSubMenus")){this.btn.store("otherSubMenus",$$(this.root.allSubMenus.filter(function(a){return!this.btn.retrieve("parentSubMenus").contains(a)&&a!=this.childMenu}.bind(this))))}this.parentSubMenus.fireEvent("show");
//this.btn.retrieve("otherSubMenus").fireEvent("hide");
this.options.onHideOtherSubMenus_complete(this)},hideAllSubMenus:function(){this.options.onHideAllSubMenus_begin(this);
$clear(this.root.hideAllMenusTimeout);
this.root.hideAllMenusTimeout=(function(){$clear(this.hideAllMenusTimeout);
$$(this.root.allSubMenus).fireEvent("hide")}).bind(this).delay(this.options.hideDelay);
this.options.onHideAllSubMenus_complete(this)},cancellHideAllSubMenus:function(){$clear(this.root.hideAllMenusTimeout)},showSubMenu:function(a){if(this.childMenu.retrieve("status")==="open"){return}this.options.onShowSubMenu_begin(this);
if(this.subMenuType=="initial"){$(this.btn).removeClass("mainMenuParentBtn");
$(this.btn).addClass("mainMenuParentBtnFocused")}else{$(this.btn).removeClass("subMenuParentBtn");
$(this.btn).addClass("subMenuParentBtnFocused")}this.root.subMenuZindex++;
this.childMenu.setStyles({"display":"block","visibility":"hidden","z-index":this.root.subMenuZindex});
if(!this.width||!this.height){this.width=this.childMenu.getFirst().getCoordinates().width;
this.height=this.childMenu.getFirst().getCoordinates().height;
this.childMenu.setStyle("height",this.height,"border");
if(this.options.effect==="slide"||this.options.effect==="slide and fade"){if(this.subMenuType=="initial"&&this.options.orientation==="horizontal"){this.childMenu.getFirst().setStyle("margin-top","0");
if(this.options.direction.y==="down"){this.myEffect.set({"margin-top":-this.height})}else{if(this.options.direction.y==="up"){this.myEffect.set({"margin-top":this.height})}}}else{if(this.options.direction.x==="left"){this.myEffect.set({"margin-left":this.width})}else{this.myEffect.set({"margin-left":-this.width})}}}}this.matchWidth();
this.positionSubMenu();
if(this.options.effect==="slide"){this.childMenu.setStyles({"display":"block","visibility":"visible"});
if(this.subMenuType==="initial"&&this.options.orientation==="horizontal"){if(a){this.myEffect.set({"margin-top":0}).chain(function(){this.showSubMenuComplete()}.bind(this))}else{this.myEffect.start({"margin-top":0}).chain(function(){this.showSubMenuComplete()}.bind(this))}}else{if(a){this.myEffect.set({"margin-left":0}).chain(function(){this.showSubMenuComplete()}.bind(this))}else{this.myEffect.start({"margin-left":0}).chain(function(){this.showSubMenuComplete()}.bind(this))}}}else{if(this.options.effect==="fade"){if(a){this.myEffect.set({"opacity":this.options.opacity}).chain(function(){this.showSubMenuComplete()}.bind(this))}else{this.myEffect.start({"opacity":this.options.opacity}).chain(function(){this.showSubMenuComplete()}.bind(this))}}else{if(this.options.effect=="slide and fade"){this.childMenu.setStyles({"display":"block","visibility":"visible"});
this.childMenu.getFirst().setStyles({"left":0});
if(this.subMenuType==="initial"&&this.options.orientation==="horizontal"){if(a){this.myEffect.set({"margin-top":0,"opacity":this.options.opacity}).chain(function(){this.showSubMenuComplete()}.bind(this))}else{this.myEffect.start({"margin-top":0,"opacity":this.options.opacity}).chain(function(){this.showSubMenuComplete()}.bind(this))}}else{if(a){if(this.options.direction.x==="right"){this.myEffect.set({"margin-left":0,"opacity":this.options.opacity}).chain(function(){this.showSubMenuComplete()}.bind(this))}else{if(this.options.direction.x==="left"){this.myEffect.set({"margin-left":0,"opacity":this.options.opacity}).chain(function(){this.showSubMenuComplete()}.bind(this))}}}else{if(this.options.direction.x==="right"){this.myEffect.set({"margin-left":-this.width,"opacity":this.options.opacity});
this.myEffect.start({"margin-left":0,"opacity":this.options.opacity}).chain(function(){this.showSubMenuComplete()}.bind(this))}else{if(this.options.direction.x==="left"){this.myEffect.start({"margin-left":0,"opacity":this.options.opacity}).chain(function(){this.showSubMenuComplete()}.bind(this))}}}}}else{this.childMenu.setStyles({"display":"block","visibility":"visible"}).chain(function(){this.showSubMenuComplete(this)}.bind(this))}}}this.childMenu.store("status","open")},showSubMenuComplete:function(){this.options.onShowSubMenu_complete(this)},positionSubMenu:function(){this.options.onPositionSubMenu_begin(this);
this.childMenu.setStyle("width",this.width);
this.childMenu.getFirst().setStyle("width",this.width);
if(this.subMenuType==="subsequent"){if(this.parentSubMenu&&this.options.direction.x!=this.parentSubMenu.options.direction.x){if(this.parentSubMenu.options.direction.x==="left"&&this.options.effect&&this.options.effect.contains("slide")){this.myEffect.set({"margin-left":this.width})}}this.options.direction.x=this.parentSubMenu.options.direction.x;
this.options.direction.xInverse=this.parentSubMenu.options.direction.xInverse;
this.options.direction.y=this.parentSubMenu.options.direction.y;
this.options.direction.yInverse=this.parentSubMenu.options.direction.yInverse}var a;
var c;
if(this.subMenuType=="initial"){if(this.options.direction.y==="up"){if(this.options.orientation==="vertical"){a=this.btn.getCoordinates().bottom-this.height+this.options.tweakInitial.y}else{a=this.btn.getCoordinates().top-this.height+this.options.tweakInitial.y}this.childMenu.style.top=a+"px"}else{if(this.options.orientation=="horizontal"){this.childMenu.style.top=this.btn.getCoordinates().bottom+this.options.tweakInitial.y+"px"}else{if(this.options.orientation=="vertical"){a=this.btn.getPosition().y+this.options.tweakInitial.y;
if((a+this.childMenu.getSize().y)>=$(document.body).getScrollSize().y){c=(a+this.childMenu.getSize().y)-$(document.body).getScrollSize().y;
a=a-c-20}this.childMenu.style.top=a+"px"}}}if(this.options.orientation=="horizontal"){this.childMenu.style.left=this.btn.getPosition().x+this.options.tweakInitial.x+"px"}else{if(this.options.direction.x=="left"){this.childMenu.style.left=this.btn.getPosition().x-this.childMenu.getCoordinates().width+this.options.tweakInitial.x+"px"}else{if(this.options.direction.x=="right"){this.childMenu.style.left=this.btn.getCoordinates().right+this.options.tweakInitial.x+"px"}}}}else{if(this.subMenuType=="subsequent"){if(this.options.direction.y==="down"){if((this.btn.getCoordinates().top+this.options.tweakSubsequent.y+this.childMenu.getSize().y)>=$(document.body).getScrollSize().y){c=(this.btn.getCoordinates().top+this.options.tweakSubsequent.y+this.childMenu.getSize().y)-$(document.body).getScrollSize().y;
this.childMenu.style.top=(this.btn.getCoordinates().top+this.options.tweakSubsequent.y)-c-20+"px"}else{this.childMenu.style.top=this.btn.getCoordinates().top+this.options.tweakSubsequent.y+"px"}}else{if(this.options.direction.y==="up"){if((this.btn.getCoordinates().bottom-this.height+this.options.tweakSubsequent.y)<1){this.options.direction.y="down";
this.options.direction.yInverse="up";
this.childMenu.style.top=this.btn.getCoordinates().top+this.options.tweakSubsequent.y+"px"}else{this.childMenu.style.top=this.btn.getCoordinates().bottom-this.height+this.options.tweakSubsequent.y+"px"}}}if(this.options.direction.x=="left"){this.childMenu.style.left=this.btn.getCoordinates().left-this.childMenu.getCoordinates().width+this.options.tweakSubsequent.x+"px";
if(this.childMenu.getPosition().x<0){this.options.direction.x="right";
this.options.direction.xInverse="left";
this.childMenu.style.left=this.btn.getPosition().x+this.btn.getCoordinates().width+this.options.tweakSubsequent.x+"px";
if(this.options.effect==="slide"||this.options.effect==="slide and fade"){this.myEffect.set({"margin-left":-this.width,"opacity":this.options.opacity})}}}else{if(this.options.direction.x=="right"){this.childMenu.style.left=this.btn.getCoordinates().right+this.options.tweakSubsequent.x+"px";
var b=this.childMenu.getCoordinates().right;
var f=document.getCoordinates().width+window.getScroll().x;
if(b>f){this.options.direction.x="left";
this.options.direction.xInverse="right";
this.childMenu.style.left=this.btn.getCoordinates().left-this.childMenu.getCoordinates().width+this.options.tweakSubsequent.x+"px";
if(this.options.effect==="slide"||this.options.effect==="slide and fade"){this.myEffect.set({"margin-left":this.width,"opacity":this.options.opacity})}}}}}}this.options.onPositionSubMenu_complete(this)}});
