(function($){$.widget("ui.resizable",$.extend({},$.ui.mouse,{init:function(){var d=this,o=this.options;var f=this.element.css('position');this.originalElement=this.element;this.element.addClass("ui-resizable").css({position:/static/.test(f)?'relative':f});$.extend(o,{_aspectRatio:!!(o.aspectRatio),helper:o.helper||o.ghost||o.animate?o.helper||'proxy':null,knobHandles:o.knobHandles===true?'ui-resizable-knob-handle':o.knobHandles});var g='1px solid #DEDEDE';o.defaultTheme={'ui-resizable':{display:'block'},'ui-resizable-handle':{position:'absolute',background:'#F2F2F2',fontSize:'0.1px'},'ui-resizable-n':{cursor:'n-resize',height:'4px',left:'0px',right:'0px',borderTop:g},'ui-resizable-s':{cursor:'s-resize',height:'4px',left:'0px',right:'0px',borderBottom:g},'ui-resizable-e':{cursor:'e-resize',width:'4px',top:'0px',bottom:'0px',borderRight:g},'ui-resizable-w':{cursor:'w-resize',width:'4px',top:'0px',bottom:'0px',borderLeft:g},'ui-resizable-se':{cursor:'se-resize',width:'4px',height:'4px',borderRight:g,borderBottom:g},'ui-resizable-sw':{cursor:'sw-resize',width:'4px',height:'4px',borderBottom:g,borderLeft:g},'ui-resizable-ne':{cursor:'ne-resize',width:'4px',height:'4px',borderRight:g,borderTop:g},'ui-resizable-nw':{cursor:'nw-resize',width:'4px',height:'4px',borderLeft:g,borderTop:g}};o.knobTheme={'ui-resizable-handle':{background:'#F2F2F2',border:'1px solid #808080',height:'8px',width:'8px'},'ui-resizable-n':{cursor:'n-resize',top:'0px',left:'45%'},'ui-resizable-s':{cursor:'s-resize',bottom:'0px',left:'45%'},'ui-resizable-e':{cursor:'e-resize',right:'0px',top:'45%'},'ui-resizable-w':{cursor:'w-resize',left:'0px',top:'45%'},'ui-resizable-se':{cursor:'se-resize',right:'0px',bottom:'0px'},'ui-resizable-sw':{cursor:'sw-resize',left:'0px',bottom:'0px'},'ui-resizable-nw':{cursor:'nw-resize',left:'0px',top:'0px'},'ui-resizable-ne':{cursor:'ne-resize',right:'0px',top:'0px'}};o._nodeName=this.element[0].nodeName;if(o._nodeName.match(/canvas|textarea|input|select|button|img/i)){var h=this.element;if(/relative/.test(h.css('position'))&&$.browser.opera)h.css({position:'relative',top:'auto',left:'auto'});h.wrap($('<div class="ui-wrapper"	style="overflow: hidden;"></div>').css({position:h.css('position'),width:h.outerWidth(),height:h.outerHeight(),top:h.css('top'),left:h.css('left')}));var j=this.element;this.element=this.element.parent();this.element.data('resizable',this);this.element.css({marginLeft:j.css("marginLeft"),marginTop:j.css("marginTop"),marginRight:j.css("marginRight"),marginBottom:j.css("marginBottom")});j.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0});if($.browser.safari&&o.preventDefault)j.css('resize','none');o.proportionallyResize=j.css({position:'static',zoom:1,display:'block'});this.element.css({margin:j.css('margin')});this._proportionallyResize()}if(!o.handles)o.handles=!$('.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(o.handles.constructor==String){o.zIndex=o.zIndex||1000;if(o.handles=='all')o.handles='n,e,s,w,se,sw,ne,nw';var n=o.handles.split(",");o.handles={};var k={handle:'position: absolute; display: none; overflow:hidden;',n:'top: 0pt; width:100%;',e:'right: 0pt; height:100%;',s:'bottom: 0pt; width:100%;',w:'left: 0pt; height:100%;',se:'bottom: 0pt; right: 0px;',sw:'bottom: 0pt; left: 0px;',ne:'top: 0pt; right: 0px;',nw:'top: 0pt; left: 0px;'};for(var i=0;i<n.length;i++){var l=$.trim(n[i]),dt=o.defaultTheme,hname='ui-resizable-'+l,loadDefault=!$.ui.css(hname)&&!o.knobHandles,userKnobClass=$.ui.css('ui-resizable-knob-handle'),allDefTheme=$.extend(dt[hname],dt['ui-resizable-handle']),allKnobTheme=$.extend(o.knobTheme[hname],!userKnobClass?o.knobTheme['ui-resizable-handle']:{});var m=/sw|se|ne|nw/.test(l)?{zIndex:++o.zIndex}:{};var p=(loadDefault?k[l]:''),axis=$(['<div class="ui-resizable-handle ',hname,'" style="',p,k.handle,'"></div>'].join('')).css(m);o.handles[l]='.ui-resizable-'+l;this.element.append(axis.css(loadDefault?allDefTheme:{}).css(o.knobHandles?allKnobTheme:{}).addClass(o.knobHandles?'ui-resizable-knob-handle':'').addClass(o.knobHandles))}if(o.knobHandles)this.element.addClass('ui-resizable-knob').css(!$.ui.css('ui-resizable-knob')?{}:{})}this._renderAxis=function(a){a=a||this.element;for(var i in o.handles){if(o.handles[i].constructor==String)o.handles[i]=$(o.handles[i],this.element).show();if(o.transparent)o.handles[i].css({opacity:0});if(this.element.is('.ui-wrapper')&&o._nodeName.match(/textarea|input|select|button/i)){var b=$(o.handles[i],this.element),padWrapper=0;padWrapper=/sw|ne|nw|se|n|s/.test(i)?b.outerHeight():b.outerWidth();var c=['padding',/ne|nw|n/.test(i)?'Top':/se|sw|s/.test(i)?'Bottom':/^e$/.test(i)?'Right':'Left'].join("");if(!o.transparent)a.css(c,padWrapper);this._proportionallyResize()}if(!$(o.handles[i]).length)continue}};this._renderAxis(this.element);o._handles=$('.ui-resizable-handle',d.element);if(o.disableSelection)o._handles.each(function(i,e){$.ui.disableSelection(e)});o._handles.mouseover(function(){if(!o.resizing){if(this.className)var a=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);d.axis=o.axis=a&&a[1]?a[1]:'se'}});if(o.autoHide){o._handles.hide();$(d.element).addClass("ui-resizable-autohide").hover(function(){$(this).removeClass("ui-resizable-autohide");o._handles.show()},function(){if(!o.resizing){$(this).addClass("ui-resizable-autohide");o._handles.hide()}})}this.mouseInit()},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,options:this.options,originalSize:this.originalSize,originalPosition:this.originalPosition}},propagate:function(n,e){$.ui.plugin.call(this,n,[e,this.ui()]);if(n!="resize")this.element.triggerHandler(["resize",n].join(""),[e,this.ui()],this.options[n])},destroy:function(){var b=this.element,wrapped=b.children(".ui-resizable").get(0);this.mouseDestroy();var c=function(a){$(a).removeClass("ui-resizable ui-resizable-disabled").removeData("resizable").unbind(".resizable").find('.ui-resizable-handle').remove()};c(b);if(b.is('.ui-wrapper')&&wrapped){b.parent().append($(wrapped).css({position:b.css('position'),width:b.outerWidth(),height:b.outerHeight(),top:b.css('top'),left:b.css('left')})).end().remove();c(wrapped)}},mouseStart:function(e){if(this.options.disabled)return false;var a=false;for(var i in this.options.handles){if($(this.options.handles[i])[0]==e.target)a=true}if(!a)return false;var o=this.options,iniPos=this.element.position(),el=this.element,num=function(v){return parseInt(v,10)||0},ie6=$.browser.msie&&$.browser.version<7;o.resizing=true;o.documentScroll={top:$(document).scrollTop(),left:$(document).scrollLeft()};if(el.is('.ui-draggable')||(/absolute/).test(el.css('position'))){var b=$.browser.msie&&!o.containment&&(/absolute/).test(el.css('position'))&&!(/relative/).test(el.parent().css('position'));var c=b?o.documentScroll.top:0,dscrolll=b?o.documentScroll.left:0;el.css({position:'absolute',top:(iniPos.top+c),left:(iniPos.left+dscrolll)})}if($.browser.opera&&/relative/.test(el.css('position')))el.css({position:'relative',top:'auto',left:'auto'});this._renderProxy();var d=num(this.helper.css('left')),curtop=num(this.helper.css('top'));if(o.containment){d+=$(o.containment).scrollLeft()||0;curtop+=$(o.containment).scrollTop()||0}this.offset=this.helper.offset();this.position={left:d,top:curtop};this.size=o.helper||ie6?{width:el.outerWidth(),height:el.outerHeight()}:{width:el.width(),height:el.height()};this.originalSize=o.helper||ie6?{width:el.outerWidth(),height:el.outerHeight()}:{width:el.width(),height:el.height()};this.originalPosition={left:d,top:curtop};this.sizeDiff={width:el.outerWidth()-el.width(),height:el.outerHeight()-el.height()};this.originalMousePosition={left:e.pageX,top:e.pageY};o.aspectRatio=(typeof o.aspectRatio=='number')?o.aspectRatio:((this.originalSize.height/this.originalSize.width)||1);if(o.preserveCursor)$('body').css('cursor',this.axis+'-resize');this.propagate("start",e);return true},mouseDrag:function(e){var b=this.helper,o=this.options,props={},self=this,smp=this.originalMousePosition,a=this.axis;var c=(e.pageX-smp.left)||0,dy=(e.pageY-smp.top)||0;var d=this._change[a];if(!d)return false;var f=d.apply(this,[e,c,dy]),ie6=$.browser.msie&&$.browser.version<7,csdif=this.sizeDiff;if(o._aspectRatio||e.shiftKey)f=this._updateRatio(f,e);f=this._respectSize(f,e);this.propagate("resize",e);b.css({top:this.position.top+"px",left:this.position.left+"px",width:this.size.width+"px",height:this.size.height+"px"});if(!o.helper&&o.proportionallyResize)this._proportionallyResize();this._updateCache(f);this.element.triggerHandler("resize",[e,this.ui()],this.options["resize"]);return false},mouseStop:function(e){this.options.resizing=false;var o=this.options,num=function(v){return parseInt(v,10)||0},self=this;if(o.helper){var a=o.proportionallyResize,ista=a&&(/textarea/i).test(a.get(0).nodeName),soffseth=ista&&$.ui.hasScroll(a.get(0),'left')?0:self.sizeDiff.height,soffsetw=ista?0:self.sizeDiff.width;var s={width:(self.size.width-soffsetw),height:(self.size.height-soffseth)},left=(parseInt(self.element.css('left'),10)+(self.position.left-self.originalPosition.left))||null,top=(parseInt(self.element.css('top'),10)+(self.position.top-self.originalPosition.top))||null;if(!o.animate)this.element.css($.extend(s,{top:top,left:left}));if(o.helper&&!o.animate)this._proportionallyResize()}if(o.preserveCursor)$('body').css('cursor','auto');this.propagate("stop",e);if(o.helper)this.helper.remove();return false},_updateCache:function(a){var o=this.options;this.offset=this.helper.offset();if(a.left)this.position.left=a.left;if(a.top)this.position.top=a.top;if(a.height)this.size.height=a.height;if(a.width)this.size.width=a.width},_updateRatio:function(b,e){var o=this.options,cpos=this.position,csize=this.size,a=this.axis;if(b.height)b.width=(csize.height/o.aspectRatio);else if(b.width)b.height=(csize.width*o.aspectRatio);if(a=='sw'){b.left=cpos.left+(csize.width-b.width);b.top=null}if(a=='nw'){b.top=cpos.top+(csize.height-b.height);b.left=cpos.left+(csize.width-b.width)}return b},_respectSize:function(b,e){var c=this.helper,o=this.options,pRatio=o._aspectRatio||e.shiftKey,a=this.axis,ismaxw=b.width&&o.maxWidth&&o.maxWidth<b.width,ismaxh=b.height&&o.maxHeight&&o.maxHeight<b.height,isminw=b.width&&o.minWidth&&o.minWidth>b.width,isminh=b.height&&o.minHeight&&o.minHeight>b.height;if(isminw)b.width=o.minWidth;if(isminh)b.height=o.minHeight;if(ismaxw)b.width=o.maxWidth;if(ismaxh)b.height=o.maxHeight;var d=this.originalPosition.left+this.originalSize.width,dh=this.position.top+this.size.height;var f=/sw|nw|w/.test(a),ch=/nw|ne|n/.test(a);if(isminw&&f)b.left=d-o.minWidth;if(ismaxw&&f)b.left=d-o.maxWidth;if(isminh&&ch)b.top=dh-o.minHeight;if(ismaxh&&ch)b.top=dh-o.maxHeight;var g=!b.width&&!b.height;if(g&&!b.left&&b.top)b.top=null;else if(g&&!b.top&&b.left)b.left=null;return b},_proportionallyResize:function(){var o=this.options;if(!o.proportionallyResize)return;var c=o.proportionallyResize,el=this.helper||this.element;if(!o.borderDif){var b=[c.css('borderTopWidth'),c.css('borderRightWidth'),c.css('borderBottomWidth'),c.css('borderLeftWidth')],p=[c.css('paddingTop'),c.css('paddingRight'),c.css('paddingBottom'),c.css('paddingLeft')];o.borderDif=$.map(b,function(v,i){var a=parseInt(v,10)||0,padding=parseInt(p[i],10)||0;return a+padding})}c.css({height:(el.height()-o.borderDif[0]-o.borderDif[2])+"px",width:(el.width()-o.borderDif[1]-o.borderDif[3])+"px"})},_renderProxy:function(){var a=this.element,o=this.options;this.elementOffset=a.offset();if(o.helper){this.helper=this.helper||$('<div style="overflow:hidden;"></div>');var b=$.browser.msie&&$.browser.version<7,ie6offset=(b?1:0),pxyoffset=(b?2:-1);this.helper.addClass(o.helper).css({width:a.outerWidth()+pxyoffset,height:a.outerHeight()+pxyoffset,position:'absolute',left:this.elementOffset.left-ie6offset+'px',top:this.elementOffset.top-ie6offset+'px',zIndex:++o.zIndex});this.helper.appendTo("body");if(o.disableSelection)$.ui.disableSelection(this.helper.get(0))}else{this.helper=a}},_change:{e:function(e,a,b){return{width:this.originalSize.width+a}},w:function(e,a,b){var o=this.options,cs=this.originalSize,sp=this.originalPosition;return{left:sp.left+a,width:cs.width-a}},n:function(e,a,b){var o=this.options,cs=this.originalSize,sp=this.originalPosition;return{top:sp.top+b,height:cs.height-b}},s:function(e,a,b){return{height:this.originalSize.height+b}},se:function(e,a,b){return $.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[e,a,b]))},sw:function(e,a,b){return $.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[e,a,b]))},ne:function(e,a,b){return $.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[e,a,b]))},nw:function(e,a,b){return $.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[e,a,b]))}}}));$.extend($.ui.resizable,{defaults:{cancel:":input",distance:1,delay:0,preventDefault:true,transparent:false,minWidth:10,minHeight:10,aspectRatio:false,disableSelection:true,preserveCursor:true,autoHide:false,knobHandles:false}});$.ui.plugin.add("resizable","containment",{start:function(e,a){var o=a.options,self=$(this).data("resizable"),el=self.element;var b=o.containment,ce=(b instanceof $)?b.get(0):(/parent/.test(b))?el.parent().get(0):b;if(!ce)return;self.containerElement=$(ce);if(/document/.test(b)||b==document){self.containerOffset={left:0,top:0};self.containerPosition={left:0,top:0};self.parentData={element:$(document),left:0,top:0,width:$(document).width(),height:$(document).height()||document.body.parentNode.scrollHeight}}else{self.containerOffset=$(ce).offset();self.containerPosition=$(ce).position();self.containerSize={height:$(ce).innerHeight(),width:$(ce).innerWidth()};var c=self.containerOffset,ch=self.containerSize.height,cw=self.containerSize.width,width=($.ui.hasScroll(ce,"left")?ce.scrollWidth:cw),height=($.ui.hasScroll(ce)?ce.scrollHeight:ch);self.parentData={element:ce,left:c.left,top:c.top,width:width,height:height}}},resize:function(e,a){var o=a.options,self=$(this).data("resizable"),ps=self.containerSize,co=self.containerOffset,cs=self.size,cp=self.position,pRatio=o._aspectRatio||e.shiftKey,cop={top:0,left:0},ce=self.containerElement;if(ce[0]!=document&&/static/.test(ce.css('position')))cop=self.containerPosition;if(cp.left<(o.helper?co.left:cop.left)){self.size.width=self.size.width+(o.helper?(self.position.left-co.left):(self.position.left-cop.left));if(pRatio)self.size.height=self.size.width*o.aspectRatio;self.position.left=o.helper?co.left:cop.left}if(cp.top<(o.helper?co.top:0)){self.size.height=self.size.height+(o.helper?(self.position.top-co.top):self.position.top);if(pRatio)self.size.width=self.size.height/o.aspectRatio;self.position.top=o.helper?co.top:0}var b=(o.helper?self.offset.left-co.left:(self.position.left-cop.left))+self.sizeDiff.width,hoset=(o.helper?self.offset.top-co.top:self.position.top)+self.sizeDiff.height;if(b+self.size.width>=self.parentData.width){self.size.width=self.parentData.width-b;if(pRatio)self.size.height=self.size.width*o.aspectRatio}if(hoset+self.size.height>=self.parentData.height){self.size.height=self.parentData.height-hoset;if(pRatio)self.size.width=self.size.height/o.aspectRatio}},stop:function(e,a){var o=a.options,self=$(this).data("resizable"),cp=self.position,co=self.containerOffset,cop=self.containerPosition,ce=self.containerElement;var b=$(self.helper),ho=b.offset(),w=b.innerWidth(),h=b.innerHeight();if(o.helper&&!o.animate&&/relative/.test(ce.css('position')))$(this).css({left:(ho.left-co.left),top:(ho.top-co.top),width:w,height:h});if(o.helper&&!o.animate&&/static/.test(ce.css('position')))$(this).css({left:cop.left+(ho.left-co.left),top:cop.top+(ho.top-co.top),width:w,height:h})}});$.ui.plugin.add("resizable","grid",{resize:function(e,b){var o=b.options,self=$(this).data("resizable"),cs=self.size,os=self.originalSize,op=self.originalPosition,a=self.axis,ratio=o._aspectRatio||e.shiftKey;o.grid=typeof o.grid=="number"?[o.grid,o.grid]:o.grid;var c=Math.round((cs.width-os.width)/(o.grid[0]||1))*(o.grid[0]||1),oy=Math.round((cs.height-os.height)/(o.grid[1]||1))*(o.grid[1]||1);if(/^(se|s|e)$/.test(a)){self.size.width=os.width+c;self.size.height=os.height+oy}else if(/^(ne)$/.test(a)){self.size.width=os.width+c;self.size.height=os.height+oy;self.position.top=op.top-oy}else if(/^(sw)$/.test(a)){self.size.width=os.width+c;self.size.height=os.height+oy;self.position.left=op.left-c}else{self.size.width=os.width+c;self.size.height=os.height+oy;self.position.top=op.top-oy;self.position.left=op.left-c}}});$.ui.plugin.add("resizable","animate",{stop:function(e,b){var o=b.options,self=$(this).data("resizable");var c=o.proportionallyResize,ista=c&&(/textarea/i).test(c.get(0).nodeName),soffseth=ista&&$.ui.hasScroll(c.get(0),'left')?0:self.sizeDiff.height,soffsetw=ista?0:self.sizeDiff.width;var d={width:(self.size.width-soffsetw),height:(self.size.height-soffseth)},left=(parseInt(self.element.css('left'),10)+(self.position.left-self.originalPosition.left))||null,top=(parseInt(self.element.css('top'),10)+(self.position.top-self.originalPosition.top))||null;self.element.animate($.extend(d,top&&left?{top:top,left:left}:{}),{duration:o.animateDuration||"slow",easing:o.animateEasing||"swing",step:function(){var a={width:parseInt(self.element.css('width'),10),height:parseInt(self.element.css('height'),10),top:parseInt(self.element.css('top'),10),left:parseInt(self.element.css('left'),10)};if(c)c.css({width:a.width,height:a.height});self._updateCache(a);self.propagate("animate",e)}})}});$.ui.plugin.add("resizable","ghost",{start:function(e,a){var o=a.options,self=$(this).data("resizable"),pr=o.proportionallyResize,cs=self.size;if(!pr)self.ghost=self.element.clone();else self.ghost=pr.clone();self.ghost.css({opacity:.25,display:'block',position:'relative',height:cs.height,width:cs.width,margin:0,left:0,top:0}).addClass('ui-resizable-ghost').addClass(typeof o.ghost=='string'?o.ghost:'');self.ghost.appendTo(self.helper)},resize:function(e,a){var o=a.options,self=$(this).data("resizable"),pr=o.proportionallyResize;if(self.ghost)self.ghost.css({position:'relative',height:self.size.height,width:self.size.width})},stop:function(e,a){var o=a.options,self=$(this).data("resizable"),pr=o.proportionallyResize;if(self.ghost&&self.helper)self.helper.get(0).removeChild(self.ghost.get(0))}});$.ui.plugin.add("resizable","alsoResize",{start:function(e,b){var o=b.options,self=$(this).data("resizable"),_store=function(a){$(a).each(function(){$(this).data("resizable-alsoresize",{width:parseInt($(this).width(),10),height:parseInt($(this).height(),10),left:parseInt($(this).css('left'),10),top:parseInt($(this).css('top'),10)})})};if(typeof(o.alsoResize)=='object'){if(o.alsoResize.length){o.alsoResize=o.alsoResize[0];_store(o.alsoResize)}else{$.each(o.alsoResize,function(a,c){_store(a)})}}else{_store(o.alsoResize)}},resize:function(e,f){var o=f.options,self=$(this).data("resizable"),os=self.originalSize,op=self.originalPosition;var g={height:(self.size.height-os.height)||0,width:(self.size.width-os.width)||0,top:(self.position.top-op.top)||0,left:(self.position.left-op.left)||0},_alsoResize=function(e,c){$(e).each(function(){var d=$(this).data("resizable-alsoresize"),style={},css=c&&c.length?c:['width','height','top','left'];$.each(css||['width','height','top','left'],function(i,a){var b=(d[a]||0)+(g[a]||0);if(b&&b>=0)style[a]=b||null});$(this).css(style)})};if(typeof(o.alsoResize)=='object'){$.each(o.alsoResize,function(a,c){_alsoResize(a,c)})}else{_alsoResize(o.alsoResize)}},stop:function(e,a){$(this).removeData("resizable-alsoresize-start")}})})(jQuery);