/*!
 * Shouting At The Internet jQuery JavaScript Library v1.0
 * http://jackedmanager.com/modules/sati
 *
 * Copyright 2011, Nick Pettazzoni
 * Licensed under the Apache Version 2.0 License.
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Includes: jQuery JavaScript Library
 * http://jquery.com
 * Copyright 2010, John Resig
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * Date: Sun Feb 13 02:23:48 2010 -0500
 */
function ISODateString(b){function a(c){return c<10?"0"+c:c}return b.getUTCFullYear()+"-"+a(b.getUTCMonth()+1)+"-"+a(b.getUTCDate())+"T"+a(b.getUTCHours())+":"+a(b.getUTCMinutes())+":"+a(b.getUTCSeconds())+"Z"}(function(b){var a={init:function(c){settings={myself:this,postID:0,spinnerHTML:'<img src="/images/layout/comments-spinner.gif" /> Loading comments...'};if(c){b.extend(settings,c)}b(this).data("thread",[]);b(this).data("settings",settings);b(this).data("replyForm",b('<div class="commentForm" id="replyForm-'+b(this).data("settings").postID+'"><input type="hidden" name="reply-toID" />Username:<br /><input name="replyUsername" /><br />Email (not shown, used only for generating <a href="http://gravatar.com" target="_blank">avatars</a>):<br /><input name="replyEmail" /><br />Comment:<br /><textarea name="replyBody" rows="4" cols="42"></textarea><br /><button name="cancelReply">Cancel</button> <button name="replySubmit">Submit</button></div>'));this.each(function(){var d=b('<div id="saticontainer-'+b(this).data("settings").postID+'"></div>');b(this).append(d);b(this).data("parentContainer",d);b(this).satify("loadThread")})},toggleSpinner:function(c){if(c=="off"){b(this).data("parentContainer").children("span#satispinner").slideUp("fast",function(){b(this).remove()})}else{b(this).data("parentContainer").append('<span id="satispinner">'+b(this).data("settings").spinnerHTML+"")}},loadThread:function(){b(this).satify("toggleSpinner","on");var c=b(this);API.call({action:"getCommentThreadForPost",args:{postID:b(this).data("settings").postID},onComplete:function(d){c.data("commentThread",d);c.satify("refreshDisplay")},onFailure:function(d){c.data("commentThread",[]);c.satify("refreshDisplay")}})},refreshDisplay:function(){if(b(this).data("commentThread").length==0){b(this).satify("toggleSpinner","off");b(this).data("parentContainer").append('<p class="noComments">No one has commented yet. Be the first!</p>')}else{b(this).satify("toggleSpinner","off");b(this).satify("parseThread",b(this).data("commentThread"),b(this).data("parentContainer"),false)}b(this).data("parentContainer").append('<p><a href="#" id="comment-on-'+b(this).data("settings").postID+'" class="postComment">Comment</a></p>');b(this).satify("bindCommentButton",b(this).data("settings").postID)},parseThread:function(d,h,j){var e=b('<div class="replyContainer"></div>');if(j==true){h.after(e)}else{h.append(e)}for(comment in d){var g=(d[comment].email=="")?"none":d[comment].email;var c=new Date(d[comment]["date"]*1000);var f=ISODateString(c);var i=b('<div class="commentContainer" id="comment-'+d[comment].id+'"><img src="http://gravatar.com/avatar/'+g+"?s=50&d="+JACKED_ROOT_PATH+'images/avatar_default.png" /><img src="'+JACKED_ROOT_PATH+'images/layout/comment_tail.png" /><div class="commentText"><p class="comment_by">'+d[comment]["name"]+':</p><br /><p class="comment_body">'+d[comment].comment+'</p><br /><p class="comment_meta"><abbr class="timeago" title="'+f+'">'+c.toLocaleString()+'</abbr> <a href="#" id="reply-to-'+d[comment].id+'" class="postReply">Reply</a></p></div><div class="cleanup"></div></div>');e.append(i);b(this).satify("bindReplyButton",d[comment].id);if(d[comment].replies.length!=0){b(this).satify("parseThread",d[comment].replies,e,false)}}jQuery("abbr.timeago").timeago()},bindReplyButton:function(e){var d=b("#reply-to-"+e);var c=b(this);d.click(function(f){f.preventDefault();b(this).after(c.data("replyForm").slideDown("fast"));c.satify("replyFormSetData",API.getName(),API.getEmail(),e)})},bindCommentButton:function(c){var e=b("#comment-on-"+c);var d=b(this);e.click(function(f){f.preventDefault();b(this).before(d.data("replyForm").slideDown("fast"));d.satify("replyFormSetData",API.getName(),API.getEmail(),0)})},replyFormSetData:function(g,d,e){var f="#replyForm-"+b(this).data("settings").postID;b(f+" input[name=reply-toID]").val(e);b(f+" input[name=replyEmail]").val(d);b(f+" input[name=replyUsername]").val(g);b(f+" textarea[name=replyBody]").val("");var c=b(this);b(f+" button[name=cancelReply]").unbind("click");b(f+" button[name=cancelReply]").click(function(h){h.preventDefault();c.data("replyForm").slideUp("fast")});b(f+" button[name=replySubmit]").unbind("click");b(f+" button[name=replySubmit]").click(function(h){h.preventDefault();c.satify("replyFormSubmit")})},replyFormSubmit:function(){var c=b(this).data("settings").postID;var i="#replyForm-"+c;var f=b(i+" input[name=reply-toID]").val();var e=b(i+" input[name=replyEmail]").val();var h=b(i+" input[name=replyUsername]").val();var g=b(i+" textarea[name=replyBody]").val();var d=b(this);API.call({action:"postComment",args:{comment:g,postID:c,"reply-to":f,email:e,name:h},onComplete:function(j){d.satify("parseThread",j,d.data("replyForm"),true);d.data("replyForm").slideUp("fast")},onFailure:function(j){alert("NO. "+j.lolReason)}})}};b.fn.satify=function(c){if(a[c]){return a[c].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof c==="object"||!c){return a.init.apply(this,arguments)}else{b.error("Method "+c+" does not exist on jQuery.satify")}}}})(jQuery);
