define(["Ti/_/Layouts/Base","Ti/_/declare","Ti/UI","Ti/_/lang"],function(e,t,i,d){var a=d.isDef,h=Math.round;return t("Ti._.Layouts.Vertical",e,{_doLayout:function(e,t,d,a,r){var o,n,_,s,u,x,g,f,l,m,p,W,b,c,L,N={width:0,height:0},y=e._children,w=0,I="px",H=[],S=0,T=y.length,C=this._measureNode;for(w=0;T>w;w++)o=e._children[w],o._alive&&o.domNode?(o._measuredRunningHeight=S,o._markedForLayout&&((o._preLayout&&o._preLayout(t,d,a,r)||o._needsMeasuring)&&C(o,o,o._layoutCoefficients,this),n=o._layoutCoefficients,_=n.width,s=n.height,u=n.sandboxWidth,x=n.sandboxHeight,f=n.left,g=n.top,m=_.x1*t+_.x2,p=s.x1*d+s.x2*(d-S)+s.x3,l=o._getContentSize?o._getContentSize(m,p):o._layout._doLayout(o,isNaN(m)?t:m-o._borderLeftWidth-o._borderRightWidth,isNaN(p)?d:p-o._borderTopWidth-o._borderBottomWidth,isNaN(m),isNaN(p)),isNaN(m)&&(m=l.width+o._borderLeftWidth+o._borderRightWidth),isNaN(p)&&(p=l.height+o._borderTopWidth+o._borderBottomWidth),o._measuredWidth=m,o._measuredHeight=p,a&&0!==f.x1?H.push(o):(c=o._measuredLeft=f.x1*t+f.x2*m+f.x3,b=o._measuredSandboxWidth=u.x1*t+u.x2+m+(isNaN(c)?0:c)),o._measuredTop=g.x1*d+g.x2+S,W=o._measuredSandboxHeight=x.x1*d+x.x2+p),o._measuredSandboxWidth>N.width&&(N.width=o._measuredSandboxWidth),S=N.height+=o._measuredSandboxHeight):this.handleInvalidState(o,e);for(T=H.length,w=0;T>w;w++)o=H[w],u=o._layoutCoefficients.sandboxWidth,b=o._measuredSandboxWidth=u.x1*t+u.x2+o._measuredWidth,b>N.width&&(N.width=b);for(w=0;T>w;w++)o=H[w],f=o._layoutCoefficients.left,u=o._layoutCoefficients.sandboxWidth,m=o._measuredWidth,b=o._measuredSandboxWidth,b>N.width&&(N.width=b),c=o._measuredLeft=f.x1*N.width+f.x2*m+f.x3,o._measuredSandboxWidth+=isNaN(c)?0:c;for(T=y.length,w=0;T>w;w++)o=y[w],o._markedForLayout&&(i._elementLayoutCount++,o=y[w],L=o.domNode.style,L.zIndex=o.zIndex,L.left=h(o._measuredLeft)+I,L.top=h(o._measuredTop)+I,L.width=h(o._measuredWidth-o._borderLeftWidth-o._borderRightWidth)+I,L.height=h(o._measuredHeight-o._borderTopWidth-o._borderBottomWidth)+I,o._markedForLayout=!1,o.fireEvent("postlayout"));return this._computedSize=N},_getWidth:function(e,t){return!a(t)&&a(e.left)+a(e.center&&e.center.x)+a(e.right)<2&&(t=e._defaultWidth),t===i.INHERIT?e._parent._parent?e._parent._parent._layout._getWidth(e._parent,e._parent.width)===i.SIZE?i.SIZE:i.FILL:i.FILL:t},_getHeight:function(e,t){return!a(t)&&(t=e._defaultHeight),t===i.INHERIT?e._parent._parent?e._parent._parent._layout._getHeight(e._parent,e._parent.height)===i.SIZE?i.SIZE:i.FILL:i.FILL:t},_isDependentOnParent:function(e){var t=e._layoutCoefficients;return!isNaN(t.width.x1)&&0!==t.width.x1||!isNaN(t.height.x1)&&0!==t.height.x1||!isNaN(t.height.x2)&&0!==t.height.x2||0!==t.sandboxWidth.x1||0!==t.sandboxHeight.x1||0!==t.left.x1||0!==t.top.x1},_doAnimationLayout:function(e,t){var i=e._parent._measuredWidth,d=e._parent._measuredHeight,a=e._measuredRunningHeight,h=t.width.x1*i+t.width.x2;return{width:h,height:t.height.x1*d+t.height.x2*(d-a)+t.height.x3,left:t.left.x1*i+t.left.x2*h+t.left.x3,top:t.top.x1*d+t.top.x2+a}},_measureNode:function(e,t,d,a){e._needsMeasuring=!1;var h,r,o,n=a.getValueType,_=a.computeValue,s=a._getWidth(e,t.width),u=n(s),x=_(s,u),g=a._getHeight(e,t.height),f=n(g),l=_(g,f),m=t.left,p=n(m),W=_(m,p),b=t.center&&t.center.x,c=n(b),L=_(b,c),N=t.right,y=n(N),w=_(N,y),I=t.top,H=n(I),S=_(I,H),T=t.bottom,C=n(T),E=_(T,C),F=d.width,v=d.height,z=d.sandboxWidth,R=d.sandboxHeight,Z=d.left,k=d.top;if(h=r=0,u===i.SIZE?h=r=0/0:u===i.FILL?(h=1,"%"===p?h-=W:"#"===p?r=-W:"%"===y?h-=w:"#"===y&&(r=-w)):"%"===u?h=x:"#"===u?r=x:"%"===p?"%"===c?h=2*(L-W):"#"===c?(h=-2*W,r=2*L):"%"===y?h=1-W-w:"#"===y&&(h=1-W,r=-w):"#"===p?"%"===c?(h=2*L,r=-2*W):"#"===c?r=2*(L-W):"%"===y?(h=1-w,r=-W):"#"===y&&(h=1,r=-w-W):"%"===c?"%"===y?h=2*(w-L):"#"===y&&(h=-2*L,r=2*w):"#"===c&&("%"===y?(h=2*w,r=-2*L):"#"===y&&(r=2*(w-L))),F.x1=h,F.x2=r,z.x1="%"===y?w:0,z.x2="#"===y?w:0,h=r=o=0,f===i.SIZE?h=r=o=0/0:f===i.FILL?(r=1,"%"===H&&(h=-S),"#"===H&&(o=-S),"%"===C&&(h=-E),"#"===C&&(o=-E)):"%"===f?h=l:"#"===f&&(o=l),v.x1=h,v.x2=r,v.x3=o,h=r=0,"%"===H&&(h=S),"#"===H&&(r=S),"%"===C&&(h+=E),"#"===C&&(r+=E),R.x1=h,R.x2=r,h=r=o=0,"%"===p)h=W;else if("#"===p)o=W;else if("%"===c)h=L,r=-.5;else if("#"===c)r=-.5,o=L;else if("%"===y)h=1-w,r=-1;else if("#"===y)h=1,r=-1,o=-w;else switch(a._defaultHorizontalAlignment){case"center":h=.5,r=-.5;break;case"end":h=1,r=-1}Z.x1=h,Z.x2=r,Z.x3=o,k.x1="%"===H?S:0,k.x2="#"===H?S:0},_defaultHorizontalAlignment:"center",_defaultVerticalAlignment:"start"})});