(function(a){a.fn.ajaxSubmit.debug=true;a.fn.commentForm=function(m){var b=a.extend({},{speed:"slow",entryId:0,parentId:0,leaveCommentMsg:"Leave a comment...",replySelector:"a.reply",onSuccess:null,target:".comments-open-content"},m);return this.each(function(){var c=a(this),e=c.attr("id");c.attr("action");c.attr("method");var j=a("[name=entry_id]").val();if(!j)j=b.entryId;c.append('<div class="spinner"></div><div class="spinner-status"></div>');c.find("textarea").unbind("focus").val(b.leaveCommentMsg).focus(function(){a(this).val()==
b.leaveCommentMsg&&a(this).val("")});c.find("input#comment-preview").hide();c.submit(function(){var k=a(this),d=a("#comment-text",this).val(),h=a("#comment-author",this).val();a("#comment-email",this).val();var l=a("#comment-url",this).val();a(this).find("[name=ajax]").val("1");a(this).find("[name=entry_id]").val(j);a(this).find("[name=preview]").val("0");a(this).find("[name=parent_id]").val(b.parentId);a(this).find("[name=armor]").val(mt.blog.comments.armor);a(this).ajaxSubmit({contentType:"application/x-www-form-urlencoded; charset=utf-8",
iframe:false,type:"post",dataType:null,clearForm:true,beforeSubmit:function(i){a.param(i);a("#"+e+" .spinner, #"+e+" .spinner-status").show()},error:function(i,f){alert(i+f)},success:function(){a("#"+e+" .spinner, #"+e+" .spinner-status").fadeOut();var i=typeof b.target=="object"?b.target:a(b.target+":first"),f=a('<div id="commentPreview" class="comment"><a name="commentPreview"/>    <div class="inner">\t<div class="comment-header">\t    <div class="asset-meta">\t\t<span class="byline">\t\t    <span class="vcard author"><a id="authorLink" title="" href="" rel="nofollow"></a></span>\t\t    | <a id="commentPreviewLink" href=""><abbr class="published" title=""></abbr></a>\t\t    \t\t</span>\t    </div>\t</div>\t<div class="comment-content">\t</div>    </div></div>');
d=d.replace(/[\n]/g,"<br/>");a(f).find("div.comment-content:first").html(d);var g=a.fn.movabletype.getUser();a("#authorLink",f).attr("title",g&&g.url?g.url:l).attr("href",g&&g.url?g.url:l).text(g&&g.name?g.name:h);nd=new Date;a("#commentPreviewLink",f).attr("href",location.href).find("abbr").attr("title",nd.toLocaleString()).text(nd.toLocaleString());replyWrapper=a('<div style="margin-left:20px;" class="comment-replies"></div>');b.parentId>0&&a(f).appendTo(replyWrapper);a(i).after(b.parentId>0?replyWrapper:
f);if(b.onSuccess)b.onSuccess(k,b.parentId>0?replyWrapper:f,0)}});return false})})};a.fn.reply=function(m){var b={speed:"slow",sourceForm:a("#comments-form"),target:"#comments-list"},c=a.extend({},b,m),e=Array(),j=function(){var k=a(this),d=a(this).closest(".comment").attr("id").substr(8);a(this).closest(".byline").find(".vcard.author").html();if(e[d])if(k.hasClass("expanded")){e[d].slideUp(c.speed);a(this).removeClass("expanded").addClass("collapsed")}else if(k.hasClass("collapsed")){e[d].slideDown(c.speed);
a(this).addClass("expanded").removeClass("collapsed")}else alert("Fatal error. A form was never initialized for this element.");else{var h=c.sourceForm.clone(),l=h.attr("id")+"-"+d;h.hide().attr("id",l);a(this).parents("div.comment:first").after(h);h.commentForm({parentId:d,target:a(this).parents("div.comment:first"),onSuccess:function(i,f){k.removeClass("expanded").addClass("collapsed");i.slideUp("fast",function(){f.slideDown(c.speed)})}});e[d]=h;a(this).addClass("expanded");e[d].slideDown(c.speed)}};
return this.each(function(){a(this).click(j)})}})(jQuery);

