$.extend($.namespace("core.Comments"),{error_template:'<p class="%(type)">%(message)</p>',init_markdown_help:function(){$("#MarkdownHelp").append(' Check out the <a href="javascript:void(0);" onclick="core.Comments.launch_markdown_sheet();" id="MarkDownCheatSheetLink">cheat sheet</a> if you are not familiar.')},launch_markdown_sheet:function(){$("#MarkDownCheatSheet").fadeIn();core.scroll_to("#MarkDownCheatSheet")},render_comment:function(a){$("#comments, #CommentsList").removeClass("hidden");$("#CommentsList li:last-child").removeClass("last-child");$("#CommentsList").append(a);$("#CommentsList li:last-child").addClass("last-child");$("#CommentForm").find("p.stand-by").fadeOut("slow");core.scroll_to("#CommentsList li:last-child");$("#CommentsListCount").text($("#CommentsList li").size())},parse_comment_form:function(a){$("#CommentForm").find("p.stand-by").fadeOut("slow");if(a.errors){for(error in a.errors){if(error=="__all__"){for(e in a.errors[error]){$("#CommentForm").prepend(core.render_template(this.error_template,{message:a.errors[error][e],type:"error"}))}}else{$("#CommentForm-"+error).parent().prepend(core.render_template(this.error_template,{message:a.errors[error],type:"error"}))}}}else{if(a.notifications){for(n in a.notifications){$("#CommentForm").prepend(core.render_template(this.error_template,{message:a.notifications[n][1],type:a.notifications[n][0]}))}}if(a.comment){$("#CommentForm").prepend(core.render_template(this.error_template,{message:"Adding your comment, please stand by.",type:"stand-by"}));$.ajax({url:a.comment,type:"GET",processData:false,dataType:"html",success:this.render_comment.bind(this)})}$("#CommentForm").find("textarea").val("")}$("#CommentForm").find("input[@type=submit]").attr("disabled",false)},submit_comment_form:function(){$("#CommentForm").find("p.error, p.warning, p.success, p.stand-by").fadeOut("slow");$("#CommentForm").find("input[@type=submit]").attr("disabled",true);$("#CommentForm").prepend(core.render_template(this.error_template,{message:"Submitting your comment, please stand by.",type:"stand-by"}));$.ajax({url:$("#CommentForm").attr("action"),type:"POST",processData:false,data:$("#CommentForm").serialize(),dataType:"json",contentType:"application/json",success:this.parse_comment_form.bind(this)});core.scroll_to("#add-comment");return false},init:function(){this.init_markdown_help();$("#CommentForm").submit(this.submit_comment_form.bind(this))}});$(function(){core.Comments.init()});