var Resizables={instances:[],observers:[],register:function(A){if(this.instances.length==0){this.eventMouseUp=this.endResize.bindAsEventListener(this);this.eventMouseMove=this.updateResize.bindAsEventListener(this);Event.observe(document,"mouseup",this.eventMouseUp);Event.observe(document,"mousemove",this.eventMouseMove)}this.instances.push(A)},unregister:function(A){this.instances=this.instances.reject(function(B){return B==A});if(this.instances.length==0){Event.stopObserving(document,"mouseup",this.eventMouseUp);Event.stopObserving(document,"mousemove",this.eventMouseMove)}},activate:function(A){if(A.options.delay){this._timeout=setTimeout(function(){Resizables._timeout=null;Resizables.activeResizable=A}.bind(this),A.options.delay)}else{this.activeResizable=A}},deactivate:function(){this.activeResizable=null},updateResize:function(A){if(!this.activeResizable){return }var B=[Event.pointerX(A),Event.pointerY(A)];if(this._lastPointer&&(this._lastPointer.inspect()==B.inspect())){return }this._lastPointer=B;this.activeResizable.updateResize(A,B)},endResize:function(A){if(this._timeout){clearTimeout(this._timeout);this._timeout=null}if(!this.activeResizable){return }this._lastPointer=null;this.activeResizable.endResize(A);this.activeResizable=null},addObserver:function(A){this.observers.push(A);this._cacheObserverCallbacks()},removeObserver:function(A){this.observers=this.observers.reject(function(B){return B.element==A});this._cacheObserverCallbacks()},notify:function(A,B,C){if(this[A+"Count"]>0){this.observers.each(function(D){if(D[A]){D[A](A,B,C)}})}if(B.options[A]){B.options[A](B,C)}},_cacheObserverCallbacks:function(){["onStart","onEnd","onResize"].each(function(A){Resizables[A+"Count"]=Resizables.observers.select(function(B){return B[A]}).length})}};var Resizable=Class.create();Resizable._resizing={};Resizable.prototype={initialize:function(B){var C={handle:false,snap:false,delay:0,minHeight:false,minwidth:false,maxHeight:false,maxWidth:false};this.element=$(B);var A=Object.extend(C,arguments[1]||{});if(A.handle&&typeof A.handle=="string"){this.handle=$(A.handle)}else{if(A.handle){this.handle=A.handle}}if(!this.handle){this.handle=this.element}this.options=A;this.dragging=false;this.eventMouseDown=this.initResize.bindAsEventListener(this);Event.observe(this.handle,"mousedown",this.eventMouseDown);Resizables.register(this)},destroy:function(){Event.stopObserving(this.handle,"mousedown",this.eventMouseDown)},currentDelta:function(){return([parseInt(Element.getStyle(this.element,"width")||"0"),parseInt(Element.getStyle(this.element,"height")||"0")])},initResize:function(A){if(typeof Resizable._resizing[this.element]!="undefined"&&Resizable._resizing[this.element]){return }if(Event.isLeftClick(A)){var B=Event.element(A);if((tag_name=B.tagName.toUpperCase())&&(tag_name=="INPUT"||tag_name=="SELECT"||tag_name=="OPTION"||tag_name=="BUTTON"||tag_name=="TEXTAREA")){return }this.pointer=[Event.pointerX(A),Event.pointerY(A)];this.size=[parseInt(this.element.getStyle("width"))||0,parseInt(this.element.getStyle("height"))||0];Resizables.activate(this);Event.stop(A)}},startResize:function(A){this.resizing=true;if(this.options.zindex){this.originalZ=parseInt(Element.getStyle(this.element,"z-index")||0);this.element.style.zIndex=this.options.zindex}Resizables.notify("onStart",this,A);Resizable._resizing[this.element]=true},updateResize:function(A,B){if(!this.resizing){this.startResize(A)}Resizables.notify("onResize",this,A);this.draw(B);if(this.options.change){this.options.change(this)}if(Prototype.Browser.WebKit){window.scrollBy(0,0)}Event.stop(A)},finishResize:function(A,B){this.resizing=false;Resizables.notify("onEnd",this,A);if(this.options.zindex){this.element.style.zIndex=this.originalZ}Resizable._resizing[this.element]=false;Resizables.deactivate(this)},endResize:function(A){if(!this.resizing){return }this.finishResize(A,true);Event.stop(A)},draw:function(A){var G=[0,1].map(function(H){return(this.size[H]+A[H]-this.pointer[H])}.bind(this));if(this.options.snap){if(typeof this.options.snap=="function"){G=this.options.snap(G[0],G[1],this)}else{if(this.options.snap instanceof Array){G=G.map(function(H,I){return Math.round(H/this.options.snap[I])*this.options.snap[I]}.bind(this))}else{G=G.map(function(H){return Math.round(H/this.options.snap)*this.options.snap}.bind(this))}}}var C=(typeof (this.options.minWidth)=="function")?this.options.minWidth(this.element):this.options.minWidth;var E=(typeof (this.options.maxWidth)=="function")?this.options.maxWidth(this.element):this.options.maxWidth;var F=(typeof (this.options.minHeight)=="function")?this.options.minHeight(this.element):this.options.minHeight;var D=(typeof (this.options.maxHeight)=="function")?this.options.maxHeight(this.element):this.options.maxHeight;if(C&&G[0]<=C){G[0]=C}if(E&&G[0]>=E){G[0]=E}if(F&&G[1]<=F){G[1]=F}if(D&&G[1]>=D){G[1]=D}var B=this.element.style;if((!this.options.constraint)||(this.options.constraint=="horizontal")){B.width=G[0]+"px"}if((!this.options.constraint)||(this.options.constraint=="vertical")){B.height=G[1]+"px"}if(B.visibility=="hidden"){B.visibility=""}}}