$(document).ready(function(){$(".reply-button").live("click",function(d){var c=$(this);comment_form=c.closest("li").find(".post-comment:first");if(c.hasClass("disabled-button")){c.removeClass("disabled-button");comment_form.hide()}else{c.addClass("disabled-button");comment_form.show()}return false});$(".post-comment").live("submit",function(e){if($("body").data("disabled")){return false}var c=$(this).find(".reply-button");c.removeClass("disabled-button");$("body").data("disabled",true);$("div.notification").remove();$(this).find("div.notification").hide();var d=$(this).find("textarea").val();var f={"data[msg]":d};$.post($(this).attr("action"),f,function(i){$("body").data("disabled",false);if(i.success){var h=$(i.message);h.hide();if(i.type=="regular"){$("#comment-"+i.id+" .subreply ul:first").prepend(h);$("#comment-"+i.id+" textarea:first").val("");$("#comment-"+i.id+" .post-comment:first").hide();$("#comment-"+i.id+" a.disabled-button").removeClass("disabled-button")}else{$("#comments-list").prepend(h);$("#comments textarea:first").val("")}h.fadeIn()}else{var g=$('<div class="notification '+i.status+'">'+i.message+"</div>");g.hide();if(i.type=="regular"){$("#comment-"+i.id+" form:first").prepend(g)}else{$("#comments").prepend(g)}g.slideDown()}},"json");return false});$("div.vote a").live("click",function(){$.getJSON($(this).attr("href"),null,function(d){if(!d.success){return}var e=d.type.substr(0,1)+d.id;var c=$("#"+e).text();$("#"+e).text(parseInt(c)+1)});return false});$("a.report-button").live("click",function(){$.getJSON($(this).attr("href"),null,function(c){if(!c.message){return}$("#comment-"+c.id+" a.report-button:first").text(c.message);$("#comment-"+c.id+" a.report-button:first").click(function(){return false})});return false});jQuery.fn.sort=function(){return this.pushStack([].sort.apply(this,arguments),[])};function b(d,c){return parseInt($(d).attr("rat"))>parseInt($(c).attr("rat"))?-1:1}function a(d,c){return parseInt($(d).attr("ref"))>parseInt($(c).attr("ref"))?1:-1}$("#toggle-sort a").click(function(){if($(this).data("tog")){$(this).html("Sort Comments by Date");$("#comments-list").append($("#comments-list li").sort(b));$(this).data("tog",false)}else{$(this).html("Sort Comments by Rating");$("#comments-list").append($("#comments-list li").sort(a));$(this).data("tog",true)}return false})});
