var BLOG_BODY_ID="pg-blog";var HOME_BODY_ID="page-home";var RECENT_POST_DISPLAY_ID="recent-blog-container";var API_URL="http://disqus.com/api";var USER_API_KEY="ZcpH9grNCx2ri60xDQazGYVwQsIchtMy5dtsRtVM3K5Gg0JmZ6NP5JcPrZ2kRyji";var THREAD_BY_URL="/get_thread_by_url/";var THREADS=[];var THREAD_IDS=[];var THREAD_URLS=[];
var THREAD_POSTS="/get_thread_posts/";var POSTS=[];var POST_TITLE_LINK_CLASS="post-title-link";var POST_TITLE_LINKS=[];var POST_COMMENT_COUNT_CLASS="post-comment-count";var POST_COMMENT_COUNTS=[];var POST_RECENT_COMMENT_CLASS="post-recent-comment";var POST_RECENT_COMMENTS=[];var RECENT_COMMENT_LIMIT=35;
$(document).ready(function(){if(document.body.id==BLOG_BODY_ID||$("#"+RECENT_POST_DISPLAY_ID)){findPosts();}});function findPosts(){POSTS=$(".post");POST_TITLE_LINKS=$("."+POST_TITLE_LINK_CLASS);POST_COMMENT_COUNTS=$("."+POST_COMMENT_COUNT_CLASS);POST_RECENT_COMMENTS=$("."+POST_RECENT_COMMENT_CLASS);
if(document.body.id==HOME_BODY_ID){POST_TITLE_LINKS.each(function(a){_getThreadByUrl($(this).attr("href"));});}else{POST_COMMENT_COUNTS.each(function(a){var b=$(this).attr("href").split("#");_getThreadByUrl(b[0]);});}}function getThreadList(){}function _getThreadByUrl(a){if(a.indexOf("http")!==0){if(a.indexOf("/")!==0){a="/"+a;
}a=window.location.protocol+"//"+window.location.host+a;}$.ajax({url:API_URL+THREAD_BY_URL,data:{"forum_api_key":FORUM_API_KEY,"url":a,"api_version":"1.1","api_response_format":"jsonp:_handleThreadByUrl"},dataType:"script",type:"GET",cache:true});}function _getThreadPosts(a){$.ajax({url:API_URL+THREAD_POSTS,data:{"user_api_key":USER_API_KEY,"thread_id":a,"limit":1,"api_version":"1.1","api_response_format":"jsonp:_handleThreadPosts"},dataType:"script",type:"GET",cache:true});
}function _handleThreadByUrl(a){if(a.message){if(a.message!=null){THREAD_IDS.push(a.message.id);THREAD_URLS.push(a.message.url);}if(a.message!=null){_updateCommentCount(a.message.num_comments,a.message.url);}if(document.body.id==BLOG_BODY_ID&&a.message!=null){_getThreadPosts(a.message.id);}}}function _handleThreadPosts(d){if(d.message[0]!=null&&d.message[0].status!="killed"){var f=d.message[0].message;
var b=truncateString(f,RECENT_COMMENT_LIMIT);if(!d.message[0].author){var a="Guest";}else{var a=d.message[0].author.username;var e=d.message[0].author.display_name;}var c=d.message[0].thread.url;}POST_TITLE_LINKS.each(function(h){var g=$(POST_TITLE_LINKS[h]).attr("href");if(g.indexOf("http")!==0){if(g.indexOf("/")!==0){g="/"+g;
}g=window.location.protocol+"//"+window.location.host+g;}if(c==g){if(e){$(POST_RECENT_COMMENTS[h]).html("Latest Comment by "+e+": "+b);}else{$(POST_RECENT_COMMENTS[h]).html("Latest Comment by "+a+": "+b);}}});}function _updateCommentCount(b,a){if(document.body.id==HOME_BODY_ID){POST_TITLE_LINKS.each(function(d){var c=$(this).attr("href");
if(c.indexOf("http")!==0){if(c.indexOf("/")!==0){c="/"+c;}c=window.location.protocol+"//"+window.location.host+c;}if(a==c){if(b!=1){$(POST_COMMENT_COUNTS[d]).html(b+" Comments");}else{$(POST_COMMENT_COUNTS[d]).html(b+" Comment");}}});}else{POST_COMMENT_COUNTS.each(function(d){var c=$(this).attr("href");
if(c.indexOf("http")!==0){if(c.indexOf("/")!==0){c="/"+c;}c=window.location.protocol+"//"+window.location.host+c;}if(a+"#disqus_thread"==c){if(b!=1){$(POST_COMMENT_COUNTS[d]).html(b+" Comments");}else{$(POST_COMMENT_COUNTS[d]).html(b+" Comment");}}});}}function truncateString(d,a){var c,b;if("string"!==typeof(d)){return"";
}c=d.split("");if(c.length>a){for(b=c.length-1;b>-1;--b){if(b>a){c.length=b;}else{if(" "===c[b]){c.length=b;break;}}}c.push("...");}return c.join("");}