(function(C){C.widget("ui.resizable",C.extend({},C.ui.mouse,{_init:function(){var E=this,I=this.options;this.element.addClass("ui-resizable");C.extend(this,{_aspectRatio:!!(I.aspectRatio),aspectRatio:I.aspectRatio,originalElement:this.element,_proportionallyResizeElements:[],_helper:I.helper||I.ghost||I.animate?I.helper||"ui-resizable-helper":null});if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)){if(/relative/.test(this.element.css("position"))&&C.browser.opera){this.element.css({position:"relative",top:"auto",left:"auto"})}this.element.wrap(C("<div class=\"ui-wrapper\" style=\"overflow: hidden;\"></div>").css({position:this.element.css("position"),width:this.element.outerWidth(),height:this.element.outerHeight(),top:this.element.css("top"),left:this.element.css("left")}));this.element=this.element.parent().data("resizable",this.element.data("resizable"));this.elementIsWrapper=true;this.element.css({marginLeft:this.originalElement.css("marginLeft"),marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom")});this.originalElement.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0});this.originalResizeStyle=this.originalElement.css("resize");this.originalElement.css("resize","none");this._proportionallyResizeElements.push(this.originalElement.css({position:"static",zoom:1,display:"block"}));this.originalElement.css({margin:this.originalElement.css("margin")});this._proportionallyResize()}this.handles=I.handles||(!C(".ui-resizable-handle",this.element).length?"e,s,se":{n:".ui-resizable-n",e:".ui-resizable-e",s:".ui-resizable-s",w:".ui-resizable-w",se:".ui-resizable-se",sw:".ui-resizable-sw",ne:".ui-resizable-ne",nw:".ui-resizable-nw"});if(this.handles.constructor==String){if(this.handles=="all"){this.handles="n,e,s,w,se,sw,ne,nw"}var J=this.handles.split(",");this.handles={};for(var F=0;F<J.length;F++){var H=C.trim(J[F]),D="ui-resizable-"+H;var G=C("<div class=\"ui-resizable-handle "+D+"\"></div>");if(/sw|se|ne|nw/.test(H)){G.css({zIndex:++I.zIndex})}if("se"==H){G.addClass("ui-icon ui-icon-gripsmall-diagonal-se")}this.handles[H]=".ui-resizable-"+H;this.element.append(G)}}this._renderAxis=function(O){O=O||this.element;for(var L in this.handles){if(this.handles[L].constructor==String){this.handles[L]=C(this.handles[L],this.element).show()}if(this.elementIsWrapper&&this.originalElement[0].nodeName.match(/textarea|input|select|button/i)){var M=C(this.handles[L],this.element),N=0;N=/sw|ne|nw|se|n|s/.test(L)?M.outerHeight():M.outerWidth();var K=["padding",/ne|nw|n/.test(L)?"Top":/se|sw|s/.test(L)?"Bottom":/^e$/.test(L)?"Right":"Left"].join("");O.css(K,N);this._proportionallyResize()}if(!C(this.handles[L]).length){continue}}};this._renderAxis(this.element);this._handles=C(".ui-resizable-handle",this.element).disableSelection();this._handles.mouseover(function(){if(!E.resizing){if(this.className){var K=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i)}E.axis=K&&K[1]?K[1]:"se"}});if(I.autoHide){this._handles.hide();C(this.element).addClass("ui-resizable-autohide").hover(function(){C(this).removeClass("ui-resizable-autohide");E._handles.show()},function(){if(!E.resizing){C(this).addClass("ui-resizable-autohide");E._handles.hide()}})}this._mouseInit()},destroy:function(){this._mouseDestroy();var D=function(F){C(F).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing").removeData("resizable").unbind(".resizable").find(".ui-resizable-handle").remove()};if(this.elementIsWrapper){D(this.element);var E=this.element;E.parent().append(this.originalElement.css({position:E.css("position"),width:E.outerWidth(),height:E.outerHeight(),top:E.css("top"),left:E.css("left")})).end().remove()}this.originalElement.css("resize",this.originalResizeStyle);D(this.originalElement)},_mouseCapture:function(E){var F=false;for(var D in this.handles){if(C(this.handles[D])[0]==E.target){F=true}}return this.options.disabled||!!F},_mouseStart:function(F){var I=this.options,E=this.element.position(),D=this.element;this.resizing=true;this.documentScroll={top:C(document).scrollTop(),left:C(document).scrollLeft()};if(D.is(".ui-draggable")||(/absolute/).test(D.css("position"))){D.css({position:"absolute",top:E.top,left:E.left})}if(C.browser.opera&&(/relative/).test(D.css("position"))){D.css({position:"relative",top:"auto",left:"auto"})}this._renderProxy();var J=B(this.helper.css("left")),G=B(this.helper.css("top"));if(I.containment){J+=C(I.containment).scrollLeft()||0;G+=C(I.containment).scrollTop()||0}this.offset=this.helper.offset();this.position={left:J,top:G};this.size=this._helper?{width:D.outerWidth(),height:D.outerHeight()}:{width:D.width(),height:D.height()};this.originalSize=this._helper?{width:D.outerWidth(),height:D.outerHeight()}:{width:D.width(),height:D.height()};this.originalPosition={left:J,top:G};this.sizeDiff={width:D.outerWidth()-D.width(),height:D.outerHeight()-D.height()};this.originalMousePosition={left:F.pageX,top:F.pageY};this.aspectRatio=(typeof I.aspectRatio=="number")?I.aspectRatio:((this.originalSize.width/this.originalSize.height)||1);var H=C(".ui-resizable-"+this.axis).css("cursor");C("body").css("cursor",H=="auto"?this.axis+"-resize":H);D.addClass("ui-resizable-resizing");this._propagate("start",F);return true},_mouseDrag:function(D){var G=this.helper,F=this.options,L={},O=this,I=this.originalMousePosition,M=this.axis;var P=(D.pageX-I.left)||0,N=(D.pageY-I.top)||0;var H=this._change[M];if(!H){return false}var K=H.apply(this,[D,P,N]),J=C.browser.msie&&C.browser.version<7,E=this.sizeDiff;if(this._aspectRatio||D.shiftKey){K=this._updateRatio(K,D)}K=this._respectSize(K,D);this._propagate("resize",D);G.css({top:this.position.top+"px",left:this.position.left+"px",width:this.size.width+"px",height:this.size.height+"px"});if(!this._helper&&this._proportionallyResizeElements.length){this._proportionallyResize()}this._updateCache(K);this._trigger("resize",D,this.ui());return false},_mouseStop:function(G){this.resizing=false;var H=this.options,L=this;if(this._helper){var F=this._proportionallyResizeElements,D=F.length&&(/textarea/i).test(F[0].nodeName),E=D&&C.ui.hasScroll(F[0],"left")?0:L.sizeDiff.height,J=D?0:L.sizeDiff.width;var M={width:(L.size.width-J),height:(L.size.height-E)},I=(parseInt(L.element.css("left"),10)+(L.position.left-L.originalPosition.left))||null,K=(parseInt(L.element.css("top"),10)+(L.position.top-L.originalPosition.top))||null;if(!H.animate){this.element.css(C.extend(M,{top:K,left:I}))}L.helper.height(L.size.height);L.helper.width(L.size.width);if(this._helper&&!H.animate){this._proportionallyResize()}}C("body").css("cursor","auto");this.element.removeClass("ui-resizable-resizing");this._propagate("stop",G);if(this._helper){this.helper.remove()}return false},_updateCache:function(D){var E=this.options;this.offset=this.helper.offset();if(A(D.left)){this.position.left=D.left}if(A(D.top)){this.position.top=D.top}if(A(D.height)){this.size.height=D.height}if(A(D.width)){this.size.width=D.width}},_updateRatio:function(G,F){var H=this.options,I=this.position,E=this.size,D=this.axis;if(G.height){G.width=(E.height*this.aspectRatio)}else{if(G.width){G.height=(E.width/this.aspectRatio)}}if(D=="sw"){G.left=I.left+(E.width-G.width);G.top=null}if(D=="nw"){G.top=I.top+(E.height-G.height);G.left=I.left+(E.width-G.width)}return G},_respectSize:function(K,F){var I=this.helper,H=this.options,P=this._aspectRatio||F.shiftKey,O=this.axis,R=A(K.width)&&H.maxWidth&&(H.maxWidth<K.width),L=A(K.height)&&H.maxHeight&&(H.maxHeight<K.height),G=A(K.width)&&H.minWidth&&(H.minWidth>K.width),Q=A(K.height)&&H.minHeight&&(H.minHeight>K.height);if(G){K.width=H.minWidth}if(Q){K.height=H.minHeight}if(R){K.width=H.maxWidth}if(L){K.height=H.maxHeight}var E=this.originalPosition.left+this.originalSize.width,N=this.position.top+this.size.height;var J=/sw|nw|w/.test(O),D=/nw|ne|n/.test(O);if(G&&J){K.left=E-H.minWidth}if(R&&J){K.left=E-H.maxWidth}if(Q&&D){K.top=N-H.minHeight}if(L&&D){K.top=N-H.maxHeight}var M=!K.width&&!K.height;if(M&&!K.left&&K.top){K.top=null}else{if(M&&!K.top&&K.left){K.left=null}}return K},_proportionallyResize:function(){var I=this.options;if(!this._proportionallyResizeElements.length){return }var F=this.helper||this.element;for(var E=0;E<this._proportionallyResizeElements.length;E++){var G=this._proportionallyResizeElements[E];if(!this.borderDif){var D=[G.css("borderTopWidth"),G.css("borderRightWidth"),G.css("borderBottomWidth"),G.css("borderLeftWidth")],H=[G.css("paddingTop"),G.css("paddingRight"),G.css("paddingBottom"),G.css("paddingLeft")];this.borderDif=C.map(D,function(J,L){var K=parseInt(J,10)||0,M=parseInt(H[L],10)||0;return K+M})}if(C.browser.msie&&!(!(C(F).is(":hidden")||C(F).parents(":hidden").length))){continue}G.css({height:(F.height()-this.borderDif[0]-this.borderDif[2])||0,width:(F.width()-this.borderDif[1]-this.borderDif[3])||0})}},_renderProxy:function(){var E=this.element,H=this.options;this.elementOffset=E.offset();if(this._helper){this.helper=this.helper||C("<div style=\"overflow:hidden;\"></div>");var D=C.browser.msie&&C.browser.version<7,F=(D?1:0),G=(D?2:-1);this.helper.addClass(this._helper).css({width:this.element.outerWidth()+G,height:this.element.outerHeight()+G,position:"absolute",left:this.elementOffset.left-F+"px",top:this.elementOffset.top-F+"px",zIndex:++H.zIndex});this.helper.appendTo("body").disableSelection()}else{this.helper=this.element}},_change:{e:function(F,E,D){return{width:this.originalSize.width+E}},w:function(G,E,D){var I=this.options,F=this.originalSize,H=this.originalPosition;return{left:H.left+E,width:F.width-E}},n:function(G,E,D){var I=this.options,F=this.originalSize,H=this.originalPosition;return{top:H.top+D,height:F.height-D}},s:function(F,E,D){return{height:this.originalSize.height+D}},se:function(F,E,D){return C.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[F,E,D]))},sw:function(F,E,D){return C.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[F,E,D]))},ne:function(F,E,D){return C.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[F,E,D]))},nw:function(F,E,D){return C.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[F,E,D]))}},_propagate:function(E,D){C.ui.plugin.call(this,E,[D,this.ui()]);(E!="resize"&&this._trigger(E,D,this.ui()))},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}}));C.extend(C.ui.resizable,{version:"1.7.1",eventPrefix:"resize",defaults:{alsoResize:false,animate:false,animateDuration:"slow",animateEasing:"swing",aspectRatio:false,autoHide:false,cancel:":input,option",containment:false,delay:0,distance:1,ghost:false,grid:false,handles:"e,s,se",helper:false,maxHeight:null,maxWidth:null,minHeight:10,minWidth:10,zIndex:1000}});C.ui.plugin.add("resizable","alsoResize",{start:function(E,F){var D=C(this).data("resizable"),G=D.options;_store=function(H){C(H).each(function(){C(this).data("resizable-alsoresize",{width:parseInt(C(this).width(),10),height:parseInt(C(this).height(),10),left:parseInt(C(this).css("left"),10),top:parseInt(C(this).css("top"),10)})})};if(typeof (G.alsoResize)=="object"&&!G.alsoResize.parentNode){if(G.alsoResize.length){G.alsoResize=G.alsoResize[0];_store(G.alsoResize)}else{C.each(G.alsoResize,function(H,I){_store(H)})}}else{_store(G.alsoResize)}},resize:function(F,H){var E=C(this).data("resizable"),I=E.options,G=E.originalSize,K=E.originalPosition;var J={height:(E.size.height-G.height)||0,width:(E.size.width-G.width)||0,top:(E.position.top-K.top)||0,left:(E.position.left-K.left)||0},D=function(L,M){C(L).each(function(){var P=C(this),Q=C(this).data("resizable-alsoresize"),O={},N=M&&M.length?M:["width","height","top","left"];C.each(N||["width","height","top","left"],function(R,T){var S=(Q[T]||0)+(J[T]||0);if(S&&S>=0){O[T]=S||null}});if(/relative/.test(P.css("position"))&&C.browser.opera){E._revertToRelativePosition=true;P.css({position:"absolute",top:"auto",left:"auto"})}P.css(O)})};if(typeof (I.alsoResize)=="object"&&!I.alsoResize.nodeType){C.each(I.alsoResize,function(L,M){D(L,M)})}else{D(I.alsoResize)}},stop:function(E,F){var D=C(this).data("resizable");if(D._revertToRelativePosition&&C.browser.opera){D._revertToRelativePosition=false;el.css({position:"relative"})}C(this).removeData("resizable-alsoresize-start")}});C.ui.plugin.add("resizable","animate",{stop:function(H,M){var N=C(this).data("resizable"),I=N.options;var G=N._proportionallyResizeElements,D=G.length&&(/textarea/i).test(G[0].nodeName),E=D&&C.ui.hasScroll(G[0],"left")?0:N.sizeDiff.height,K=D?0:N.sizeDiff.width;var F={width:(N.size.width-K),height:(N.size.height-E)},J=(parseInt(N.element.css("left"),10)+(N.position.left-N.originalPosition.left))||null,L=(parseInt(N.element.css("top"),10)+(N.position.top-N.originalPosition.top))||null;N.element.animate(C.extend(F,L&&J?{top:L,left:J}:{}),{duration:I.animateDuration,easing:I.animateEasing,step:function(){var O={width:parseInt(N.element.css("width"),10),height:parseInt(N.element.css("height"),10),top:parseInt(N.element.css("top"),10),left:parseInt(N.element.css("left"),10)};if(G&&G.length){C(G[0]).css({width:O.width,height:O.height})}N._updateCache(O);N._propagate("resize",H)}})}});C.ui.plugin.add("resizable","containment",{start:function(E,O){var Q=C(this).data("resizable"),I=Q.options,K=Q.element;var F=I.containment,J=(F instanceof C)?F.get(0):(/parent/.test(F))?K.parent().get(0):F;if(!J){return }Q.containerElement=C(J);if(/document/.test(F)||F==document){Q.containerOffset={left:0,top:0};Q.containerPosition={left:0,top:0};Q.parentData={element:C(document),left:0,top:0,width:C(document).width(),height:C(document).height()||document.body.parentNode.scrollHeight}}else{var M=C(J),H=[];C(["Top","Right","Left","Bottom"]).each(function(S,R){H[S]=B(M.css("padding"+R))});Q.containerOffset=M.offset();Q.containerPosition=M.position();Q.containerSize={height:(M.innerHeight()-H[3]),width:(M.innerWidth()-H[1])};var N=Q.containerOffset,D=Q.containerSize.height,L=Q.containerSize.width,G=(C.ui.hasScroll(J,"left")?J.scrollWidth:L),P=(C.ui.hasScroll(J)?J.scrollHeight:D);Q.parentData={element:J,left:N.left,top:N.top,width:G,height:P}}},resize:function(F,O){var R=C(this).data("resizable"),H=R.options,E=R.containerSize,N=R.containerOffset,L=R.size,M=R.position,P=R._aspectRatio||F.shiftKey,D={top:0,left:0},G=R.containerElement;if(G[0]!=document&&(/static/).test(G.css("position"))){D=N}if(M.left<(R._helper?N.left:0)){R.size.width=R.size.width+(R._helper?(R.position.left-N.left):(R.position.left-D.left));if(P){R.size.height=R.size.width/H.aspectRatio}R.position.left=H.helper?N.left:0}if(M.top<(R._helper?N.top:0)){R.size.height=R.size.height+(R._helper?(R.position.top-N.top):R.position.top);if(P){R.size.width=R.size.height*H.aspectRatio}R.position.top=R._helper?N.top:0}R.offset.left=R.parentData.left+R.position.left;R.offset.top=R.parentData.top+R.position.top;var K=Math.abs((R._helper?R.offset.left-D.left:(R.offset.left-D.left))+R.sizeDiff.width),Q=Math.abs((R._helper?R.offset.top-D.top:(R.offset.top-N.top))+R.sizeDiff.height);var J=R.containerElement.get(0)==R.element.parent().get(0),I=/relative|absolute/.test(R.containerElement.css("position"));if(J&&I){K-=R.parentData.left}if(K+R.size.width>=R.parentData.width){R.size.width=R.parentData.width-K;if(P){R.size.height=R.size.width/R.aspectRatio}}if(Q+R.size.height>=R.parentData.height){R.size.height=R.parentData.height-Q;if(P){R.size.width=R.size.height*R.aspectRatio}}},stop:function(E,L){var N=C(this).data("resizable"),F=N.options,J=N.position,K=N.containerOffset,D=N.containerPosition,G=N.containerElement;var H=C(N.helper),O=H.offset(),M=H.outerWidth()-N.sizeDiff.width,I=H.outerHeight()-N.sizeDiff.height;if(N._helper&&!F.animate&&(/relative/).test(G.css("position"))){C(this).css({left:O.left-D.left-K.left,width:M,height:I})}if(N._helper&&!F.animate&&(/static/).test(G.css("position"))){C(this).css({left:O.left-D.left-K.left,width:M,height:I})}}});C.ui.plugin.add("resizable","ghost",{start:function(F,G){var D=C(this).data("resizable"),H=D.options,E=D.size;D.ghost=D.originalElement.clone();D.ghost.css({opacity:0.25,display:"block",position:"relative",height:E.height,width:E.width,margin:0,left:0,top:0}).addClass("ui-resizable-ghost").addClass(typeof H.ghost=="string"?H.ghost:"");D.ghost.appendTo(D.helper)},resize:function(E,F){var D=C(this).data("resizable"),G=D.options;if(D.ghost){D.ghost.css({position:"relative",height:D.size.height,width:D.size.width})}},stop:function(E,F){var D=C(this).data("resizable"),G=D.options;if(D.ghost&&D.helper){D.helper.get(0).removeChild(D.ghost.get(0))}}});C.ui.plugin.add("resizable","grid",{resize:function(D,L){var N=C(this).data("resizable"),G=N.options,J=N.size,H=N.originalSize,I=N.originalPosition,M=N.axis,K=G._aspectRatio||D.shiftKey;G.grid=typeof G.grid=="number"?[G.grid,G.grid]:G.grid;var F=Math.round((J.width-H.width)/(G.grid[0]||1))*(G.grid[0]||1),E=Math.round((J.height-H.height)/(G.grid[1]||1))*(G.grid[1]||1);if(/^(se|s|e)$/.test(M)){N.size.width=H.width+F;N.size.height=H.height+E}else{if(/^(ne)$/.test(M)){N.size.width=H.width+F;N.size.height=H.height+E;N.position.top=I.top-E}else{if(/^(sw)$/.test(M)){N.size.width=H.width+F;N.size.height=H.height+E;N.position.left=I.left-F}else{N.size.width=H.width+F;N.size.height=H.height+E;N.position.top=I.top-E;N.position.left=I.left-F}}}}});var B=function(D){return parseInt(D,10)||0};var A=function(D){return !isNaN(parseInt(D,10))}})(jQuery)