/*


 Copyright (c) 2008 Paul Bakaus
 Dual licensed under the MIT (MIT-LICENSE.txt)
 and GPL (GPL-LICENSE.txt) licenses.

*/
(function(e){e.widget("ui.resizable",e.extend(e.ui.mouse,{init:function(){var d=this,b=this.options,a=this.element.css("position");this.originalElement=this.element;this.element.addClass("ui-resizable").css({position:/static/.test(a)?"relative":a});e.extend(b,{_aspectRatio:!!b.aspectRatio,helper:b.helper||b.ghost||b.animate?b.helper||"proxy":null,knobHandles:b.knobHandles===true?"ui-resizable-knob-handle":b.knobHandles});b.defaultTheme={"ui-resizable":{display:"block"},"ui-resizable-handle":{position:"absolute",
background:"#ffffff",fontSize:"0.1px"},"ui-resizable-n":{cursor:"n-resize",height:"4px",left:"0px",right:"0px",borderTop:"1px solid #278DCD"},"ui-resizable-s":{cursor:"s-resize",height:"4px",left:"0px",right:"0px",borderBottom:"1px solid #278DCD"},"ui-resizable-e":{cursor:"e-resize",width:"4px",top:"0px",bottom:"0px",borderRight:"1px solid #278DCD"},"ui-resizable-w":{cursor:"w-resize",width:"4px",top:"0px",bottom:"0px",borderLeft:"1px solid #278DCD"},"ui-resizable-se":{cursor:"se-resize",width:"4px",
height:"4px",borderRight:"1px solid #278DCD",borderBottom:"1px solid #278DCD"},"ui-resizable-sw":{cursor:"sw-resize",width:"4px",height:"4px",borderBottom:"1px solid #278DCD",borderLeft:"1px solid #278DCD"},"ui-resizable-ne":{cursor:"ne-resize",width:"4px",height:"4px",borderRight:"1px solid #278DCD",borderTop:"1px solid #278DCD"},"ui-resizable-nw":{cursor:"nw-resize",width:"4px",height:"4px",borderLeft:"1px solid #278DCD",borderTop:"1px solid #278DCD"}};b.knobTheme={"ui-resizable-handle":{background:"#ffffff",
border:"1px solid #278DCD",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"}};b._nodeName=this.element[0].nodeName;if(b._nodeName.match(/canvas|textarea|input|select|button|img/i)){a=this.element;/relative/.test(a.css("position"))&&e.browser.opera&&a.css({position:"relative",top:"auto",left:"auto"});a.wrap(e('<div class="ui-wrapper"\tstyle="overflow: hidden;"></div>').css({position:a.css("position"),width:a.outerWidth(),height:a.outerHeight(),top:a.css("top"),left:a.css("left")}));a=this.element;this.element=this.element.parent();this.element.data("resizable",
this);this.element.css({marginLeft:a.css("marginLeft"),marginTop:a.css("marginTop"),marginRight:a.css("marginRight"),marginBottom:a.css("marginBottom")});a.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0});e.browser.safari&&b.preventDefault&&a.css("resize","none");b.proportionallyResize=a.css({position:"static",zoom:1,display:"block"});this.element.css({margin:a.css("margin")});this._proportionallyResize()}if(!b.handles)b.handles=!e(".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(b.handles.constructor==String){b.zIndex=b.zIndex||1E3;if(b.handles=="all")b.handles="n,e,s,w,se,sw,ne,nw";a=b.handles.split(",");b.handles={};for(var c={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;"},f=0;f<a.length;f++){var g=e.trim(a[f]),i=b.defaultTheme,h="ui-resizable-"+g,j=!e.ui.css(h)&&!b.knobHandles,l=e.ui.css("ui-resizable-knob-handle");i=e.extend(i[h],i["ui-resizable-handle"]);l=e.extend(b.knobTheme[h],!l?b.knobTheme["ui-resizable-handle"]:{});var p=/sw|se|ne|nw/.test(g)?{zIndex:++b.zIndex}:{};h=e(['<div class="ui-resizable-handle ',h,'" style="',j?c[g]:"",c.handle,'"></div>'].join("")).css(p);b.handles[g]=
".ui-resizable-"+g;this.element.append(h.css(j?i:{}).css(b.knobHandles?l:{}).addClass(b.knobHandles?"ui-resizable-knob-handle":"").addClass(b.knobHandles))}if(b.knobHandles)this.element.addClass("ui-resizable-knob").css(!e.ui.css("ui-resizable-knob")?{}:{})}this._renderAxis=function(m){m=m||this.element;for(var k in b.handles){if(b.handles[k].constructor==String)b.handles[k]=e(b.handles[k],this.element).show();b.transparent&&b.handles[k].css({opacity:0});if(this.element.is(".ui-wrapper")&&b._nodeName.match(/textarea|input|select|button/i)){var n=
e(b.handles[k],this.element),o=0;o=/sw|ne|nw|se|n|s/.test(k)?n.outerHeight():n.outerWidth();n=["padding",/ne|nw|n/.test(k)?"Top":/se|sw|s/.test(k)?"Bottom":/^e$/.test(k)?"Right":"Left"].join("");b.transparent||m.css(n,o);this._proportionallyResize()}e(b.handles[k])}};this._renderAxis(this.element);b._handles=e(".ui-resizable-handle",d.element);b.disableSelection&&b._handles.each(function(m,k){e.ui.disableSelection(k)});b._handles.mouseover(function(){if(!b.resizing){if(this.className)var m=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
d.axis=b.axis=m&&m[1]?m[1]:"se"}});if(b.autoHide){b._handles.hide();e(d.element).addClass("ui-resizable-autohide").hover(function(){e(this).removeClass("ui-resizable-autohide");b._handles.show()},function(){if(!b.resizing){e(this).addClass("ui-resizable-autohide");b._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(d,b){e.ui.plugin.call(this,d,[b,this.ui()]);d!="resize"&&this.element.triggerHandler(["resize",d].join(""),[b,this.ui()],this.options[d])},destroy:function(){var d=this.element,b=d.children(".ui-resizable").get(0);this.mouseDestroy();var a=function(c){e(c).removeClass("ui-resizable ui-resizable-disabled").removeData("resizable").unbind(".resizable").find(".ui-resizable-handle").remove()};a(d);if(d.is(".ui-wrapper")&&b){d.parent().append(e(b).css({position:d.css("position"),
width:d.outerWidth(),height:d.outerHeight(),top:d.css("top"),left:d.css("left")})).end().remove();a(b)}},mouseStart:function(d){if(this.options.disabled)return false;var b=false,a;for(a in this.options.handles)if(e(this.options.handles[a])[0]==d.target)b=true;if(!b)return false;b=this.options;var c=this.element.position();a=this.element;var f=function(h){return parseInt(h,10)||0},g=e.browser.msie&&e.browser.version<7;b.resizing=true;b.documentScroll={top:e(document).scrollTop(),left:e(document).scrollLeft()};
if(a.is(".ui-draggable")||/absolute/.test(a.css("position"))){var i=e.browser.msie&&!b.containment&&/absolute/.test(a.css("position"))&&!/relative/.test(a.parent().css("position"));a.css({position:"absolute",top:c.top+(i?b.documentScroll.top:0),left:c.left+(i?b.documentScroll.left:0)})}e.browser.opera&&/relative/.test(a.css("position"))&&a.css({position:"relative",top:"auto",left:"auto"});this._renderProxy();c=f(this.helper.css("left"));f=f(this.helper.css("top"));this.offset=this.helper.offset();
this.position={left:c,top:f};this.size=b.helper||g?{width:a.outerWidth(),height:a.outerHeight()}:{width:a.width(),height:a.height()};this.originalSize=b.helper||g?{width:a.outerWidth(),height:a.outerHeight()}:{width:a.width(),height:a.height()};this.originalPosition={left:c,top:f};this.sizeDiff={width:a.outerWidth()-a.width(),height:a.outerHeight()-a.height()};this.originalMousePosition={left:d.pageX,top:d.pageY};b.aspectRatio=typeof b.aspectRatio=="number"?b.aspectRatio:this.originalSize.height/
this.originalSize.width||1;b.preserveCursor&&e("body").css("cursor",this.axis+"-resize");this.propagate("start",d);return true},mouseDrag:function(d){var b=this.helper,a=this.options,c=this.originalMousePosition,f=this._change[this.axis];if(!f)return false;c=f.apply(this,[d,d.pageX-c.left||0,d.pageY-c.top||0]);if(a._aspectRatio||d.shiftKey)c=this._updateRatio(c,d);c=this._respectSize(c,d);this.propagate("resize",d);b.css({top:this.position.top+"px",left:this.position.left+"px",width:this.size.width+
"px",height:this.size.height+"px"});!a.helper&&a.proportionallyResize&&this._proportionallyResize();this._updateCache(c);this.element.triggerHandler("resize",[d,this.ui()],this.options.resize);return false},mouseStop:function(d){this.options.resizing=false;var b=this.options;if(b.helper){var a=b.proportionallyResize,c=a&&/textarea/i.test(a.get(0).nodeName);a=c&&e.ui.hasScroll(a.get(0),"left")?0:this.sizeDiff.height;c={width:this.size.width-(c?0:this.sizeDiff.width),height:this.size.height-a};a=parseInt(this.element.css("left"),
10)+(this.position.left-this.originalPosition.left)||null;var f=parseInt(this.element.css("top"),10)+(this.position.top-this.originalPosition.top)||null;b.animate||this.element.css(e.extend(c,{top:f,left:a}));b.helper&&!b.animate&&this._proportionallyResize()}b.preserveCursor&&e("body").css("cursor","auto");this.propagate("stop",d);b.helper&&this.helper.remove();return false},_updateCache:function(d){this.offset=this.helper.offset();if(d.left)this.position.left=d.left;if(d.top)this.position.top=d.top;
if(d.height)this.size.height=d.height;if(d.width)this.size.width=d.width},_updateRatio:function(d){var b=this.options,a=this.position,c=this.size,f=this.axis;if(d.height)d.width=c.height/b.aspectRatio;else if(d.width)d.height=c.width*b.aspectRatio;if(f=="sw"){d.left=a.left+(c.width-d.width);d.top=null}if(f=="nw"){d.top=a.top+(c.height-d.height);d.left=a.left+(c.width-d.width)}return d},_respectSize:function(d){var b=this.options,a=this.axis,c=d.width&&b.maxWidth&&b.maxWidth<d.width,f=d.height&&b.maxHeight&&
b.maxHeight<d.height,g=d.width&&b.minWidth&&b.minWidth>d.width,i=d.height&&b.minHeight&&b.minHeight>d.height;if(g)d.width=b.minWidth;if(i)d.height=b.minHeight;if(c)d.width=b.maxWidth;if(f)d.height=b.maxHeight;var h=this.originalPosition.left+this.originalSize.width,j=this.position.top+this.size.height,l=/sw|nw|w/.test(a);a=/nw|ne|n/.test(a);if(g&&l)d.left=h-b.minWidth;if(c&&l)d.left=h-b.maxWidth;if(i&&a)d.top=j-b.minHeight;if(f&&a)d.top=j-b.maxHeight;if((b=!d.width&&!d.height)&&!d.left&&d.top)d.top=
null;else if(b&&!d.top&&d.left)d.left=null;return d},_proportionallyResize:function(){var d=this.options;if(d.proportionallyResize){var b=d.proportionallyResize,a=this.helper||this.element;if(!d.borderDif){var c=[b.css("borderTopWidth"),b.css("borderRightWidth"),b.css("borderBottomWidth"),b.css("borderLeftWidth")],f=[b.css("paddingTop"),b.css("paddingRight"),b.css("paddingBottom"),b.css("paddingLeft")];d.borderDif=e.map(c,function(g,i){var h=parseInt(g,10)||0,j=parseInt(f[i],10)||0;return h+j})}b.css({height:a.height()-
d.borderDif[0]-d.borderDif[2]+"px",width:a.width()-d.borderDif[1]-d.borderDif[3]+"px"})}},_renderProxy:function(){var d=this.element,b=this.options;this.elementOffset=d.offset();if(b.helper){this.helper=this.helper||e('<div style="overflow:hidden;"></div>');var a=e.browser.msie&&e.browser.version<7,c=a?1:0;a=a?2:-1;this.helper.addClass(b.helper).css({width:d.outerWidth()+a,height:d.outerHeight()+a,position:"absolute",left:this.elementOffset.left-c+"px",top:this.elementOffset.top-c+"px",zIndex:++b.zIndex});
this.helper.appendTo("body");b.disableSelection&&e.ui.disableSelection(this.helper.get(0))}else this.helper=d},_change:{e:function(d,b){return{width:this.originalSize.width+b}},w:function(d,b){return{left:this.originalPosition.left+b,width:this.originalSize.width-b}},n:function(d,b,a){return{top:this.originalPosition.top+a,height:this.originalSize.height-a}},s:function(d,b,a){return{height:this.originalSize.height+a}},se:function(d,b,a){return e.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,
[d,b,a]))},sw:function(d,b,a){return e.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[d,b,a]))},ne:function(d,b,a){return e.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[d,b,a]))},nw:function(d,b,a){return e.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[d,b,a]))}}}));e.extend(e.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}});e.ui.plugin.add("resizable","containment",{start:function(d,b){var a=b.options,c=e(this).data("resizable"),f=c.element;a=a.containment;if(f=a instanceof e?a.get(0):/parent/.test(a)?f.parent().get(0):a){c.containerElement=e(f);if(/document/.test(a)||a==document){c.containerOffset={left:0,top:0};c.containerPosition={left:0,top:0};c.parentData={element:e(document),left:0,top:0,width:e(document).width(),height:e(document).height()||document.body.parentNode.scrollHeight}}else{c.containerOffset=
e(f).offset();c.containerPosition=e(f).position();c.containerSize={height:e(f).innerHeight(),width:e(f).innerWidth()};a=c.containerOffset;var g=c.containerSize.height,i=c.containerSize.width;i=e.ui.hasScroll(f,"left")?f.scrollWidth:i;g=e.ui.hasScroll(f)?f.scrollHeight:g;c.parentData={element:f,left:a.left,top:a.top,width:i,height:g}}}},resize:function(d,b){var a=b.options,c=e(this).data("resizable"),f=c.containerOffset,g=c.position,i=a._aspectRatio||d.shiftKey,h={top:0,left:0},j=c.containerElement;
if(j[0]!=document&&/static/.test(j.css("position")))h=c.containerPosition;if(g.left<(a.helper?f.left:h.left)){c.size.width+=a.helper?c.position.left-f.left:c.position.left-h.left;if(i)c.size.height=c.size.width*a.aspectRatio;c.position.left=a.helper?f.left:h.left}if(g.top<(a.helper?f.top:0)){c.size.height+=a.helper?c.position.top-f.top:c.position.top;if(i)c.size.width=c.size.height/a.aspectRatio;c.position.top=a.helper?f.top:0}g=(a.helper?c.offset.left-f.left:c.position.left-h.left)+c.sizeDiff.width;
f=(a.helper?c.offset.top-f.top:c.position.top)+c.sizeDiff.height;if(g+c.size.width>=c.parentData.width){c.size.width=c.parentData.width-g;if(i)c.size.height=c.size.width*a.aspectRatio}if(f+c.size.height>=c.parentData.height){c.size.height=c.parentData.height-f;if(i)c.size.width=c.size.height/a.aspectRatio}},stop:function(d,b){var a=b.options,c=e(this).data("resizable"),f=c.containerOffset,g=c.containerPosition,i=c.containerElement,h=e(c.helper);c=h.offset();var j=h.innerWidth();h=h.innerHeight();
a.helper&&!a.animate&&/relative/.test(i.css("position"))&&e(this).css({left:c.left-f.left,top:c.top-f.top,width:j,height:h});a.helper&&!a.animate&&/static/.test(i.css("position"))&&e(this).css({left:g.left+(c.left-f.left),top:g.top+(c.top-f.top),width:j,height:h})}});e.ui.plugin.add("resizable","grid",{resize:function(d,b){var a=b.options,c=e(this).data("resizable"),f=c.size,g=c.originalSize,i=c.originalPosition,h=c.axis;a.grid=typeof a.grid=="number"?[a.grid,a.grid]:a.grid;var j=Math.round((f.width-
g.width)/(a.grid[0]||1))*(a.grid[0]||1);a=Math.round((f.height-g.height)/(a.grid[1]||1))*(a.grid[1]||1);if(/^(se|s|e)$/.test(h)){c.size.width=g.width+j;c.size.height=g.height+a}else if(/^(ne)$/.test(h)){c.size.width=g.width+j;c.size.height=g.height+a;c.position.top=i.top-a}else{if(/^(sw)$/.test(h)){c.size.width=g.width+j;c.size.height=g.height+a}else{c.size.width=g.width+j;c.size.height=g.height+a;c.position.top=i.top-a}c.position.left=i.left-j}}});e.ui.plugin.add("resizable","animate",{stop:function(d,
b){var a=b.options,c=e(this).data("resizable"),f=a.proportionallyResize,g=f&&/textarea/i.test(f.get(0).nodeName),i=g&&e.ui.hasScroll(f.get(0),"left")?0:c.sizeDiff.height;g={width:c.size.width-(g?0:c.sizeDiff.width),height:c.size.height-i};i=parseInt(c.element.css("left"),10)+(c.position.left-c.originalPosition.left)||null;var h=parseInt(c.element.css("top"),10)+(c.position.top-c.originalPosition.top)||null;c.element.animate(e.extend(g,h&&i?{top:h,left:i}:{}),{duration:a.animateDuration||"slow",easing:a.animateEasing||
"swing",step:function(){var j={width:parseInt(c.element.css("width"),10),height:parseInt(c.element.css("height"),10),top:parseInt(c.element.css("top"),10),left:parseInt(c.element.css("left"),10)};f&&f.css({width:j.width,height:j.height});c._updateCache(j);c.propagate("animate",d)}})}});e.ui.plugin.add("resizable","ghost",{start:function(d,b){var a=b.options,c=e(this).data("resizable"),f=a.proportionallyResize,g=c.size;c.ghost=f?f.clone():c.element.clone();c.ghost.css({opacity:0.25,display:"block",
position:"relative",height:g.height,width:g.width,margin:0,left:0,top:0}).addClass("ui-resizable-ghost").addClass(typeof a.ghost=="string"?a.ghost:"");c.ghost.appendTo(c.helper)},resize:function(){var d=e(this).data("resizable");d.ghost&&d.ghost.css({position:"relative",height:d.size.height,width:d.size.width})},stop:function(){var d=e(this).data("resizable");d.ghost&&d.helper&&d.helper.get(0).removeChild(d.ghost.get(0))}});e.ui.plugin.add("resizable","alsoResize",{start:function(d,b){var a=b.options;
e(this).data("resizable");var c=function(f){e(f).each(function(){e(this).data("resizable-alsoresize",{width:parseInt(e(this).width(),10),height:parseInt(e(this).height(),10),left:parseInt(e(this).css("left"),10),top:parseInt(e(this).css("top"),10)})})};if(typeof a.alsoResize=="object")if(a.alsoResize.length){a.alsoResize=a.alsoResize[0];c(a.alsoResize)}else e.each(a.alsoResize,function(f){c(f)});else c(a.alsoResize)},resize:function(d,b){var a=b.options,c=e(this).data("resizable"),f=c.originalSize,
g=c.originalPosition,i={height:c.size.height-f.height||0,width:c.size.width-f.width||0,top:c.position.top-g.top||0,left:c.position.left-g.left||0},h=function(j,l){e(j).each(function(){var p=e(this).data("resizable-alsoresize"),m={};e.each((l&&l.length?l:["width","height","top","left"])||["width","height","top","left"],function(k,n){var o=(p[n]||0)+(i[n]||0);if(o&&o>=0)m[n]=o||null});e(this).css(m)})};typeof a.alsoResize=="object"?e.each(a.alsoResize,function(j,l){h(j,l)}):h(a.alsoResize)},stop:function(){e(this).removeData("resizable-alsoresize-start")}})})(jQuery);

