/**
 * Inline editor feature for RightJS
 *  http://rightjs.org/ui/in-edit
 *
 * Copyright (C) 2009-2010 Nikolay Nemshilov
 */
var InEdit=RightJS.InEdit=function(i,a){var g=a.$,m=a.$w,n=a.Xhr,o=a.Object,j=a.Element,k=a.Input,p=new a.Wrapper(a.Element,{initialize:function(b){this.$super("div",{"class":"rui-spinner"});this.dots=[];for(var e=0;e<(b||4);e++)this.dots.push(new a.Element("div"));this.dots[0].addClass("glowing");this.insert(this.dots);a(this.shift).bind(this).periodical(300)},shift:function(){if(this.visible()){var b=this.dots.pop();this.dots.unshift(b);this.insert(b,"top")}}}),d=new (function(b,e){if(!e){e=b;b=
"DIV"}var f=new a.Wrapper(a.Element.Wrappers[b]||a.Element,{initialize:function(h,c){this.key=h;var l=[{"class":"rui-"+h}];this instanceof a.Input||this instanceof a.Form||l.unshift(b);this.$super.apply(this,l);if(a.isString(c))c=a.$(c);if(c instanceof a.Element){this._=c._;if("$listeners"in c)c.$listeners=c.$listeners;c={}}this.setOptions(c,this);return this},setOptions:function(h,c){c=c||this;a.Options.setOptions.call(this,a.Object.merge(h,eval("("+(c.get("data-"+this.key)||"{}")+")")));return this}});
f=new a.Wrapper(f,e);a.Observer.createShortcuts(f.prototype,f.EVENTS||[]);return f})("FORM",{extend:{version:"2.0.0",EVENTS:m("show hide send update"),Options:{url:null,name:"text",method:"put",type:"text",toggle:null,update:true,Xhr:{}},i18n:{Save:"Save",Cancel:"Cancel"},current:null},initialize:function(b,e){this.element=g(b);this.$super("in-edit",e).set("action",this.options.url).insert([this.field=new k({type:this.options.type,name:this.options.name,"class":"field"}),this.spinner=new p(4),this.submit=
new k({type:"submit","class":"submit",value:d.i18n.Save}),this.cancel=new j("a",{"class":"cancel",href:"#",html:d.i18n.Cancel})]).onClick(this.clicked).onSubmit(this.send)},show:function(){if(d.current!==this){d.current&&d.current.hide();this.oldContent=this.element.html();a(["file","password"]).include(this.options.type)||this.field.setValue(this.oldContent);this.element.update(this);this.spinner.hide();this.submit.show();this.options.toggle&&g(this.options.toggle).hide()}this.options.type!=="file"&&
this.field.focus();d.current=this;return this.fire("show")},hide:function(){this.element._.innerHTML=this.oldContent;this.xhr&&this.xhr.cancel();return this.finish()},send:function(b){b&&b.stop();this.spinner.show().resize(this.submit.size());this.submit.hide();this.xhr=(new n(this.options.url,o.merge(this.options.Xhr,{method:this.options.method,spinner:this.spinner,onComplete:a(this.receive).bind(this)}))).send(this);return this.fire("send")},finish:function(){this.options.toggle&&g(this.options.toggle).show();
d.current=null;return this.fire("hide")},receive:function(){if(this.options.update){this.element.update(this.xhr.text);this.fire("update")}this.xhr=null;this.finish()},clicked:function(b){if(b.target===this.cancel){b.stop();this.hide()}}});g(i).onKeydown(function(b){b.keyCode===27&&d.current&&d.current.hide()});j.include({inEdit:function(b){return(new d(this,b)).show()}});i.write('<style type="text/css">div.rui-spinner,div.rui-spinner div{margin:0;padding:0;border:none;background:none;list-style:none;font-weight:normal;float:none;display:inline-block; *display:inline; *zoom:1;border-radius:.12em;-moz-border-radius:.12em;-webkit-border-radius:.12em}div.rui-spinner{text-align:center;white-space:nowrap;background:#EEE;border:1px solid #DDD;height:1.2em;padding:0 .2em}div.rui-spinner div{width:.4em;height:70%;background:#BBB;margin-left:1px}div.rui-spinner div:first-child{margin-left:0}div.rui-spinner div.glowing{background:#777}form.rui-in-edit,form.rui-in-edit .cancel{margin:0;padding:0;float:none;position:static}form.rui-in-edit{display:inline-block; *display:inline; *zoom:1;border:none;background:none}form.rui-in-edit div.rui-spinner{margin-right:.2em}form.rui-in-edit div.rui-spinner div{margin-top:.2em}form.rui-in-edit textarea.field{width:100%;margin-bottom:.5em}form.rui-in-edit .field,form.rui-in-edit .submit{margin-right:.2em}form.rui-in-edit,form.rui-in-edit .field,form.rui-in-edit .submit,form.rui-in-edit div.rui-spinner,form.rui-in-edit .cancel{vertical-align:middle}</style>');
return d}(document,RightJS);