YUI.add("dd-constrain",function(n,t){var i,c="dragNode",r="offsetHeight",a="offsetWidth",h="host",g="tickXArray",o="tickYArray",l=n.DD.DDM,u="top",d="right",f="bottom",_="left",s="view",e="drag:tickAlignX",k="drag:tickAlignY",v=function(){this._lazyAddAttrs=!1,v.superclass.constructor.apply(this,arguments)};v.NAME="ddConstrained",v.NS="con",v.ATTRS={host:{},stickX:{value:!1},stickY:{value:!1},tickX:{value:!1},tickY:{value:!1},tickXArray:{value:!1},tickYArray:{value:!1},gutter:{value:"0",setter:function(t){return n.DD.DDM.cssSizestoObject(t)}},constrain:{value:s,setter:function(t){var i=n.one(t);return t=i?i:t}},constrain2region:{setter:function(t){return this.set("constrain",t)}},constrain2node:{setter:function(t){return this.set("constrain",n.one(t))}},constrain2view:{setter:function(){return this.set("constrain",s)}},cacheRegion:{value:!0}},i={_lastTickXFired:null,_lastTickYFired:null,initializer:function(){this._createEvents(),this._eventHandles=[this.get(h).on("drag:end",n.bind(this._handleEnd,this)),this.get(h).on("drag:start",n.bind(this._handleStart,this)),this.get(h).after("drag:align",n.bind(this.align,this)),this.get(h).after("drag:drag",n.bind(this.drag,this))]},destructor:function(){n.Array.each(this._eventHandles,function(t){t.detach()}),this._eventHandles.length=0},_createEvents:function(){n.Array.each([e,k],function(t){this.publish(t,{type:t,emitFacade:!0,bubbles:!0,queuable:!1,prefix:"drag"})},this)},_handleEnd:function(){this._lastTickYFired=null,this._lastTickXFired=null},_handleStart:function(){this.resetCache()},_regionCache:null,_cacheRegion:function(){this._regionCache=this.get("constrain").get("region")},resetCache:function(){this._regionCache=null},_getConstraint:function(){var e,t=this.get("constrain"),i=this.get("gutter");return t&&(t instanceof n.Node?(this._regionCache||(this._eventHandles.push(n.on("resize",n.bind(this._cacheRegion,this),n.config.win)),this._cacheRegion()),e=n.clone(this._regionCache),this.get("cacheRegion")||this.resetCache()):n.Lang.isObject(t)&&(e=n.clone(t))),(t=t&&e?t:s)===s&&(e=this.get(h).get(c).get("viewportRegion")),n.Object.each(i,function(t,i){i===d||i===f?e[i]-=t:e[i]+=t}),e},getRegion:function(t){var i={},e=this.get(h),i=this._getConstraint();return t&&(t=e.get(c).get(r),e=e.get(c).get(a),i[d]=i[d]-e,i[f]=i[f]-t),i},_checkRegion:function(t){var i=t,e=this.getRegion(),n=this.get(h),s=n.get(c).get(r),n=n.get(c).get(a);return i[1]>e[f]-s&&(t[1]=e[f]-s),e[u]>i[1]&&(t[1]=e[u]),i[0]>e[d]-n&&(t[0]=e[d]-n),e[_]>i[0]&&(t[0]=e[_]),t},inRegion:function(t){t=t||this.get(h).get(c).getXY();var i=this._checkRegion([t[0],t[1]]),e=!1;return e=t[0]===i[0]&&t[1]===i[1]?!0:e},align:function(){var t=this.get(h),i=[t.actXY[0],t.actXY[1]],e=this.getRegion(!0);this.get("stickX")&&(i[1]=t.startXY[1]-t.deltaXY[1]),this.get("stickY")&&(i[0]=t.startXY[0]-t.deltaXY[0]),e&&(i=this._checkRegion(i)),i=this._checkTicks(i,e),t.actXY=i},drag:function(){var t=this.get(h),i=this.get("tickX"),e=this.get("tickY"),t=[t.actXY[0],t.actXY[1]];(n.Lang.isNumber(i)||this.get(g))&&this._lastTickXFired!==t[0]&&(this._tickAlignX(),this._lastTickXFired=t[0]),(n.Lang.isNumber(e)||this.get(o))&&this._lastTickYFired!==t[1]&&(this._tickAlignY(),this._lastTickYFired=t[1])},_checkTicks:function(t,i){var e=this.get(h),n=e.startXY[0]-e.deltaXY[0],e=e.startXY[1]-e.deltaXY[1],s=this.get("tickX"),c=this.get("tickY");return s&&!this.get(g)&&(t[0]=l._calcTicks(t[0],n,s,i[_],i[d])),c&&!this.get(o)&&(t[1]=l._calcTicks(t[1],e,c,i[u],i[f])),this.get(g)&&(t[0]=l._calcTickArray(t[0],this.get(g),i[_],i[d])),this.get(o)&&(t[1]=l._calcTickArray(t[1],this.get(o),i[u],i[f])),t},_tickAlignX:function(){this.fire(e)},_tickAlignY:function(){this.fire(k)}},n.namespace("Plugin"),n.extend(v,n.Base,i),n.Plugin.DDConstrained=v,n.mix(l,{_calcTicks:function(t,i,e,n,s){var c=(t-i)/e,r=Math.floor(c),a=Math.ceil(c);return 0===r&&0===a||r<=c&&c<=a&&(t=i+e*r,n&&s&&s<(t=t<n?i+e*(r+1):t)&&(t=i+e*(r-1))),t},_calcTickArray:function(t,i,e,n){var s,c=0,r=i.length;if(!i||0===i.length)return t;if(i[0]>=t)return i[0];for(c=0;c<r;c++)if(i[s=c+1]&&i[s]>=t)return s=t-i[c]<i[s]-t?i[c]:i[s],s=e&&n&&n<s?i[c]||i[r-1]:s;return i[i.length-1]}})},"patched-v3.18.4",{requires:["dd-drag"]});