(function(){function F(b,a,d){var n=b.jq,r=n.prev(),h=[0,0];if(r.length){var y=r[0].style;if(zk(r[0]).isRealVisible()){var t=n[0].style;var u={};var v={};a=["marginTop","marginBottom","marginLeft","marginRight"];for(d=a.length;0<d--;)u[a[d]]=t[a[d]],v[a[d]]=y[a[d]],t[a[d]]=y[a[d]]="0px";a=r.zk.revisedOffset();h[0]=a[0]+r.zk.offsetWidth();h[1]=a[1]+r.zk.offsetHeight()}else return h}else h[0]=d[0]+a.sumStyles("l",jq.paddings)+a.sumStyles("l",jq.borders),h[1]=d[1]+a.sumStyles("t",jq.paddings)+a.sumStyles("t",
jq.borders);a=b.revisedOffset();h[0]=a[0]-h[0];h[1]=a[1]-h[1];zk.copy(t,u);zk.copy(y,v);return[Math.max(0,h[0]),Math.max(0,h[1])]}function D(b,a,d){if(d)return d=b._hgh||(b._hgh=b.top+b.height),b=b._wdh||(b._wdh=b.left+b.width),10!=zk.ie?a.top>=d||a.left<b:Math.round(a.top)>=d||Math.round(a.left)<b;d=b._hgh||(b._hgh=b.top+b.height);b=b._wdh||(b._wdh=b.left+b.width);return 10!=zk.ie?a.left>=b||a.top<d:Math.round(a.left)>=b||Math.round(a.top)<d}function E(b){if(b){var a="_vflexsz";var d="height";var n=
"_vflex";var r="offsetHeight";var h="marginHeight";var y="_maxFlexHeight";var t="_sumFlexHeight";var u=1;var v="getContentEdgeHeight_"}else a="_hflexsz",d="width",n="_hflex",r="offsetWidth",h="marginWidth",y="_maxFlexWidth",t="_sumFlexWidth",u=0,v="getContentEdgeWidth_";return function(e,c,f,q){var p,x,l,k;if(void 0===e[a]){var g=e.firstChild;var w=zk(c);var m=0;if(null!=q)m=q;else{q={};q[d]="auto";e.setFlexSize_(q,!0);var B=q=0;if(g&&g.desktop){for(l=g;l&&l.ignoreFlexSize_(f);)l=l.nextSibling;for(;g;g=
g.nextSibling)if(!g.ignoreFlexSize_(f)&&(k=g.$n())&&(c=k.style.position,"absolute"!=c&&"fixed"!=c)){var z=zk(k);c=0;"min"==g[n]?z.isVisible()&&(c+=void 0===g[a]?zFlex.fixMinFlex(g,k,f):g[a]):(g.beforeParentMinFlex_(f),c+=e.getChildMinSize_(f,g)+z[h]());g[y]&&c>B?B=c:g[t]?q+=c:!g[y]&&l!=g&&D(x||(x=zk(l).dimension(!0)),z.dimension(!0),b)?m+=c:c>m&&(m=c)}}else if(k=c.firstChild)for(g=e.ignoreChildNodeOffset_(f),l=k;k;k=k.nextSibling){var C=3==k.nodeType;if(!C&&(c=k.style.position,"absolute"==c||"fixed"==
c))continue;z=zk(k);c=0;if(g)for(var A=k.firstChild;A;A=A.nextSibling)(p=A&&3==A.nodeType?A.nodeValue:null)?(p=z.textSize(p),p[1]>c&&(c=p[1])):(p=zk(A)).isVisible()&&(p=p[r]()+p[h](),p>c&&(c=p));else c=C?k.nodeValue?w.textSize(k.nodeValue)[u]:0:z[r]()+z[h]();C?c>m&&(m=c):(z=z.dimension(!0),D(x||(x=zk(l).dimension(!0)),z,b)?m+=c:c>m&&(m=c))}else m=w[r]();B&&(q+=B);q>m&&(m=q)}x=e.getMarginSize_(f);zk.webkit&&0>x&&(x=0);q={};w=e.$n();m=zk.isLoaded("zul.wgt")&&e.$instanceof(zul.wgt.Caption)&&0<e.nChildren?
zk(e.$n("cave"))[r]():m;q[d]=m+e[v](m);p=e.setFlexSize_(q,!0);(c={height:w.offsetHeight,width:p&&p.width||w.offsetWidth},0<=c[d])&&(e[a]=c[d]+x);(m=e.ebody)&&"min"==e[n]&&(e[a]+=zk(m)[b?"hasHScroll":"hasVScroll"]()?jq.scrollbarWidth():0);e.afterChildrenMinFlex_(f);e.parent&&"min"!=e.parent[n]&&e.parent.afterChildMinFlexChanged_(e,f)}return e[a]}}function G(){return 0}var H=E(!0),I=E();zFlex={beforeSize:function(b,a,d){var n;d&&this.clearCachedSize_();!zk.mounting&&this.isRealVisible()&&(this._hflex&&
"min"!=this._hflex&&(this.resetSize_("w"),delete this._flexFixed,(n=this.parent)&&n.afterResetChildSize_("w")),this._vflex&&"min"!=this._vflex&&(this.resetSize_("h"),delete this._flexFixed,(n=this.parent)&&n.afterResetChildSize_("h")))},onSize:function(){zFlex.fixFlex(this)},fixFlex:function(b){var a;if(b._flexFixed||!b._nvflex&&!b._nhflex)delete b._flexFixed;else if(!((void 0===b._vflex||b._vflexsz&&"min"==b._vflex)&&(void 0===b._hflex||b._hflexsz&&"min"==b._hflex)||b.ignoreFlexSize_("w")&&b.ignoreFlexSize_("h"))&&
b.parent.beforeChildrenFlex_(b)){b._flexFixed=!0;var d=!1,n=[],r=0,h=[],y=0,t=b.$n().parentNode,u=zk(t),v=b.getParentSize_(t),e=v.height,c=v.width,f=t.firstChild,q=[],p=u.hasVScroll(),x=u.hasHScroll();p&&(c-=a=jq.scrollbarWidth());for(x&&(e-=a||jq.scrollbarWidth());f&&3==f.nodeType;f=f.nextSibling);for(var l;f;f=f.nextSibling)if(3===f.nodeType)d=!0;else if(a=f.style.position,"absolute"!=a&&"fixed"!=a){var k=zk(f);if(k.isVisible(!0)){var g=k.offsetHeight(),w=0<g?k.offsetWidth():0;a=zk.Widget.$(f,{exact:1});
var m=zk.isLoaded("zul.mesh");if(!(a&&m&&a.$instanceof(zul.mesh.Auxheader))){0==w&&a&&m&&a.$instanceof(zul.mesh.HeaderWidget)&&(w=(w=a.$n("hdfaker"))?zk.parseInt(w.style.width)||w.offsetWidth:0);d&&(l||(l=u.revisedOffset()),d=F(k,u,l),a&&a.isExcludedHflex_()||(c-=d[0]),a&&a.isExcludedVflex_()||(e-=d[1]));if(a&&a._nhflex&&a.isVisible())a!==b&&(a._flexFixed=!0),"min"==a._hflex?c-=zFlex.fixMinFlex(a,f,"w"):(h.push(a),y+=a._nhflex);else if(!(a||zk.isLoaded("zul.wnd")&&b.$instanceof(zul.wnd.Panelchildren))||
a&&!a.isExcludedHflex_())c-=w,c-=k.marginWidth();a&&a._nvflex&&a.isVisible()?(a!==b&&(a._flexFixed=!0),"min"==a._vflex?e-=zFlex.fixMinFlex(a,f,"h"):(n.push(a),q.push(a),r+=a._nvflex)):a&&a.isExcludedVflex_()||(e-=g,e-=k.marginHeight());d=!1}}}f=function(a,b,d){for(var c,e=a.length-1;0<e;--e){c=a.shift();var f=c.isExcludedVflex_()?b:c._nvflex*b/r|0;c.setFlexSize_({height:f});c._vflexsz=f;c.isExcludedVflex_()||(d-=f)}a.length&&(c=a.shift(),c.setFlexSize_({height:d}),c._vflexsz=d)};l=e=Math.max(e,0);
f(n,e,l);n=b.getParentSize_(t);n.width>v.width&&(c+=n.width-v.width);l=c=Math.max(c,0);for(t=h.length-1;0<t;--t)a=h.shift(),d=a.isExcludedHflex_()?c:a._nhflex*c/y|0,a.setFlexSize_({width:d}),a._hflexsz=d,a.isExcludedHflex_()||(l-=d);h.length&&(a=h.shift(),a.setFlexSize_({width:l}),a._hflexsz=l);n.height>v.height&&(e+=n.height-v.height,l=e=Math.max(e,0),f(q,e,l));b.parent.afterChildrenFlex_(b);b._flexFixed=!1;u.hasVScroll()==p&&u.hasHScroll()==x||zFlex.fixFlex(b)}},onFitSize:function(){var b=this.$n();
b&&zk(b).isVisible()&&("min"==this._hflex&&void 0===this._hflexsz&&this.isRealVisible()&&!this.ignoreFlexSize_("w")&&zFlex.fixMinFlex(this,b,"w"),"min"==this._vflex&&void 0===this._vflexsz&&this.isRealVisible()&&!this.ignoreFlexSize_("h")&&zFlex.fixMinFlex(this,b,"h"))},fixMinFlex:function(b,a,d){return("h"==d?H:"w"==d?I:G)(b,a,d,b.beforeMinFlex_(d))}}})();
