zul.box.Layout=zk.$extends(zk.Widget,{_spacing:"5px",$define:{spacing:function(){var b=this.$n(),a=this.isVertical_(),c=this._spacing;b&&jq(b).children("div:not(:last-child)").css("padding-"+(a?"bottom":"right"),c&&"auto"!=c?c:"")}},_chdextr:function(b){return b.$n("chdex")||b.$n()},insertChildHTML_:function(b,a,c){if(a)jq(this._chdextr(a)).before(this.encloseChildHTML_(b));else{a=jq(this.$n());var d=this._spacing;a.children("div:last-child").css("padding-"+(this.isVertical_()?"bottom":"right"),d&&
"auto"!=d?d:"");a.append(this.encloseChildHTML_(b))}b.bind(c)},bind_:function(){this.$supers(zul.box.Layout,"bind_",arguments);zWatch.listen({onResponse:this})},unbind_:function(){zWatch.unlisten({onResponse:this});this.$supers(zul.box.Layout,"unbind_",arguments)},syncSize:function(){this._shallSize=!1;if(this.desktop)for(var b=this.firstChild;b;b=b.nextSibling)if(b._nvflex||b._nhflex){zUtl.fireSized(this);break}},onResponse:function(){this._shallSize&&this.syncSize()},onChildVisible_:function(b){this.$supers("onChildVisible_",
arguments);if(this.desktop){var a=b.$n("chdex");this._shallSize=!0;a&&(a.style.display=b.isVisible()?"":"none")}},onChildAdded_:function(b){this.$supers("onChildAdded_",arguments);if(this.desktop){var a=b.$n("chdex");this._shallSize=!0;a&&(a.style.display=b.isVisible()?"":"none")}},onChildRemoved_:function(){this.$supers("onChildRemoved_",arguments);this.desktop&&(this._shallSize=!0)},removeChildHTML_:function(b){this.$supers("removeChildHTML_",arguments);jq(b.uuid+"-chdex",zk).remove();"auto"!=this._spacing&&
this.lastChild==b&&jq(this.$n()).children("div:last-child").css("padding-"+(this.isVertical_()?"bottom":"right"),"")},encloseChildHTML_:function(b,a){var c=new zk.Buffer,d=this.isVertical_(),p=this._spacing;c.push('<div id="'+b.uuid+'-chdex" class="'+this.$s("inner")+'"');if(p&&"auto"!=p){c.push(' style="',b.isVisible()?"":"display:none;");var n=b.nextSibling;!n||n.$instanceof(zul.wgt.Popup)||b.$instanceof(zul.wgt.Popup)||c.push("padding-",d?"bottom:":"right:",p);c.push('"')}c.push(">");b.redraw(c);
c.push("</div>");if(!a)return c.join("");a.push(c.join(""))},isVertical_:zk.$void,_resetBoxSize:function(b){for(var a,c=this.firstChild;c;c=c.nextSibling){var d=c.$n("chdex");d&&(b&&c._nvflex&&"min"!=c.getVflex()&&((a=c.$n())&&(a.scrollTop||a.scrollLeft)||c.setFlexSize_({height:"",width:""}),d&&(d.style.height="")),!b&&c._nhflex&&"min"!=c.getHflex()&&((a=c.$n())&&(a.scrollTop||a.scrollLeft)||c.setFlexSize_({height:"",width:""}),d&&(d.style.width="")))}},afterResetChildSize_:function(b){for(var a=
this.firstChild;a;a=a.nextSibling){var c=a.$n("chdex");c&&("h"==b&&(c.style.height=""),"w"==b&&(c.style.width=""),c.style.minWidth="1px")}},resetSize_:function(b){this.$supers(zul.box.Layout,"resetSize_",arguments);for(var a=this.isVertical_(),c=this.firstChild;c;c=c.nextSibling)if(a?c._nvflex&&"min"!=c.getVflex():c._nhflex&&"min"!=c.getHflex()){var d=c.$n("chdex");d&&("h"==b&&(d.style.height=""),"w"==b&&(d.style.width=""))}},getChildMinSize_:function(b,a){var c=a.$n();if("w"==b&&a._hflex&&this.isVertical_()){b=
a.nextSibling;for(a=0;b;b=b.nextSibling)b._hflex||(c=zjq.minWidth(b.$n()),a=c>a?c:a);return a}return"h"==b?zk(c.parentNode).contentHeight():zjq.minWidth(c)},getContentEdgeHeight_:function(){for(var b=0,a=this.firstChild;a;a=a.nextSibling)b+=zk(a.$n("chdex")).paddingHeight();return b},getContentEdgeWidth_:function(){for(var b=0,a=this.firstChild;a;a=a.nextSibling)b+=zk(a.$n("chdex")).paddingWidth();return b},beforeChildrenFlex_:function(b){var a;this._shallSize=!1;b._flexFixed=!0;var c=this.isVertical_(),
d=[],p=c?0:1,n=[],r=c?1:0,k=this.$n(),l=b.getParentSize_(k);var e=zk(k);k=l.height;l=l.width;var f=this.firstChild;zk.mounting||this._resetBoxSize(c);e.hasVScroll()&&(l-=a=jq.scrollbarWidth());for(e.hasHScroll()&&(k-=a||jq.scrollbarWidth());f;f=f.nextSibling){var h;if("nodom"==f.getMold()){if(a=f.firstChild)a=a.$n().parentNode,e=zk(a),c?k-=e.offsetHeightDoubleValue()+e.marginHeight():l-=a.offsetWidth+e.marginWidth()}else if(f.isVisible()&&!(h=zk(f)).hasVParent()){a=f;var m=a.$n();e=m.parentNode;var g=
zk(e);if(f&&f._nvflex)if(a!==b&&(a._flexFixed=!0),"min"==a._vflex){a.fixMinFlex_(m,"h");var q=m.offsetHeight+h.marginHeight()+g.padBorderHeight();e.style.height=jq.px0(q);c&&(k-=e.offsetHeight+g.marginHeight())}else d.push(a),c&&(p+=a._nvflex,k-=g.marginHeight());else c&&(k-=g.offsetHeightDoubleValue()+g.marginHeight());a&&a._nhflex?(a!==b&&(a._flexFixed=!0),"min"==a._hflex?(a.fixMinFlex_(m,"w"),a=m.offsetWidth+h.marginWidth()+g.padBorderWidth(),e.style.width=jq.px0(g.revisedWidth(a)),c||(l-=e.offsetWidth+
g.marginWidth())):(n.push(a),c||(r+=a._nhflex,l-=g.marginWidth()))):c||(l-=e.offsetWidth+g.marginWidth())}}for(h=0<k?k:0;1<d.length;)a=d.shift(),m=(c?a._nvflex*k/p:k)|0,f=a.$n().offsetTop,q=m-(11>zk.ie&&0<f?2*f:0),g=a.$n("chdex"),e=zk(g).padBorderHeight(),f=!a.$n().style.height,a.setFlexSize_({height:q-e}),a._vflexsz=m-e,g.style.height=jq.px0(m),c&&(h-=m),!f&&c&&a!==b&&zUtl.fireSized(a);d.length&&(a=d.shift(),f=a.$n().offsetTop,q=h-(11>zk.ie&&0<f?2*f:0),g=a.$n("chdex"),e=zk(g).padBorderHeight(),f=
!a.$n().style.height,a.setFlexSize_({height:q-e}),a._vflexsz=h-e,g.style.height=jq.px0(h),!f&&c&&a!==b&&zUtl.fireSized(a));for(h=0<l?l:0;1<n.length;)a=n.shift(),d=(c?l:a._nhflex*l/r)|0,g=a.$n("chdex"),e=zk(g).padBorderWidth(),f=!a.$n().style.width,a.setFlexSize_({width:d-e}),a._hflexsz=d-e,g.style.width=jq.px0(d),c||(h-=d),f||c||a===b||zUtl.fireSized(a);n.length&&(a=n.shift(),g=a.$n("chdex"),e=zk(g).padBorderWidth(),f=!a.$n().style.width,a.setFlexSize_({width:h-e}),a._hflexsz=h-e,g.style.width=jq.px0(h),
f||c||a===b||zUtl.fireSized(a));b.parent.afterChildrenFlex_(b);return b._flexFixed=!1},afterChildrenMinFlex_:function(b){var a=this.$n();if("h"==b){if(this.isVertical_()){var c=0;for(b=a.firstChild;b;b=b.nextSibling){var d=b.firstChild;d.style.height?(d=d.offsetHeight+zk(b).padBorderHeight()+zk(d).marginHeight(),b.style.height=jq.px0(d),c+=d):c+=b.offsetHeight}}else for(c=0,b=a.firstChild;b;b=b.nextSibling)d=b.offsetHeight+zk(b.firstChild).marginHeight(),d>c&&(c=d);a.style.height=jq.px0(c)}else{if(this.isVertical_())for(c=
0,b=a.firstChild;b;b=b.nextSibling)d=b.firstChild.offsetWidth+zk(b.firstChild).marginWidth(),d>c&&(c=d);else for(c=0,b=a.firstChild;b;b=b.nextSibling)d=b.firstChild,d.style.width?(d=d.offsetWidth+zk(b).padBorderWidth()+zk(d).marginWidth(),b.style.width=jq.px0(d),c+=d):c+=b.offsetWidth;8<zk.ie&&this._hflexsz&&(c=Math.max(this._hflexsz,c));a.style.width=jq.px0(c)}}});
