(function(){function h(a){a=a.parent;return a.$instanceof(zul.menu.Menu)?a:null}function p(a){for(;a&&(a=h(a));a=a.parent)if(a.isTopmost())return a;return null}function r(a,b){var d=-1,c=zul.menu.Menubar;for(a=a.firstChild;a&&(c._isActiveItem(a)&&d++,a!=b);a=a.nextSibling);return d}function t(a){var b=a.menupopup;b&&(b._shallClose=!1,b.isOpen()||(a.focus(),b.open(null,null,null,{focusFirst:!0,sendOnOpen:!0,disableMask:!0})));a.$class._addActive(a);zWatch.fire("onFloatUp",a)}zul.menu.Menupopup=zk.$extends(zul.wgt.Popup,
{_curIndex:-1,_keepOpen:!1,zsync:function(){this.$supers("zsync",arguments);this._shadow||(this._shadow=new zk.eff.Shadow(this.$n()));this._shadow.sync()},_hideShadow:function(){this._shadow&&this._shadow.hide()},_syncPos:function(){var a=h(this);if(a){var b=this.$n(),d=a.$n(),c=jq(b),e=jq(d),m=c.offset().left,f=e.offset().left;c=c.outerWidth();e=e.outerWidth();var k=a.parent,l=a.getMenubar();l=l?l.getOrient():"";var q=!1,g=-1;a.isTopmost()&&"horizontal"==l&&b&&(b.style.top=jq.px0(zk.parseInt(b.style.top)));
for(;k&&!k.$instanceof(zul.menu.Menupopup);)k=k.parent;if(k)if(k._reverseDirection){a=f-c;var u=0>a;a=u?f+e:a;g=a+c;var n=jq.innerX()+jq.innerWidth();g=g>n?n-c:a;this._reverseDirection=!u}else q=!0;!k&&zk(b).isOverlapped(d,1)&&(5<f+e-m&&"vertical"!=l||m<f+e/2&&"vertical"==l)&&(q=!0);q&&(a=f+e,g=a+c,n=jq.innerX()+jq.innerWidth(),d=g>n,g=Math.max(d?f-c:a,0),this._reverseDirection=d);if(0<=g&&(b.style.left=jq.px0(g),zk.ie))this.onShow()}},close:function(){this.isOpen()&&zul.menu._nOpen--;this.$supers("close",
arguments);jq(this.$n()).hide();this._hideShadow();var a;(a=h(this))&&a.isTopmost()&&jq(a.$n()).removeClass(a.$s("selected"));this.removeActive_();this.$class._rmActive(this)},open:function(a,b,d,c){this.isOpen()||zul.menu._nOpen++;var e;(e=h(this))&&!b&&(a=e.getAnchor_(),d||(d=e.isTopmost()?"vertical"==e.parent.getOrient()?"end_before":"after_start":"end_before"));this.$super("open",a,b,d,c||{sendOnOpen:!0,disableMask:!0});this._syncPos();c&&c.focusFirst&&this.doKeyDown_(new zk.Event(this,"onKeyDown",
{keyCode:40,key:"ArrowDown"}))},shallStackup_:function(){return!1},setTopmost:function(){this.$supers("setTopmost",arguments);this.zsync()},onFloatUp:function(a,b){if(this.isVisible()){var d=this._openInfo;this._shallToggle&&d&&b&&(void 0===b.triggerByClick||d[3].which==b.triggerByClick&&zUtl.isAncestor(this._openInfo[0],a.origin))||this._doFloatUp(a)}},_doFloatUp:function(a){if(this.isVisible()){a=a.origin;if(this.parent.menupopup!=this||this.parent.isTopmost()||this.parent.$class._isActive(this.parent)){for(var b,
d=a;d;d=d.parent){if(d==this||d.menupopup==this&&!this._shallClose){b||this.setTopmost();return}b=b||d.isFloating_()}if(a&&a.ignoreDescendantFloatUp_(this))for(d=this;d=d.parent;){if(d==a){if(this._shallClose)break;b||this.setTopmost();return}b=b||d.isFloating_()}}this.close({sendOnOpen:!0})}},onShow:function(){this.zsync();var a=this.getAnchor_();a&&zk(a).isRealVisible()&&(a.focus(),zk.currentFocus=this);zk(this).redoCSS(-1,{fixFontIcon:!0})},onHide:function(){this.isOpen()&&this.close();this._hideShadow()},
bind_:function(){this.$supers(zul.menu.Menupopup,"bind_",arguments);zWatch.listen({onHide:this,onResponse:this});var a=this.$n();a.addEventListener("mouseenter",this.proxy(this._doMouseEnter));a.addEventListener("mouseleave",this.proxy(this._doMouseLeave));if(!zk.css3)jq.onzsync(this)},unbind_:function(){this.isOpen()&&this.close();this._shadow&&this._shadow.destroy();zk.css3||jq.unzsync(this);this._shadow=null;zWatch.unlisten({onHide:this,onResponse:this});var a=this.$n();a.removeEventListener("mouseleave",
this.proxy(this._doMouseLeave));a.removeEventListener("mouseenter",this.proxy(this._doMouseEnter));this.$supers(zul.menu.Menupopup,"unbind_",arguments)},onResponse:function(){this.isOpen()&&(this.zsync(),this.$supers("onResponse",arguments),this._syncPos())},doKeyDown_:function(a){var b=this._currentChild(),d=a.keyCode;switch(d){case 38:case 40:b&&b.$class._rmActive(b);if(38==d)a:{var c=b;b=zul.menu.Menubar;if(c)for(;c=c.previousSibling;)if(b._isActiveItem(c)){this._curIndex--;break a}this._curIndex=
-1;for(var e=this.firstChild;e;e=e.nextSibling)b._isActiveItem(e)&&(c=e,this._curIndex++)}else a:{c=zul.menu.Menubar;if(b)for(;b=b.nextSibling;)if(c._isActiveItem(b)){this._curIndex++;c=b;break a}for(b=this.firstChild;b;b=b.nextSibling)if(c._isActiveItem(b)){this._curIndex=0;c=b;break a}c=void 0}(b=c)&&b.$class._addActive(b);break;case 37:if(b&&b.$instanceof(zul.menu.Menu)&&b._contentHandler&&b._contentHandler.isOpen())b._contentHandler.onHide();else if((c=h(this))&&!c.isTopmost()){if(this.close(),
c.$class._addActive(c),b=c.parent)b.focus(),b._curIndex=r(b,c)}else(c=p(this))&&(c=c._getPrevVisibleMenu())?t(c):(c=this._fakeParent,this.close(),c&&c.focus());break;case 39:b&&b.$instanceof(zul.menu.Menu)&&!b.isDisabled()?b._togglePopup(!0):(c=p(this))&&(c=c._getNextVisibleMenu())&&t(c);break;case 13:if(b&&b.$instanceof(zul.menu.Menuitem))b.doClick_(new zk.Event(b,"onClick",{})),zWatch.fire("onFloatUp",b),this.close({sendOnOpen:!0});else if(b&&b.$instanceof(zul.menu.Menu))b._togglePopup(!0);else if(c=
h(this))this.close(),c.isTopmost()?c.focus():(c.$class._addActive(c),(b=c.parent)&&b.focus());break;case 27:if(c=h(this))if(c.isTopmost())this.close(),c.focus();else if((b=c._contentHandler)&&b.isOpen())b.onHide();else this.close(),c.$class._addActive(c),(b=c.parent)&&b.focus();else c=this._fakeParent,this.close({sendOnOpen:!0}),c&&c.focus();break;case 9:(c=p(this))&&c.focus_(void 0,11>zk.ie),this.close()}9!=d&&27!=d&&a.stop();this.$supers("doKeyDown_",arguments)},doClick_:function(a){a.domTarget==
this.getAnchor_()&&a.stop();this.$supers("doClick_",arguments)},getMenubar:function(){for(var a=this.parent;a;){if(a.$instanceof(zul.menu.Menubar))return a;if(a.$instanceof(zul.menu.Menu))return a.getMenubar();break}return null},_doMouseEnter:function(a){if(a=this.getMenubar())a._bOver=!0;this._shallClose=!1},_doMouseLeave:function(a){if(a=this.getMenubar())a._bOver=!1,a._autodrop&&a._closeOnOut();zul.menu.Menu.isInstance(this._currentChild())||this.removeActive_()},setActive:function(a){if(0<=a&&
a<this.nChildren){for(var b=-1,d=zul.menu.Menubar,c=this.firstChild,e=0,m=0;c;c=c.nextSibling,e++){var f=d._isActiveItem(c);if(a===e&&f){b=m;break}f&&m++}0<=b&&(this.removeActive_(),this._curIndex=b,(a=this.getChildAt(a))&&a.$class._addActive(a))}},getAnchor_:function(){return this.$n("a")},focus_:function(a){return zk(this.getAnchor_()).focus(a)?!0:this.$supers("focus_",arguments)},addActive_:function(a){this._curIndex=r(this,a)},removeActive_:function(){var a=this._currentChild();a&&(a.$class._rmActive(a),
this._curIndex=-1)},_currentChild:function(){var a=this._curIndex,b=zul.menu.Menubar;if(0<=a)for(var d=this.firstChild,c=0;d;d=d.nextSibling)if(b._isActiveItem(d)&&c++==a)return d;return null}},{_rmActive:function(a){a.parent.$instanceof(zul.menu.Menu)&&a.parent.$class._rmActive(a.parent)}});zul.menu._nOpen=0})();
