/**
 * menuMatic 
 * @version 0.67 (beta)
 * @author Jason J. Jaeger | greengeckodesign.com
 * @copyright 2008 Jason John Jaeger
 * @license MIT-style License
 *			Permission is hereby granted, free of charge, to any person obtaining a copy
 *			of this software and associated documentation files (the "Software"), to deal
 *			in the Software without restriction, including without limitation the rights
 *			to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *			copies of the Software, and to permit persons to whom the Software is
 *			furnished to do so, subject to the following conditions:
 *	
 *			The above copyright notice and this permission notice shall be included in
 *			all copies or substantial portions of the Software.
 *	
 *			THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *			IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *			FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *			AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *			LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *			OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *			THE SOFTWARE.	
 **/
 
var MenuMatic=new Class(
{Implements:Options,options:
{id:"nav",subMenusContainerId:"subMenusContainer",effect:"slide & fade",duration:600,physics:Fx.Transitions.Pow.easeOut,hideDelay:300,menuWidth:false,matchWidthMode:false,orientation:"horizontal",direction:
{x:"right",y:"down"
},tweakInitial:
{x:0,y:0
},tweakSubsequent:
{x:0,y:0
},opacity:95,mmbFocusedClassName:null,mmbClassName:null,killDivider:null,debug:false
},classElHash:new Hash(),hideAllMenusTimeout:null,parentBtns:new Hash(),subMenuZindex:1,initialize:function(P)
{if(Browser.Engine.webkit419)
{return 
}if($type(this.parentBtns)==="object")
{this.parentBtns=new Hash()
}if($type(this.classElHash)==="object")
{this.classElHash=new Hash()
}this.setOptions(P);
this.options.opacity=this.options.opacity/100;
var D=$(this.options.id).getElements("a");
var F=[];
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"
}
}D.each(function(Q)
{var R=new Object();
if($(Q).getNext("ul")||$(Q).getNext("ol"))
{var S="subsequent";
if($(Q).parentNode.parentNode.id&&$(Q).parentNode.parentNode.id==this.options.id)
{S="initial"
}R.btn=$(Q);
this.parentBtns.set(this.getOrSetId(R.btn),R.btn);
if(S==="initial")
{R.btn.addClass("mainMenuParentBtn")
}else
{R.btn.addClass("subMenuParentBtn")
}R.childMenu=$(Q).getNext();
R.parentSubMenus=this.getParents($(Q),this.options.id,"ul,ol");
R.subMenuType=S;
F.push(R)
}
}.bind(this));
var H=new Element("div",
{id:this.options.subMenusContainerId
}).inject($(document.body),"bottom");
F.each(function(R,Q)
{var S=new Element("div",
{"class":"smOW "
}).inject(H);
R.childMenu.inject(S);
R.childMenu=S;
this.classElHash.set(this.getOrSetId(S),null)
}.bind(this));
for(var I in F)
{if(F.hasOwnProperty(I))
{var O=new Hash();
for(var N in F[I].parentSubMenus)
{if(F[I].parentSubMenus.hasOwnProperty(N))
{var A=$(F[I].parentSubMenus[N]).getParent().id;
O.set(A,null)
}
}F[I].parentSubMenus=O
}
}H.getElements("a").each(function(R,Q)
{R.set("tabindex","-1")
});
for(var I in F)
{if(F.hasOwnProperty(I))
{$(F[I].btn).store("isParent",true);
var G=new MenuMaticSubMenu(this.options,
{root:this,btn:F[I].btn,childMenu:F[I].childMenu,parentSubMenus:F[I].parentSubMenus,subMenuType:F[I].subMenuType
});
G.setOptions(this.options);
this.classElHash[F[I].childMenu.id]=G
}
}this.classElHash.each(function(R,Q)
{var S=[];
R.parentSubMenus.each(function(T,U)
{R.parentSubMenus[U]=this.classElHash[U];
S.push(this.classElHash[U])
}.bind(this));
R.parentSubMenu=S[0]
}.bind(this));
var M=$(this.options.id).getElements("a").filter(function(R,Q)
{return !this.parentBtns.contains(R)
}.bind(this));
M.each(function(R,Q)
{R.addEvents(
{mouseenter:function(S)
{S=new Event(S).stop();
this.hideAllSubMenusNow();

if(this.options.mmbClassName&&this.options.mmbFocusedClassName)
{$(R).retrieve("btnMorph",new Fx.Morph(R,
{duration:(this.options.duration/2),transition:this.options.physics,link:"cancel"
})).start(this.options.mmbFocusedClassName)
}
}.bind(this),focus:function(S)
{S=new Event(S).stop();
this.hideAllSubMenusNow();
if(this.options.mmbClassName&&this.options.mmbFocusedClassName)
{$(R).retrieve("btnMorph",new Fx.Morph(R,
{duration:(this.options.duration/2),transition:this.options.physics,link:"cancel"
})).start(this.options.mmbFocusedClassName)
}
}.bind(this),mouseleave:function(S)
{S=new Event(S).stop();
if(this.options.mmbClassName&&this.options.mmbFocusedClassName)
{$(R).retrieve("btnMorph",new Fx.Morph(R,
{duration:(this.options.duration*5),transition:this.options.physics,link:"cancel"
})).start(this.options.mmbClassName)
}
}.bind(this),blur:function(S)
{S=new Event(S).stop();
if(this.options.mmbClassName&&this.options.mmbFocusedClassName)
{$(R).retrieve("btnMorph",new Fx.Morph(R,
{duration:(this.options.duration*5),transition:this.options.physics,link:"cancel"
})).start(this.options.mmbClassName)
}
}.bind(this),keydown:function(T)
{var S=new Event(T);
if(T.key==="up"||T.key==="down"||T.key==="left"||T.key==="right")
{T.stop()
}if(T.key==="left"&&this.options.orientation==="horizontal"||T.key==="up"&&this.options.orientation==="vertical")
{if(R.getParent("li").getPrevious("li"))
{R.getParent("li").getPrevious("li").getFirst("a").focus()
}else
{R.getParent("li").getParent().getLast("li").getFirst("a").focus()
}
}else
{if(T.key==="right"&&this.options.orientation==="horizontal"||T.key==="down"&&this.options.orientation==="vertical")
{if(R.getParent("li").getNext("li"))
{R.getParent("li").getNext("li").getFirst("a").focus()
}else
{R.getParent("li").getParent().getFirst("li").getFirst("a").focus()
}
}
}
}.bind(this)
})
},this);
if(this.options.menuWidth&&this.options.orientation==="horizontal")
{var L=parseFloat($(this.options.id).getCoordinates().width);
var E=0;
var B=$(this.options.id).getElements("a");
var K=0+parseFloat($(B[0]).getStyle("border-left-width"))+parseFloat($(B[B.length-1]).getStyle("border-right-width"));
var C=1000;
var J=0;
B.each(function(R,Q)
{R.setStyles(
{"padding-left":0,"padding-right":0
})
}.bind(this));
while((E+K)<L&&C>0)
{C--;
E=0;
B[J].setStyle("width",B[J].getCoordinates().width+1);
B.each(function(R,Q)
{E+=R.getCoordinates().width
}.bind(this));
J++;
if(J>B.length-1)
{J=0
}
}
}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"
})
}
}
},getParents:function(F,E,A)
{var D=[];
if(A)
{A=A.toString().split(",");
A.each(function(H,G)
{A[G]=A[G].toLowerCase()
})
}currentObj=F;
var C=200;
var B=0;
while(currentObj.parentNode&&currentObj.parentNode.id!=E)
{B++;
if(B>C)
{break
}if(!A||A.contains(currentObj.parentNode.tagName.toLowerCase()))
{D.push(currentObj.parentNode)
}currentObj=currentObj.parentNode
}return D
},getOrSetId:function(C)
{if(!C.id)
{var D=new Date();
var B=D.getMilliseconds().toString();
var A=Math.floor(Math.random()*1000);
if(C.nodeName)
{C.id=C.nodeName.toString()+"-"+B+A.toString()
}else
{C.id="element"+B+A.toString()
}
}return C.id
},hideAllSubMenusNow:function()
{
$clear(this.hideAllMenusTimeout);
this.classElHash.each(function(B,A)
{B.hideSubMenu()
}.bind(this))
}
});
var MenuMaticSubMenu=new Class(
{Implements:Options,Extends:MenuMatic,options:
{
},root:null,btn:null,childMenu:null,subMenuType:null,parentSubMenus:new Hash(),parentSubMenu:null,hidden:true,myEffect:null,width:false,height:null,widthMatched:false,initialize:function(B,C)
{if($type(this.parentBtns)==="object")
{this.parentBtns=new Hash()
}if($type(this.classElHash)==="object")
{this.classElHash=new Hash()
}this.setOptions(B);
for(var A in C)
{if(C.hasOwnProperty(A))
{this[A]=C[A]
}
}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 & 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 & fade")
{this.childMenu.getFirst().setStyle("opacity",0)
}
}if(this.options.effect!="fade"&&this.options.effect!="slide & fade")
{this.childMenu.getFirst().setStyle("opacity",this.options.opacity)
}var D=$(this.childMenu).getElements("a").filter(function(F,E)
{return !this.parentBtns.contains(F)
}.bind(this));
D.each(function(F,E)
{$(F).addClass("subMenuBtn");
F.addEvents(
{mouseenter:function(G)
{G=new Event(G).stop();
this.cancellHideAllSubMenus();
if(!F.retrieve("isParent"))
{this.hideOtherSubMenus()
}
}.bind(this),focus:function(G)
{G=new Event(G).stop();
this.cancellHideAllSubMenus();
if(!F.retrieve("isParent"))
{this.hideOtherSubMenus()
}
}.bind(this),mouseleave:function(G)
{G=new Event(G).stop();
this.cancellHideAllSubMenus();
this.hideAllSubMenus()
}.bind(this),blur:function(G)
{G=new Event(G).stop();
this.cancellHideAllSubMenus();
this.hideAllSubMenus()
}.bind(this),keydown:function(H)
{var G=new Event(H);
if(H.key==="up"||H.key==="down"||H.key==="left"||H.key==="right"||H.key==="tab")
{H.stop()
}if(H.key==="up")
{if(F.getParent("li").getPrevious("li"))
{F.getParent("li").getPrevious("li").getFirst("a").focus()
}else
{if(this.options.direction.y==="down")
{this.btn.focus()
}else
{if(this.options.direction.y==="up")
{F.getParent("li").getParent().getLast("li").getFirst("a").focus()
}
}
}
}else
{if(H.key==="down")
{if(F.getParent("li").getNext("li"))
{F.getParent("li").getNext("li").getFirst("a").focus()
}else
{if(this.options.direction.y==="down")
{F.getParent("li").getParent().getFirst("li").getFirst("a").focus()
}else
{if(this.options.direction.y==="up")
{this.btn.focus()
}
}
}
}else
{if(H.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(E)
{E=new Event(E).stop();
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(E)
{E=new Event(E).stop();
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(E)
{E=new Event(E).stop();
this.cancellHideAllSubMenus();
this.hideAllSubMenus()
}.bind(this),blur:function(E)
{E=new Event(E).stop();
this.cancellHideAllSubMenus();
this.hideAllSubMenus()
}.bind(this),keydown:function(E)
{E=new Event(E);
if(E.key==="up"||E.key==="down"||E.key==="left"||E.key==="right")
{E.stop()
}if(!this.parentSubMenu)
{if(this.options.orientation==="horizontal"&&E.key===this.options.direction.y||this.options.orientation==="vertical"&&E.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"&&E.key==="left"||this.options.orientation==="vertical"&&E.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"&&E.key==="right"||this.options.orientation==="vertical"&&E.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(E.key==="tab")
{E.stop()
}if(E.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(E.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(E.key===this.options.direction.xInverse)
{this.parentSubMenu.btn.focus()
}else
{if(E.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)
})
},matchWidth:function()
{if(this.widthMatched||!this.options.matchWidthMode||this.subMenuType==="subsequent")
{return 
}var A=this.btn.getCoordinates().width;
$(this.childMenu).getElements("a").each(function(E,D)
{var C=parseFloat($(this.childMenu).getFirst().getStyle("border-left-width"))+parseFloat($(this.childMenu).getFirst().getStyle("border-right-width"));
var B=parseFloat(E.getStyle("padding-left"))+parseFloat(E.getStyle("padding-right"));
var F=C+B;
if(A>E.getCoordinates().width)
{E.setStyle("width",A-F);
E.setStyle("margin-right",-C)
}
}.bind(this));
this.width=this.childMenu.getFirst().getCoordinates().width;
this.widthMatched=true
},hideSubMenu:function()
{
if(this.hidden)
{
 return 
}

hideFrame(this.childMenu.childNodes[0].className) ;

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 & 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.hidden=true
},hideOtherSubMenus:function()
{var A=[];
(this.root.classElHash).each(function(C,B)
{if(!this.parentSubMenus.contains(C)&&this.childMenu.id!=B)
{C.hideSubMenu()
}else
{A.push(C)
}
}.bind(this));
for(i=(A.length-1);
i>=0;
i--)
{A[i].showSubMenu()
}
},hideAllSubMenus:function()
{
$clear(this.root.hideAllMenusTimeout);
this.root.hideAllMenusTimeout=(function()
{$clear(this.hideAllMenusTimeout);
this.root.classElHash.each(function(B,A)
{B.hideSubMenu()
}.bind(this))
}).bind(this).delay(this.options.hideDelay)
},cancellHideAllSubMenus:function()
{$clear(this.root.hideAllMenusTimeout)
},showSubMenu:function(A)
{if(!this.btn||!this.hidden)
{return 
}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 & 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
})
}else
{this.myEffect.start(
{"margin-top":0
})
}
}else
{if(A)
{this.myEffect.set(
{"margin-left":0
})
}else
{this.myEffect.start(
{"margin-left":0
})
}
}
}else
{if(this.options.effect==="fade")
{if(A)
{this.myEffect.set(
{opacity:this.options.opacity
})
}else
{this.myEffect.start(
{opacity:this.options.opacity
})
}
}else
{if(this.options.effect=="slide & 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
})
}else
{this.myEffect.start(
{"margin-top":0,opacity:this.options.opacity
})
}
}else
{if(A)
{if(this.options.direction.x==="right")
{this.myEffect.set(
{"margin-left":0,opacity:this.options.opacity
})
}else
{if(this.options.direction.x==="left")
{this.myEffect.set(
{"margin-left":0,opacity:this.options.opacity
})
}
}
}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
})
}else
{if(this.options.direction.x==="left")
{this.myEffect.start(
{"margin-left":0,opacity:this.options.opacity
})
}
}
}
}
}else
{this.childMenu.setStyles(
{display:"block",visibility:"visible"
})
}
}
}this.hidden=false
},positionSubMenu:function()
{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 C;
var A;
if(this.subMenuType=="initial")
{if(this.options.direction.y==="up")
{if(this.options.orientation==="vertical")
{C=this.btn.getCoordinates().bottom-this.height+this.options.tweakInitial.y
}else
{C=this.btn.getCoordinates().top-this.height+this.options.tweakInitial.y
}this.childMenu.style.top=C+"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")
{C=this.btn.getPosition().y+this.options.tweakInitial.y;
if((C+this.childMenu.getSize().y)>=$(document.body).getScrollSize().y)
{A=(C+this.childMenu.getSize().y)-$(document.body).getScrollSize().y;
C=C-A-20
}this.childMenu.style.top=C+"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)
{A=(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)-A-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 & 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 D=this.childMenu.getCoordinates().right;
var B=document.getCoordinates().width+window.getScroll().x;
if(D>B)
{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 & fade")
{this.myEffect.set(
{"margin-left":this.width,opacity:this.options.opacity
})
}
}
}
}
}
}
}
});
