(function($){$.fn.editable=function(a,b){if("disable"==a){$(this).data("disabled.editable",true);return}if("enable"==a){$(this).data("disabled.editable",false);return}if("destroy"==a){$(this).unbind($(this).data("event.editable")).removeData("disabled.editable").removeData("event.editable");return}var c=$.extend({},$.fn.editable.defaults,{target:a},b);var d=$.editable.types[c.type].plugin||function(){};var e=$.editable.types[c.type].submit||function(){};var f=$.editable.types[c.type].buttons||$.editable.types["defaults"].buttons;var g=$.editable.types[c.type].content||$.editable.types["defaults"].content;var h=$.editable.types[c.type].element||$.editable.types["defaults"].element;var i=$.editable.types[c.type].reset||$.editable.types["defaults"].reset;var j=c.callback||function(){};var k=c.onedit||function(){};var l=c.onsubmit||function(){};var m=c.onreset||function(){};var n=c.onerror||i;if(c.tooltip){$(this).attr("title",c.tooltip)}c.autowidth="auto"==c.width;c.autoheight="auto"==c.height;return this.each(function(){var a=this;var b=$(a).width();var o=$(a).height();$(this).data("event.editable",c.event);if(!$.trim($(this).html())){$(this).html(c.placeholder)}$(this).bind(c.event,function(m){if(true===$(this).data("disabled.editable")){return}if(a.editing){return}if(false===k.apply(this,[c,a])){return}m.preventDefault();m.stopPropagation();if(c.tooltip){$(a).removeAttr("title")}if(0==$(a).width()){c.width=b;c.height=o}else{if(c.width!="none"){c.width=c.autowidth?$(a).width():c.width}if(c.height!="none"){c.height=c.autoheight?$(a).height():c.height}}if($(this).html().toLowerCase().replace(/(;|")/g,"")==c.placeholder.toLowerCase().replace(/(;|")/g,"")){$(this).html("")}a.editing=true;a.revert=$(a).html();$(a).html("");var p=$("<form />");if(c.cssclass){if("inherit"==c.cssclass){p.attr("class",$(a).attr("class"))}else{p.attr("class",c.cssclass)}}if(c.style){if("inherit"==c.style){p.attr("style",$(a).attr("style"));p.css("display",$(a).css("display"))}else{p.attr("style",c.style)}}var q=h.apply(p,[c,a]);var r;if(c.loadurl){var s=setTimeout(function(){q.disabled=true;g.apply(p,[c.loadtext,c,a])},100);var t={};t[c.id]=a.id;if($.isFunction(c.loaddata)){$.extend(t,c.loaddata.apply(a,[a.revert,c]))}else{$.extend(t,c.loaddata)}$.ajax({type:c.loadtype,url:c.loadurl,data:t,async:false,success:function(a){window.clearTimeout(s);r=a;q.disabled=false}})}else if(c.data){r=c.data;if($.isFunction(c.data)){r=c.data.apply(a,[a.revert,c])}}else{r=a.revert}g.apply(p,[r,c,a]);q.attr("name",c.name);f.apply(p,[c,a]);$(a).append(p);d.apply(p,[c,a]);$(":input:visible:enabled:first",p).focus();if(c.select){q.select()}q.keydown(function(b){if(b.keyCode==27){b.preventDefault();i.apply(p,[c,a])}});var s;if("cancel"==c.onblur){q.blur(function(b){s=setTimeout(function(){i.apply(p,[c,a])},500)})}else if("submit"==c.onblur){q.blur(function(a){s=setTimeout(function(){p.submit()},200)})}else if($.isFunction(c.onblur)){q.blur(function(b){c.onblur.apply(a,[q.val(),c])})}else{q.blur(function(a){})}p.submit(function(b){if(s){clearTimeout(s)}b.preventDefault();if(false!==l.apply(p,[c,a])){if(false!==e.apply(p,[c,a])){if($.isFunction(c.target)){var d=c.target.apply(a,[q.val(),c]);$(a).html(d);a.editing=false;j.apply(a,[a.innerHTML,c]);if(!$.trim($(a).html())){$(a).html(c.placeholder)}}else{var f={};f[c.name]=q.val();f[c.id]=a.id;if($.isFunction(c.submitdata)){$.extend(f,c.submitdata.apply(a,[a.revert,c]))}else{$.extend(f,c.submitdata)}if("PUT"==c.method){f["_method"]="put"}$(a).html(c.indicator);var g={type:"POST",data:f,dataType:"json",url:c.target,success:function(b,d){if(g.dataType=="html"){$(a).html(b)}if(g.dataType=="json"){switch(b["status"]){case"duplicate":i.apply(p,[c,a]);$("#alert span").addClass("error").text("Looks like you added that one already! No cheating!").fadeIn();var e=203;var f=$(window).scrollTop();if(f>=e)$("#alert").slideToggle();window.clearTimeout(to);to=window.setTimeout(function(){$("#alert span").fadeOut();$("#newlistitem").autocomplete("enable");if(f>=e)$("#alert").slideToggle()},3e3);break;case"nodata":i.apply(p,[c,a]);$("#alert span").addClass("error").text("Hey man, that's empty!").fadeIn();var e=203;var f=$(window).scrollTop();if(f>=e)$("#alert").slideToggle();window.clearTimeout(to);to=window.setTimeout(function(){$("#alert span").fadeOut();$("#newlistitem").autocomplete("enable");if(f>=e)$("#alert").slideToggle()},3e3);break;case"success":$(a).html(b["newText"]);break;default:i.apply(p,[c,a]);$("#alert span").addClass("error").text("Uh oh. Looks like we weren't able to add that one!").fadeIn();var e=203;var f=$(window).scrollTop();if(f>=e)$("#alert").slideToggle();window.clearTimeout(to);to=window.setTimeout(function(){$("#alert span").fadeOut();$("#newlistitem").autocomplete("enable");if(f>=e)$("#alert").slideToggle()},3e3);break}return false}a.editing=false;j.apply(a,[b,c]);if(!$.trim($(a).html())){$(a).html(c.placeholder)}},error:function(b,d,e){n.apply(p,[c,a,b])}};$.extend(g,c.ajaxoptions);$.ajax(g)}}}$(a).attr("title",c.tooltip);return false})});this.reset=function(b){if(this.editing){if(false!==m.apply(b,[c,a])){$(a).html(a.revert);a.editing=false;if(!$.trim($(a).html())){$(a).html(c.placeholder)}if(c.tooltip){$(a).attr("title",c.tooltip)}}}}})};$.editable={types:{defaults:{element:function(a,b){var c=$('<input type="hidden"></input>');$(this).append(c);return c},content:function(a,b,c){$(":input:first",this).val(a)},reset:function(a,b){b.reset(this)},buttons:function(a,b){var c=this;if(a.submit){if(a.submit.match(/>$/)){var d=$(a.submit).click(function(){if(d.attr("type")!="submit"){c.submit()}})}else{var d=$('<button type="submit" />');d.html(a.submit)}$(this).append(d)}if(a.cancel){if(a.cancel.match(/>$/)){var e=$(a.cancel)}else{var e=$('<button type="cancel" />');e.html(a.cancel)}$(this).append(e);$(e).click(function(d){if($.isFunction($.editable.types[a.type].reset)){var e=$.editable.types[a.type].reset}else{var e=$.editable.types["defaults"].reset}e.apply(c,[a,b]);return false})}}},text:{element:function(a,b){var c=$("<input />");if(a.width!="none"){c.width(a.width)}if(a.height!="none"){c.height(a.height)}c.attr("autocomplete","off");$(this).append(c);return c}},textarea:{element:function(a,b){var c=$("<textarea />");if(a.rows){c.attr("rows",a.rows)}else if(a.height!="none"){c.height(a.height)}if(a.cols){c.attr("cols",a.cols)}else if(a.width!="none"){c.width(a.width)}$(this).append(c);return c}},select:{element:function(a,b){var c=$("<select />");$(this).append(c);return c},content:function(data,settings,original){if(String==data.constructor){eval("var json = "+data)}else{var json=data}for(var key in json){if(!json.hasOwnProperty(key)){continue}if("selected"==key){continue}var option=$("<option />").val(key).append(json[key]);$("select",this).append(option)}$("select",this).children().each(function(){if($(this).val()==json["selected"]||$(this).text()==$.trim(original.revert)){$(this).attr("selected","selected")}})}}},addInputType:function(a,b){$.editable.types[a]=b}};$.fn.editable.defaults={name:"value",id:"id",type:"text",width:"auto",height:"auto",event:"click.editable",onblur:"cancel",loadtype:"GET",loadtext:"Loading...",placeholder:"Click to edit",loaddata:{},submitdata:{},ajaxoptions:{},method:function(a,b){}}})(jQuery)
