(function(a){a(".story-actions-report").live("digg:flag",function(){a(this).die("click").replaceWith("Reported")});a(".story-actions-report").live("click",function(f){var j=a(this),l=DUI.parseItemId(j.parents(".story-item").attr("class"));DUI.Auth.requireLogin(function(){DUI.treq({target:f.target,url:"/ajax/flag",data:{item_id:l,referrer:document.referrer,location_id:DUI.digg_location_id}})},function(){DUI.Tooltip.load(j,"report")});f.preventDefault()})})($);
(function(a,f){function j(c,b){b=parseInt(c.text())+b;c.text(b+(b==1?" Reply":" Replies"));return b}function l(c){var b=a("#main-column h4:last");m+=c;b.text(m+(m==1?" Comment":" Comments"))}function n(c,b){var d=c.find("span").remove();c.text(b).prepend(d)}function u(){if(p){a("#comment-list").addClass("expanded");a(".collapsed").removeClass("collapsed")}else a(".expanded").removeClass("expanded")}function A(c){var b=c.offset().top+c.height(),d=a(window),e=d.scrollTop(),g=e+d.height();b=b-g+a("#feedback-bar").height();
b>0&&d.scrollTop(e+b);a("textarea",c).focus()}function v(c,b){var d=a("em.counter em",c);b.append(c);f.Countdown.add(+d.text(),d,f.parseItemId(c.attr("className"),{prefix:"thread-"}))}function q(c){var b=a(".comment-edit-content:first",c);if(b.length){b.remove();a(".comment-body",c).show();a(".comment-reply-options",c).show()}}function B(c){c=a("<div/>").html(c.replace(/\n/g,""));var b=a("br",c);b.length&&b.replaceWith("\n");return c.text()}var p,r=a("#item_id").val(),m=parseInt(a("#main-column h4:last").text()),
o=[["Show Hidden Comment","Hide Hidden Comment"],["Show Buried Comment","Show Buried Comment"]];m==a(".comment-thread").length&&a("#more-stories").remove();a(".comment-reply button[type=submit]").live("click",function(c){var b=a(this),d=b.closest("form");d=a("textarea",d);var e=a.trim(d.val()),g=e.length;if(g>3E4)f.SysMsg.show("Comment too long. Please shorten it and try again.","error");else g&&e!=d.attr("placeholder")&&"disabled"!==b.attr("disabled")&&b.attr("disabled","disabled");c.preventDefault()});
a(".comment-reply-content").live("submit",function(){var c=a(this);if(c.hasClass("disabled"))return false;f.treq({url:c.attr("action"),target:this,data:c.serializeObject()});c.addClass("disabled");return false}).live("digg:postedcomment",function(c,b){var d;c=a(this);var e=c.closest(".comment-thread");c.removeClass("disabled");a(".comment-reply button[type=submit]").removeAttr("disabled");if(e.length){if(e.closest("#comments-activity").length){d=a("#comment-list .thread-"+f.parseItemId(e.attr("className"),
{prefix:"thread-"}).replace(":","_"));f.SysMsg.show("Your reply has been posted!")}(d||e).trigger("digg:commentrepliedto",b);e.find(".reply-to-thread:last").hide().empty()}else{b=a(b.html);v(b,a("#comment-list"));b=a(this).find("textarea");b.val("").blur()}l(1);a("#no-comments-error").remove()}).live("digg:error",function(){a(this).removeClass("disabled")});a(".comment-thread").live("digg:commentrepliedto",function(c,b){a(b.html);c=a(this);v(a(b.html),c.find(".thread-replies:first").addClass("expanded"));
b=a(".comment:first > .comment-content > ul.comment-reply-options",c);if(b.length){replyCount=b.find(".option-toggle-replies").show();replyCount.length||a('<li class="option-toggle-replies"><a><span class="indicator"></span><span class="reply-count">0</span></a></li>').appendTo(b);j(b.find(".reply-count"),1)}}).live("digg:commentdugg digg:commentburied digg:commentneutral",function(c,b){var d=f.parseItemId(this.className,{prefix:"thread-"});if(c.type=="digg:commentneutral")b.action="un"+(b.action==
"digg"?"bury":"digg");a(".thread-"+d.replace(":","_")).trigger("digg:commentduggburied",b)}).live("digg:commentduggburied",function(c,b){var d=a(this),e=d.find(".comment-actions"),g=a(".comment-meta:first",d),h=a(".comment-toggle",g),w=b.action,x=b.diggs;b=b.buries;var k=x-b,y=a(".digg-count-net:first",d),i=y.text(),C=parseInt(i),s=d.find(".comment-digg").eq(0),t=d.find(".comment-bury").eq(0),z=a(".digg-count-raw:first span",d);if(w=="bury"){e.addClass("comment-buried").removeClass("comment-dugg");
s.removeClass("active");c.type!="digg:neutral"&&t.addClass("active");d.addClass("is-buried");g.removeClass("viewing-buried");n(h.toggleClass("bury",k>=0).find("a").removeClass("active"),o[+(k>=0)][0])}else{if(w=="digg"){e.addClass("comment-dugg").removeClass("comment-buried");t.removeClass("active");c.type!="digg:neutral"&&s.addClass("active")}else{e.removeClass("comment-buried comment-dugg");d.removeClass("is-buried");s.removeClass("active");t.removeClass("active")}if(k<0){h.removeClass("bury");
C>=0&&g.addClass("viewing-buried");n(h.find("a"),o[0][+g.hasClass("viewing-buried")])}else{h.addClass("bury");g.removeClass("viewing-buried");n(h.find("a").removeClass("active"),o[1][0])}}z.eq(0).text(x);z.eq(1).text(b);if(k<=0)i=i.replace("+","");else if(i.indexOf("+"))i="+"+i;y.text(i.replace(parseInt(i),k))}).live("digg:commentdeleted",function(){var c=a(this),b=c.find(".comment-thread").length+1,d=c.parent().closest(".comment-thread");c.remove();l(-b);if(d.length){c=a(".option-toggle-replies:first",
d);j(c.find(".reply-count"),-1)||c.hide()}});a("#post-comment textarea").live("focusin",function(){a(".reply-actions","#post-comment").show()});a(".option-toggle-replies a").live("click",function(c){var b=a(this).closest(".comment-thread");if(a(".thread-replies",b).eq(0).css("display")!="none")b.addClass("collapsed").removeClass("expanded");else{b.addClass("expanded").removeClass("collapsed");a(".comment-thread",b).removeClass("collapsed")}c.preventDefault()});a(".comment-digg-counts li").live("click",
function(c){a(this).hide().siblings().toggle();c.preventDefault()});a(".comment-toggle a").live("click",function(c){var b=a(this).toggleClass("active"),d=b.closest(".comment-thread").toggleClass("is-buried");a(".comment-meta:first",d).toggleClass("viewing-buried");n(b,o[+b.parent().hasClass("bury")][+b.hasClass("active")]);c.preventDefault()});a(".option-reply a").live("click",function(c){var b=a(this),d=b.closest(".comment-thread"),e=f.parseItemId(d.attr("className"),{prefix:"thread-"}),g=d.find(".reply-to-thread:last"),
h=a("#reply-prototype").clone().removeAttr("id");f.Auth.requireLogin(function(){d.addClass("expanded");if(g.find(".comment-reply").length)g.show().find(".comment-reply").show();else{h.find("input[name=parent_id]").val(e);h.find("input[name=item_id]").val(r);g.append(h.show()).show()}A(g)},function(){f.Tooltip.load(b,"reply")});c.preventDefault()});a(".comment-edit a").live("click",function(c){var b,d;b=a(this);var e=a(this).closest(".comment-thread");if(b.hasClass("comment-delete"))f.treq({url:"/ajax/comments/delete",
target:this,data:{comment_id:f.parseItemId(e.attr("className"),{prefix:"thread-"})}});else if(!a(".comment-content:first .comment-edit-content",e).length){d=a(".comment-body:first",e);b=a("#edit-prototype").clone().removeAttr("id");a("textarea",b).val(B(d.html()));a("input[name=item_id]",b).val(r);a("input[name=comment_id]",b).val(f.parseItemId(e.attr("className"),{prefix:"thread-"}));a(".comment-reply-options",e).hide();b.show().insertAfter(d.hide())}c.preventDefault()});a(".comment-edit-content").live("submit",
function(c){f.treq({url:a(this).attr("action"),target:this,data:a(this).serializeObject()});c.preventDefault()}).live("digg:editsuccess",function(c,b){c=a(this);var d=c.closest(".comment-thread"),e=a(".comment-body:first",d);b&&b.html?e.replaceWith(a(b.html)):e.text(c.closest("form").find("textarea").val());q(d)});a(".comment-digg, .comment-bury","#main-column").live("click",function(){var c,b,d,e,g,h=a(this);f.Auth.requireLogin(function(){if(!h.hasClass("active")){c=h.closest(".comment-thread");
b=f.parseItemId(c.attr("className"),{prefix:"thread-"});d=h.hasClass("comment-digg")?1:-1;e=d>0?"digg":"bury";g=c.find(d>0?".comment-bury":".comment-digg").eq(0);if(g.hasClass("active"))d=0;f.treq({url:"/ajax/comments/setScore",target:h,data:{topic:f.getTopic(),comment_id:b,score:d,button:e}})}},function(){f.Tooltip.load(h,"diggbury")})});a("em.counter em").live("digg:countdown",function(c,b){a(this).text(b);if(!+b){c=a(this).closest(".comment-thread");a(".comment-edit",c).remove();q(c)}return false}).each(function(){var c=
a(this);f.Countdown.add(+c.text(),c,f.parseItemId(c.closest(".comment-thread").attr("className")))});a("#friend-activity-sorting a").live("click",function(c){c.preventDefault()}).live("mousedown",function(c){if(c.button!==2){var b=a(this),d=b.attr("href").replace("#sort-","");if(b.hasClass("active"))return false;a(".active","#friend-activity-sorting").removeClass("active");b.addClass("active");a(".friend-activity-container","#comments-activity").addClass("hidden");a("#"+d).removeClass("hidden");c.preventDefault()}});
a("#comment-sorting a").live("click",function(c){a(this).hasClass("ignore")||c.preventDefault()}).live("mousedown",function(c){if(c.button!==2){var b;c="/ajax/comments/get";b=a(this);if(b.hasClass("sort")&&!b.hasClass("active")){b=b.attr("href").substr(1);if(b=="most-dugg")c="/ajax/comments/getMostDugg";a("#comment-list").append('<span class="loader-large"></span>').find(".comment-thread").hide();f.treq({url:c,target:this,type:"get",data:{item_id:r,sort:b}});a("#comment-sorting .active").removeClass("active").addClass("deactivated");
a(this).addClass("active")}else if(b.hasClass("show-threads")){b.hide();p=b.hasClass("expand-all");a(p?".collapse-all":".expand-all","#comment-sorting").show();u()}}}).live("digg:success",function(c,b){if(b&&b.html){f.Countdown.abort();a("#comment-list").html(b.html);a("em.counter em").each(function(){var d=a(this);f.Countdown.add(+d.text(),d,f.parseItemId(d.closest(".comment-thread").attr("className")))});a("#comment-sorting .deactivated").removeClass("deactivated");u()}else a(this).trigger("digg:error",
{message:"Internal error - comments could not be loaded. Please <a href=http://about.new.digg.com/contact/bugreport/ target=_blank>report this bug</a>."});return false}).live("digg:error",function(){a(".loader-large").hide();a("#comment-list .comment-thread").show();a(this).removeClass("active");a("#comment-sorting .deactivated").removeClass("deactivated").addClass("active")});a(".comment-reply-content .cancel-reply").live("click",function(){a(this).closest(".comment-thread").find(".reply-to-thread:last").hide()});
a(".comment-edit-content .cancel-reply").live("click",function(){q(a(this).closest(".comment-thread"))})})($,DUI);
