var commentPanelHtml="";var commentIdArray=[];var presenceArray=[];var topicArray=[];var keywordArray=[];var isInEditMode=false;$(function(){if(window.XMLHttpRequest){$("#jsWarning").remove()}$("#pollForNewComments").attr("checked","checked");$.ajax({url:"/api/getlatestdiscussion/",dataType:"json",cache:false,success:populatePage,error:function(a){displayMessage("Error: Could not load recent comments.")}});$(".commentContent *").live("click",commentClicked);$(".commentAuthor").live("click",commentClicked);$(".replyButton").live("click",createReponsePanel);$(".postButton").live("click",postComment);$(".previewButton").live("click",previewComment);$(".uploadButton").live("click",uploadFile);$(".hrefButton").live("click",hrefSelected);$(".strongButton").live("click",boldSelected);$(".emphasisButton").live("click",italicSelected);$("#activeThread").change(activePostChanged);$("#activeThreadLink").click(displayPostLightBox);$("#quickComment").click(displayQuickComment);$("#moreLink").click(displayMoreComments)});function populatePage(b,a){if(b==null||b.error){displayMessage("Error: Page data could not be parsed.");return}cookieKey=b.siteUrlHash;populateUserInformation();if(parseInt(b.refreshInterval)>0){secondsToRefresh=b.refreshInterval}if(parseInt(b.sleepDelay)>0){sleepDelay=b.sleepDelay}populateLatestPosts(b.favouredThreadType,b.latestPostTitles);addCommentsToTree(b.latestComments,a,true,true);updateConnectionStatusDisplay(1);updatePollingDisplay();setTimeout(lifecyclePoller,secondsToRefresh*1000)}function populateUserInformation(){var c=getCookie("commentAuthor");var b=getCookie("commentAuthorEmail");var a=getCookie("commentAuthorUrl");if(c!=null&&c!=undefined){c=c.replace(/\+/g," ");$("#author").val(c).blur(function(){setCookie("commentAuthor",$("#author").val(),365)})}if(b!=null&&b!=undefined){$("#email").val(b).blur(function(){setCookie("commentAuthorEmail",$("#email").val(),365)})}if(a!=null&&a!=undefined){$("#url").val(a).blur(function(){setCookie("commentAuthorUrl",$("#url").val(),365)})}}function populateLatestPosts(a,b){if(b==null||b.error){displayMessage("Post data could not be parsed.");return}var c=false;$.each(b,function(d,g){var f=g.id;var e=g.title;if(!c&&e.indexOf(a+":")==0){$("#activeThread").append('<option value="'+f+'" selected="true">'+e+"</option>");c=true}else{$("#activeThread").append('<option value="'+f+'">'+e+"</option>")}});currentPostId=$("#activeThread").val();$.ajax({url:"/api/getpost/?postid="+currentPostId,dataType:"json",success:function(d){var e="";e+="<h2>"+d.postTitle+"</h2>";e+='<span style="margin-bottom: 10px;">Published '+formatMySqlDate(d.postDate).substring(0,19)+"</span>";e+='<p class="floatRight">By '+d.authorName+"</p>";e+='<div style="margin-top: 10px;"id="postContent">'+d.postContent+"</div>";$("#contents").html(e)},error:function(d){alert(d)}})}function activePostChanged(a){$.each($(".replyButton"),function(c,d){if($(this).val()=="Reply"){$(this).attr("disabled",true)}});var b=$(this).val();currentPostId=b;$.each($(".commentItem"),function(d,e){var c=$(this).find(".postId").val();if(c==currentPostId){$(this).find(".replyButton").attr("disabled","")}});$.ajax({url:"/api/getpost/?postid="+currentPostId,dataType:"json",success:function(c){var d="";d+="<h2>"+c.postTitle+"</h2>";d+="<span>Published "+formatMySqlDate(c.postDate).substring(0,19)+"</span>";d+='<p class="floatRight">By '+c.authorName+"</p>";d+='<div style="margin-top: 10px;" id="postContent">'+c.postContent+"</div>";$("#contents").html(d)}})}function buildCommentDisplay(b,f,g,h,d,k,j,c){var i=$("#activeThread").val();var e=(c!=i)?'disabled=""':"";var a="";a+='<li id="'+b+'" class="commentItem">';a+='<div class="commentHeader"><span class="commentAuthor">'+f+': </span><span class="commentDate">'+d+"</span></div>";a+='<div class="clearBoth commentContent">'+h+"</div>";a+='<div class="commentFooter"><span class="reply">';a+='<input class="replyButton" type="button" style="width: 70px;" value="Reply" '+e+"/>";a+='<input type="hidden" class="postId" value="'+c+'"/>';a+="<!-- textarea -->";a+='</span><span class="permalink"><a href="'+k+"#comment-"+b+'" title="View post - '+j+'">'+j+"</a></span>";a+='</div><div class="clearBoth"></div>';a+="</li>";return a}function addCommentsToTree(f,d,a,e){if(f===null||f===undefined){return}if(f.error){displayMessage("Comment data could not be parsed.");return}var c=false;var h="";var g=isInEditMode||!$("#pollForNewComments").is(":checked");var b=0;$.each(f,function(j,p){var o=p.id;var m=formatMySqlDate(p.commentDate);var k=convertSmilies(p.commentContent);var l=buildCommentDisplay(o,p.author,p.authorUrl,k,m,p.permalink,p.postTitle,p.postId);if(commentIdArray.indexOf(o)!==-1){return}commentIdArray.push(o);if(e){h=(l+h)}else{h+=l}presenceArray[presenceArray.length]=new presence(p.authorUrl,p.author,p.md5Hash);topicArray[topicArray.length]=new topic(p.permalink,p.postTitle);if(g){b++}freshCommentCount++;c=true});if(!c){return}if(a){$(h).appendTo("#commentsContainer > ol").hide()}else{if(e){$(h).prependTo("#commentsContainer > ol").hide()}else{$(h).appendTo("#commentsContainer > ol").hide()}}if(!isInEditMode&&$("#pollForNewComments").is(":checked")){if($("#pendingBox").length>0){$("#pendingBox").click()}else{showPendingComments()}}else{if(b>0){displayPendingCount(b)}}if(freshCommentCount>0){document.title="["+freshCommentCount+" new] - "+documentTitle}if(!a&&$("#playNewCommentAlert").is(":checked")){$("#newCommentFx")[0].play()}commentIdArray.sort(sortNumber);presenceArray.sort(sortNameAscending);topicArray.sort(sortNameAscending);updatePresenceDisplay();updateTopicDisplay()}function lifecyclePoller(){if(readyToSleep()){clearLightBox();displaySleepInformation();return}var a=commentIdArray[commentIdArray.length-1];try{$.ajax({url:"/api/getlatestdiscussionafterid/?commentid="+a,dataType:"json",cache:false,success:function(c,d){updateConnectionStatusDisplay(1);addCommentsToTree(c,d,false,true)},error:function(e,c,d){if(e.status===204){updateConnectionStatusDisplay(1)}else{updateConnectionStatusDisplay(0)}}})}catch(b){displayMessage("Error: "+b+".");updateConnectionStatusDisplay(0)}updatePollingDisplay();setTimeout(lifecyclePoller,secondsToRefresh*1000)}function displayMoreComments(b){var c=commentIdArray[0];var a=commentIdArray[commentIdArray.length-1];var d=$(this);d.fadeOut("slow");try{$.ajax({url:"/api/getlatestdiscussionbeforeid/?firstcommentid="+c+"&lastcommentid="+a,dataType:"json",cache:false,success:function(e,g){addCommentsToTree(e,g,false,false);if(e.length>0){d.fadeIn("slow")}},error:function(){d.fadeIn("slow");updateConnectionStatusDisplay(0)}})}catch(f){displayMessage("Error: "+f+".");d.fadeIn("slow");updateConnectionStatusDisplay(0)}return false}function displaySleepInformation(){var a="";a+='<div id="overlay"></div>';a+='<div id="lightboxFrame">';a+='<img src="http://static.sidepodcast.com/images/closenegative.png" width="16" height="16" id="lightboxFrameClose" title="Close" alt="Close"/>';a+="<p>Shhhhh.... Real-Time Doohickey is sleeping right now.</p>";a+='<p><img src="http://static.sidepodcast.com/images/sleeping_doohickey.jpg" width="480" height="270" alt="Sleeping Panda"/></p>';a+='<p><a href="http://www.flickr.com/photos/loush555/2382470574/" class="pictureCopyright">Photo by El Tekolote</a></p>';a+='<div class="clearBoth"></div>';a+="<p>[click to wake her up]</p>";a+="</div>";$(a).appendTo("body").hide().fadeIn("slow").click(function(){document.title=documentTitle;clearLightBox();lifecyclePoller()});$("#lightboxFrame").css("top",$(window).scrollTop()+scrollTopOffset);document.title="[Sleeping] - "+documentTitle}function displayPostLightBox(){var a=$("#activeThread").val();var b="";b+='<div id="overlay"></div>';b+='<div id="lightboxFrame" class="postLightBox">';b+='<img src="http://static.sidepodcast.com/images/closenegative.png" width="16" height="16" id="lightboxFrameClose" title="Close" alt="Close"/>';b+='<div id="postPlaceholder">Loading content...</div>';b+="</div>";$(b).appendTo("body").hide().fadeIn("slow");$.ajax({url:"/api/getpost/?postid="+a,dataType:"json",success:displayPost,error:function(){clearLightBox();displayMessage("Error: Could not display post.")}});return false}function displayPost(b){if(b==null||b.error){clearLightBox();displayMessage("Error: Unexpected server response.");return}var c="";for(var a=0;a<b.tags.length;a++){c+='<a href="'+b.tags[a].tagPermalink+'" title="'+b.tags[a].tagName+'">'+b.tags[a].tagName+"</a>";if(a<(b.tags.length-1)){c+=", "}}var d="";for(var a=0;a<b.categories.length;a++){d+='<a href="'+b.categories[a].categoryPermalink+'" title="'+b.categories[a].categoryName+'">'+b.categories[a].categoryName+"</a>";if(a<(b.categories.length-1)){d+=", "}}var e="";e+="<h2>"+b.postTitle+"</h2>";e+="<hr/>";e+='<div id="postContent">'+b.postContent+"</div>";e+="<hr/>";e+='<div id="postMeta">';e+='<p><span class="leftPad">Published:</span> <div class="rightPad">'+formatMySqlDate(b.postDate).substring(0,19)+"</div></p>";e+='<p><span class="leftPad">Author:</span> <div class="rightPad"><a href="'+b.authorPermalink+'" title="'+b.authorName+'">'+b.authorName+"</a></div></p>";e+='<p><span class="leftPad">Category:</span> <div class="rightPad">'+d+"</div></p>";e+='<p><span class="leftPad">Rating:</span> <div class="rightPad"><div class="postRatings"><form method="post" action="/submitrating/" class="ratingForm"><ul class="ratingList rating'+b.rating+'"><li><input class="ratingButton vote1" name="rating" title="1 out of 5" type="submit" value="1"/></li><li><input class="ratingButton vote2" name="rating" title="2 out of 5" type="submit" value="2"/></li><li><input class="ratingButton vote3" name="rating" title="3 out of 5" type="submit" value="3"/></li><li><input class="ratingButton vote4" name="rating" title="4 out of 5" type="submit" value="4"/></li><li><input class="ratingButton vote5" name="rating" title="5 out of 5" type="submit" value="5"/></li></ul><div class="ratingVotes"><span class="ratingResponse"></span><span class="ratingCount">'+b.ratingCount+'</span> <span class="ratingText">ratings</span></div><input type="hidden" class="ratingPostId" name="postid" value="'+b.id+'"/></form></div><div class="clearBoth"></div></div></p>';e+='<p><span class="leftPad">Permalink:</span> <div class="rightPad"><a href="'+b.permalink+'" title="'+b.postTitle+'">'+b.postTitle+"</a></div></p>";e+='<p><span class="leftPad">Tags:</span> <div class="rightPad">'+c+"</div></p>";e+="</div>";$("#postPlaceholder").html(e)}function displayQuickComment(a){if($(this).attr("value")=="Quick Comment"){$(this).attr("value","Cancel");$("#mainCommentPanel").html(createCommentBox()).show().find(".comment").focus()}else{$(this).attr("value","Quick Comment");$("#mainCommentPanel").hide().html()}}function commentClicked(c){if($(this).is("a")){if($(this).attr("href").indexOf("drop.io/sidepodcast/asset")===-1){if(c.button===0){window.open($(this).attr("href"));return false}}return}if($(this).parents("li").find(".comment").length===0){return}var g="";if($(this).is("p")||$(this).is("blockquote")){g=$(this).html()}else{if($(this).is("span.commentAuthor")){g=$(this).parents("li").find(".commentContent").html()}else{g=$(this).parents("p").html()}}if(g==null){return}g=unconvertSmilies(g);g=g.replace(new RegExp("\\&amp;","g"),"&");var d=$(this).parents("li").find(".comment");var h=d[0].selectionStart;var b=d[0].selectionEnd;var e=(b+startQuote.length+g.length+endQuote.length);var a=d.val().substring(0,h);var f=d.val().substring(b);d.val(a+startQuote+g+endQuote+f);d.get(0).setSelectionRange(e,e);d.focus()}function hrefSelected(){tagSelected($(this).parents(".commentPanel").find(".comment"),"a",'href="enter url here"')}function boldSelected(a){tagSelected($(this).parents(".commentPanel").find(".comment"),"strong")}function italicSelected(){tagSelected($(this).parents(".commentPanel").find(".comment"),"em")}function createReponsePanel(){if($(this).parents("li").find(".commentPanel").length>0){$(this).attr("value","Reply");$(this).parents("li").find(".commentPanel").remove()}else{$(this).attr("value","Cancel");$(this).parents("li").append(createCommentBox());$(this).parents("li").find(".comment").focus()}if($(this).parents(".commentlist").find(".commentPanel").length>0){isInEditMode=true}else{if($("#pollForNewComments").is(":checked")&&$("#pendingBox").length>0){$("#pendingBox").click()}isInEditMode=false}}function createRow(b,c,a){var d=b;if(d.length>33){d=b.substring(0,30)+"..."}if(a.indexOf("/")>-1){d='<a href="'+a+'">'+d+"</a>"}var e="<tr><td>"+d+"</td><td></td></tr>";return e}function updatePresenceDisplay(){var e="";var f="";var c=0;$("#presenceContainer").html('<table class="metaTable"><tr><th>Contributor</th><th></th></tr></table>');for(var d=0;d<presenceArray.length;d++){var b=presenceArray[d].name;var a=presenceArray[d].url;if(b!=e&&e!=""){$("#presenceContainer table").append(createRow(e,c,f));c=0}c++;e=b;f=a}if(e!=""){$("#presenceContainer table").append(createRow(e,c,a))}}function updateTopicDisplay(){var e="";var f="";var c=0;$("#topicContainer").html('<table class="metaTable"><tr><th>Topic</th><th></th></tr></table>');for(var d=0;d<topicArray.length;d++){var b=topicArray[d].name;var a=topicArray[d].url;if(b!=e&&e!=""){$("#topicContainer table").append(createRow(e,c,f));c=0}c++;e=b;f=a}if(e!=""){$("#topicContainer table").append(createRow(e,c,f))}};
