/* Copyright (C) 2007 - 2011 YOOtheme GmbH, YOOtheme Proprietary Use License (http://www.yootheme.com/license) */

(function(d){var e=function(){};e.prototype=d.extend(e.prototype,{name:"Update",options:{msgPerformingUpdate:"Performing Update...",msgFinished:"Update successfull...Reload page to continue working."},initialize:function(b,a){this.options=d.extend({},this.options,a);var c=this;this.form=b;b.find("button.update").bind("click",function(){d(this).parent().remove();c.step()})},step:function(){var b=this.form,a=this;d.ajax({url:b.attr("action"),type:"post",datatype:"json",data:b.serialize(),beforeSend:function(){a.addMessage(a.options.msgPerformingUpdate,
"loading")},success:function(c){c=d.parseJSON(c);b.find("div.message-box").find("div.message").last().removeClass("loading");c.error?a.addMessage(c.message,"error"):(a.addMessage(c.message),c["continue"]?a.step():(a.addMessage(a.options.msgFinished,"success"),b.find("button.update").removeEvents()))},error:function(c,d){b.find("div.message-box").find("div.message").last().removeClass("loading");a.addMessage(d,"error")}})},addMessage:function(b,a){b=d('<div class="message">').text(b).appendTo(this.form.find("div.message-box"));
a&&b.addClass(a)}});d.fn[e.prototype.name]=function(){var b=arguments,a=b[0]?b[0]:null;return this.each(function(){var c=d(this);if(e.prototype[a]&&c.data(e.prototype.name)&&a!="initialize")c.data(e.prototype.name)[a].apply(c.data(e.prototype.name),Array.prototype.slice.call(b,1));else if(!a||d.isPlainObject(a)){var f=new e;e.prototype.initialize&&f.initialize.apply(f,d.merge([c],b));c.data(e.prototype.name,f)}else d.error("Method "+a+" does not exist on jQuery."+e.name)})}})(jQuery);
