var Spinner=new Class({Extends:Mask,Implements:Chain,options:{"class":"spinner",containerPosition:{},content:{"class":"spinner-content"},messageContainer:{"class":"spinner-msg"},img:{"class":"spinner-img"},fxOptions:{link:"chain"}},initialize:function(c,a){this.target=document.id(c)||document.id(document.body);this.target.store("spinner",this);this.setOptions(a);this.render();this.inject();var b=function(){this.active=false}.bind(this);this.addEvents({hide:b,show:b})},render:function(){this.parent();this.element.set("id",this.options.id||"spinner-"+String.uniqueID());this.content=document.id(this.options.content)||new Element("div",this.options.content);this.content.inject(this.element);if(this.options.message){this.msg=document.id(this.options.message)||new Element("p",this.options.messageContainer).appendText(this.options.message);this.msg.inject(this.content)}if(this.options.img){this.img=document.id(this.options.img)||new Element("div",this.options.img);this.img.inject(this.content)}this.element.set("tween",this.options.fxOptions)},show:function(a){if(this.active){return this.chain(this.show.bind(this))}if(!this.hidden){this.callChain.delay(20,this);return this}this.active=true;return this.parent(a)},showMask:function(a){var b=function(){this.content.position(Object.merge({relativeTo:this.element},this.options.containerPosition))}.bind(this);if(a){this.parent();b()}else{if(!this.options.style.opacity){this.options.style.opacity=this.element.getStyle("opacity").toFloat()}this.element.setStyles({display:"block",opacity:0}).tween("opacity",this.options.style.opacity);b();this.hidden=false;this.fireEvent("show");this.callChain()}},hide:function(a){if(this.active){return this.chain(this.hide.bind(this))}if(this.hidden){this.callChain.delay(20,this);return this}this.active=true;return this.parent(a)},hideMask:function(a){if(a){return this.parent()}this.element.tween("opacity",0).get("tween").chain(function(){this.element.setStyle("display","none");this.hidden=true;this.fireEvent("hide");this.callChain()}.bind(this))},destroy:function(){this.content.destroy();this.parent();this.target.eliminate("spinner")}});Request=Class.refactor(Request,{options:{useSpinner:false,spinnerOptions:{},spinnerTarget:false},initialize:function(a){this._send=this.send;this.send=function(b){var c=this.getSpinner();if(c){c.chain(this._send.pass(b,this)).show()}else{this._send(b)}return this};this.previous(a)},getSpinner:function(){if(!this.spinner){var b=document.id(this.options.spinnerTarget)||document.id(this.options.update);if(this.options.useSpinner&&b){b.set("spinner",this.options.spinnerOptions);var a=this.spinner=b.get("spinner");["complete","exception","cancel"].each(function(c){this.addEvent(c,a.hide.bind(a))},this)}}return this.spinner}});Element.Properties.spinner={set:function(a){var b=this.retrieve("spinner");if(b){b.destroy()}return this.eliminate("spinner").store("spinner:options",a)},get:function(){var a=this.retrieve("spinner");if(!a){a=new Spinner(this,this.retrieve("spinner:options"));this.store("spinner",a)}return a}};Element.implement({spin:function(a){if(a){this.set("spinner",a)}this.get("spinner").show();return this},unspin:function(){this.get("spinner").hide();return this}});