function getTrans(a,c){var b=IIN_JS_TRANS_STRINGS[a];if(c!=null){if(typeof(c)=="string"){c=[c]}for(i=0;i<c.length;i++){b=b.replace("%s",c[i])}}return b}function flagPost(b,a){$(".flag-container-"+a).html(getTrans("saving"));$.ajax({url:"/api/load/flag/",data:{post_id:b,flag_id:a},success:function(c){$(".flag-container-"+a).html(getTrans("flagged")).addClass("flagged")}});return false}function reportComment(a){if(confirm("Are you sure?  ")){$.ajax({url:"/api/load/comment_report/",data:{comment_id:a},success:function(b){$("#comment-"+a).addClass("reported");$("#comment-report-"+a+" a").hide();$("#comment-report-done-"+a).show()}})}return false}function deleteComment(a,b){if(confirm("Are you sure?  You can't undo this.")){$.ajax({url:"/api/admin/comment_delete_by_author/",data:{comment_id:b},success:function(c){$("#comment-"+b).addClass("hidden")}})}return false}function hideComment(a,b){if(confirm("Are you sure?")){$.ajax({url:"/api/admin/comment_hide/",data:{comment_id:b},success:function(c){$("#comment-"+b).addClass("hidden")}})}return false}function moderatePost(a,c,b){$.ajax({url:"/api/admin/post_moderate/",data:{post_id:a,approved:c,safe:b},success:function(d){$("#post-moderation-"+a).html("Moderated!")}});return false}function displayCommentForm(d){if(d!=null){var c=mobileSafeSel(".comment-reply-form");c.remove();var b=mobileSafeSel(d).parents(".comment");var a=parseInt(b.attr("id").split("-")[1]);b.append(c);c.show();c.find(".comment-reply-parent-id").val(a);setTimeout(function(){iinScrollTo(b);c.find("textarea").focus()},50)}else{mobileSafeSel(".new-comment-form").show();setTimeout(function(){iinScrollTo(".new-comment-form");$(".new-comment-body").focus()},400)}}function resetCommentForm(){mobileSafeSel(".new-comment-post-button").attr("disabled",false);mobileSafeSel(".new-comment-post-button").value="Post Comment!";mobileSafeSel(".new-comment-parent-id").val("");mobileSafeSel(".new-comment-body").val("")}var commentPostInProgress=false;function submitComment(){if(commentPostInProgress){return}var c=mobileSafeSel(".new-comment-body").val();var a=mobileSafeSel(".new-comment-postId").val();var b=mobileSafeSel(".author-anonymous")&&mobileSafeSel(".author-anonymous").attr("checked");mobileSafeSel(".new-comment-post-button").attr("disabled",true);doSubmitComment(a,null,b,c,function(d){resetCommentForm()})}function cancelCommentReply(a){var b=mobileSafeSel(a).parents(".comment");var c=b.find(".comment-reply-form");c.find(".formText").val("");c.find(".comment-reply-parent-id").val("");c.hide()}function submitCommentReply(b){if(commentPostInProgress){return}var d=mobileSafeSel(b).parents(".comment");var e=d.find(".comment-reply-form");var g=e.find(".formText").val();var f=e.find(".comment-reply-parent-id").val();var a=e.find(".comment-reply-postId").val();var c=e.find(".reply-author-anonymous")&&e.find(".reply-author-anonymous").attr("checked");$(b).attr("disabled",true);doSubmitComment(a,f,c,g,function(h){$(b).attr("disabled",false);e.find(".comment-reply-parent-id").val("");e.find(".formText").val("");e.hide()})}function doSubmitComment(a,e,b,d,c){if(commentPostInProgress){return}if(d==""&&d.length<2){return false}if(d.length>3000){alert("Sorry, your comment is too long.  ");return false}b=(b=="checked")?true:false;commentPostInProgress=true;data={post_id:a,anonymous:b,comment:d};if(e){data.parent_id=e}$.ajax({url:"/api/load/comment/",data:data,type:"POST",success:function(g){commentPostInProgress=false;var m=parseInt($(".comment-count").html());mobileSafeSel(".comment-count").html(m+1);mobileSafeSel(".comment-count-top").html(m+1);c(g);var h=$(g.comment_html);if(e){var k=$("#comment-"+e);var f=1;var l=0;var j=k.attr("class").match(/reply-level-(\d+)/);if(j){l=parseInt(j[1]);f=l+1}h.addClass("reply-level-"+f);h.insertAfter(k)}else{$(".comment-container").append(h)}startCommentEditHideChecks(g.comment.id);iinScrollTo(h);if(typeof(clicky)!="undefined"){clicky.goal("791")}}})}var oldCommentTexts={};function editComment(b,a){var d=$("#comment-text-"+a);var c=$.trim(d.html().replace(/<br\/>/g,"\n").replace(/<br>/g,"\n"));oldCommentTexts[a]=c;d.html("<textarea id='comment-edit-text-"+a+"' class='comment-edit-text'></textarea><input type='button' onclick='submitEditComment("+a+"); return false;' value='Save'>&nbsp;<input type='button' onclick='cancelEditComment("+a+"); return false;' value='Cancel'>");$("#comment-edit-text-"+a).val(c);$("#comment-edit-text-"+a).focus()}function submitEditComment(a){var b=jQuery.trim($("#comment-edit-text-"+a).val());if(b.length==0){alert("You must enter some text for your comment.  ");return}var c=$("#comment-text-"+a);c.html(b.replace(/\n/g,"<br>"));$.ajax({url:"/api/modify/comment/",data:{comment_id:a,comment_text:b},type:"POST",success:function(d){}})}function cancelEditComment(a){var b=$("#comment-text-"+a);b.html(oldCommentTexts[a])}function startCommentEditHideChecks(a){setTimeout(function(){$("#comment-edit-container-"+a).hide()},5*60*1000)}function safeMode(a){$(".safe-mode").hide();$(".safe-mode-saving").show();$.ajax({url:"/api/load/safe_mode/",data:{safe_mode_active:a},success:function(b){reloadPage()}})}function reloadPage(){try{var a=location.hash;if(a){a=a.substr(1,9999)}else{a=location.href}$.mobile.changePage(a,{reloadPage:true})}catch(b){location.href=location.href}}function submitVote(b,d,a){var c=$(a).parents(".logo-vote-area");$(c).find(".vote-form-area").hide();$(c).find(".vote-saving-area").show();$.ajax({url:"/api/load/vote/",data:{story_id:d,vote:b},success:function(e){$(c).find(".vote-form-area").hide();$(c).find(".voting-results").html(e.voting_results_html).show();$(c).find(".vote-saving-area").hide();$(c).find(".vote-success-area").show()}});return false}function emailToFriend(){$(".send-to-friend").hide();$(".send-to-friend-form-container").show();$("#friendEmail").focus()}function emailToFriendSend(a){$(".send-to-friend-message-error").hide();$(".send-to-friend-message-success").hide();friend_email=$("#friendEmail").val();user_name=$("#fromName").val();$.ajax({url:"/api/email/send_to_friend/",data:{friend_email:friend_email,user_name:user_name,story_id:a},success:function(b){if(b.error){$(".send-to-friend-message-error").show();$(".send-to-friend-message-success").hide()}else{$(".send-to-friend-message-error").hide();$(".send-to-friend-message-success").show()}}})}function editStory(a){}function deletePost(a){if(confirm("Are you sure you want to delete your post?")){if(confirm("Are you absolutely sure???  It will be GONE")){if(confirm("100% Sure?  This is the last time we're going to ask.")){$.ajax({url:"/api/admin/post_delete/",data:{post_id:a},success:function(b){alert("Your post has been removed successfully.  It may take a few hours for it be completely gone from the entire site.  We're going to take you to the homepage now.  ");location.href="/";try{$.mobile.changePage("/")}catch(c){}}})}}}}function reloadSampler(){$("#sampler-paging").hide();$.ajax({url:"/api/info/stories/random",data:{limit:15,include_sampler_html:true},success:function(a){$("#sampler-stories").html(a.sampler_html);$("#sampler-paging").show()}})}function addPollChoice(){var b=$("#poll-answers .poll-answer:last");var c=b.clone();var a=c.find("input");a.val("");c.insertAfter(b)}function removePollChoice(b){if($("#poll-answers .poll-answer").length>1){var a=$(b).parents(".poll-answer").remove()}}function recordPreviewPollVote(a){var b=$(a).parents(".poll-form-area");$(b).removeClass("needs-vote");$(b).addClass("already-voted");$(b).find(".vote-results").show()}function recordPollVote(a,f,d){var e=$(a).parents(".poll-form-area");var c=$(e).find("input[type=radio]");var b=$(e).find("input[checked!=false]").val();showLoading();$.ajax({url:"/api/load/poll_vote/",data:{poll_id:f,choice_id:b},success:function(h){$(e).removeClass("needs-vote");$(e).addClass("already-voted");$(e).find(".vote-results").show();var j=$("#choice_count_"+b);var g=parseInt(j.html());j.animate({opacity:0.1},500,function(){j.html(g+1);j.animate({opacity:1},1000)});hideLoading()}});return false}function commentShow(a){a.find(".comment-user").show("slow");a.find(".comment-text").show("slow",function(){a.removeClass("negative-rating")})}function commentHide(a){a.find(".comment-user").hide("slow");a.find(".comment-text").hide("slow",function(){a.addClass("negative-rating")})}var ratingLocked=false;function updateScore(f,e){ratingLocked=true;var c=f.find(".score");var d=f.find(".initial-score");c.html("saving...");var b=f.attr("id").split("-")[1];function a(g){c.html(parseInt(d.html())+e);if(e>=0){commentShow(f)}else{commentHide(f)}ratingLocked=false}if(e!=0){$.ajax({url:"/api/load/comment_rating/",data:{comment_id:b,rating:e},success:a})}else{setTimeout(a,1000)}}function toggleCommentChildren(a){a=$(a);var b=a.parents(".comment-children:first");if(!b.hasClass("collapsed")){b.addClass("collapsed");a.html("+")}else{b.removeClass("collapsed");a.html("-")}}function commentThumbsDown(a){if(ratingLocked){return}if(!IIN_CURR_USER||!IIN_CURR_USER.user_id){authNeeded();return}a=$(a);var b=a.parents(".comment");if(a.hasClass("active")){a.removeClass("active");updateScore(b,0)}else{a.addClass("active");b.find(".thumb-up").removeClass("active");updateScore(b,-1)}}function commentThumbsUp(a){if(ratingLocked){return}if(!IIN_CURR_USER||!IIN_CURR_USER.user_id){authNeeded();return}a=$(a);var b=a.parents(".comment");if(a.hasClass("active")){a.removeClass("active");updateScore(b,0)}else{a.addClass("active");b.find(".thumb-down").removeClass("active");updateScore(b,1)}}function suicideWatch(g){var f=false;var c=$(g.target).val();if(!c||c.length<6){return}var d=["suicide","kill myself","off myself","end my life"];for(i=0;i<d.length;i++){var a=d[i];var b=RegExp(a,"ig");if(b.test(c)){f=true;break}}if(f){$("#suicide-watch").show()}}function authNeeded(){if(!REQUEST_IS_MOBILE){var b=getTrans("auth_error_title");var a=$("#auth-info").html();infoDialog(b,a)}else{alert("Sorry, you must sign in to do that.")}}var favoritingInProgress=false;function toggleFavorite(c,a){if(favoritingInProgress){return}if(!IIN_CURR_USER||!IIN_CURR_USER.user_id){authNeeded();return}favoritingInProgress=true;var d=$(c).hasClass("on");var b=$(c).siblings(".fav-info");$(b).html("saving...");$(c).html("");$.ajax({url:"/api/load/favorite/",data:{post_id:a,favorite:!d},success:function(e){if(d){$(b).html("");$(c).removeClass("on").addClass("off").html("+ Favorite")}else{$(b).html("Favorited");$(c).removeClass("off").addClass("on").html("(undo)");if(typeof(clicky)!="undefined"){clicky.goal("886")}}favoritingInProgress=false}})}noticeBlinkInterval=null;function startNoticeBlink(){noticeBlinkInterval=setInterval(function(){$("#notice-info-count-container").toggleClass("blink")},750)}function stopNoticeBlink(){clearInterval(noticeBlinkInterval)}var cachedNotices=null;function showNoticeDetails(d){var c=$("#notice-info");var a=$("#notice-details");var b="<ul class='notices'>";for(i=0;i<d.length;i++){b+="<li class='notice "+(d[i].unseen?"unseen":"")+"'>"+d[i].message+"</li>";d[i].unseen=false}if(d.length==0){b+="<li class='notice'>No notices at this time.  Check back later.</li>"}if(d.length>=15){b+="<li class='notice'><a href='/profile?tab=notices&page=2#ptc'>More...</a></li>"}b+="</ul>";a.html(b);c.removeClass("unseen");$("#notice-info-count-container").removeClass("blink").html("0");setTimeout(function(){$("body").bind("click.notices",function(f){if(f.target.tagName!="A"){c.show();a.hide();$("body").unbind("click.notices")}})},100)}function expandProfileCmt(b){var a=$(b).parents("em:first");a.find(".cmt-shrt").hide();a.find(".cmt-long").show();return false}function toggleHPQuote(){var a=$(".hp-quote");var b=a.hasClass("collapsed");if(!b){$.cookie("hhpq","1",{expires:999999});a.addClass("collapsed")}else{$.cookie("hhpq",null);a.removeClass("collapsed")}}function toggleNotices(){var c=$("#notice-info");var b=$("#notice-details");if(b.css("display")=="none"){stopNoticeBlink();b.html("<p><img src='/media/img/loading.gif'></p>");c.hide();b.show();if(cachedNotices==null){var a=new Date().getTime();$.ajax({url:"/api/info/notices/",data:{limit:15,cache_buster:a},success:function(d){showNoticeDetails(d.notices);cachedNotices=d.notices}})}else{showNoticeDetails(cachedNotices)}}else{c.show();b.hide()}}function trackEvent(b,c,d,a){if(_gaq){_gaq.push(["_trackEvent",b,c,d,a])}}function mobileSafeSel(a){if(typeof a=="string"){if(REQUEST_IS_MOBILE){a='div:jqmData(role="page"):visible '+a}}return $(a)}function iinScrollTo(b){var a=mobileSafeSel(b);if(a){var c=a.offset();if(c){$("html, body").animate({scrollTop:c.top},0)}}}function doDeepLink(){if(location.href.indexOf("dl=")!=-1){var a=location.href.substr(location.href.indexOf("dl=")).replace("dl=","");if(a){if(a.indexOf("&")!=-1){a=a.substr(0,a.indexOf("&"))}if(a&&a.length>0){setTimeout(function(){iinScrollTo("#"+a)},800)}}}}function updateNoticeUnseenCount(){if(IIN_CURR_USER&&IIN_CURR_USER.user_id){$.ajax({url:"/api/info/notice_unseen_count/",data:{user_id:IIN_CURR_USER.user_id},success:function(a){$(".active-notices").html(a)}})}}function doAskLinkHover(){if($(this).find(".do-it").length==0){$(this).css("position","relative");var a=$("<div>").addClass("do-it").html("Go for it! :)");a.css("top","-1px");$(this).append(a);a.css("right",-1*a.width()-5)}}function doAskLinkHoverOut(){$(this).find(".do-it").remove()}function showLoading(){try{$.mobile.pageLoading()}catch(a){var b=$("#spinner");centerObj(b);b.show();showShadow()}}function hideLoading(){try{$.mobile.pageLoading(true)}catch(a){var b=$("#spinner");b.hide();hideShadow()}}function showShadow(){var b=$("#shadow");var a=$("#page-container").height();b.css({height:a}).show();b.show()}function hideShadow(){var a=$("#shadow");a.hide()}function infoDialog(f,j,c,h,b){var d=$("#info-dialog");var g=$("#shadow");d.find(".title").html(f);d.find(".message").html(j||"");var e=d.find(".ok");var a=d.find(".cancel");if(!c){c=hideInfoDialog}e.bind("click",c);if(!h){a.hide()}else{a.bind("click",h)}centerObj(d);showShadow();d.show();e.focus();if(b!=null){b()}}function hideInfoDialog(){$("#info-dialog").hide();$("#shadow").hide()}function centerObj(g){var f=$(g);var e=$(window).scrollTop();var b=$(window).width();var c=$(window).height();var a=f.width();var d=f.height();f.css("left",(b-a)/2);f.css("top",((c-d)/2)-50+e)}function sendQuickFeedback(){var b=$("#mini-feedback-form .message");if(b.val()){showLoading();if($("#mini-feedback-email").hasClass("tip")){$("#mini-feedback-email").val("")}var a=$(this).serialize();a+="&is_quick_feedback=y";$.post($(this).attr("action"),a,function(){hideLoading();infoDialog(getTrans("quick_feedback_success_title"),getTrans("quick_feedback_success_message"));b.val("");b.css("height","60px");b.addClass("tip")})}return false}function initMiniFeedbackForm(){$("#mini-feedback-form").submit(sendQuickFeedback);$("#mini-feedback-form .message").bind("focus",function(){if($(this).attr("class").indexOf("tip")!=-1){$(this).val("");$(this).removeClass("tip");$(this).css("height","150px");$("#mini-feedback-email").show()}});$("#mini-feedback-email").bind("focus",function(){if($(this).attr("class").indexOf("tip")!=-1){$(this).removeClass("tip");$(this).val("")}})}var submitSearchInProgress=false;var submitSearchTimeout=null;var submitQueryCache={};function doSubmitSearch(a){var b=$(this).val();if(b.length>8&&!submitSearchInProgress&&b[b.length-1]==" "){b=b.substr(0,50);cached_html=submitQueryCache[b];if(cached_html){$("#dynamic-search-results").html(cached_html);$("#dynamic-search-results-container").show()}else{submitSearchInProgress=true;$.ajax({url:"/api/info/posts/search/",data:{query:b,limit:8},success:function(e){setTimeout(function(){submitSearchInProgress=false},500);if(e.total_hits>0){var d="<ul>";for(i=0;i<e.posts.length;i++){var c=e.posts[i];d+='<li><a href="'+c.url+'" target="_blank">'+c.title+"</a></li>"}d+="</ul>";submitQueryCache[b]=d;$("#dynamic-search-results").html(d);$("#dynamic-search-results-container").show()}}})}}}function expandComments(a){mobileSafeSel(".hcl-"+a).hide();mobileSafeSel(".hc-"+a).show()}function goToTop(){if(!REQUEST_IS_MOBILE){iinScrollTo("#page-container")}else{$.mobile.silentScroll(0)}}jQuery.cookie=function(d,e,b){if(arguments.length>1&&String(e)!=="[object Object]"){b=jQuery.extend({},b);if(e===null||e===undefined){b.expires=-1}if(typeof b.expires==="number"){var g=b.expires,c=b.expires=new Date();c.setDate(c.getDate()+g)}e=String(e);return(document.cookie=[encodeURIComponent(d),"=",b.raw?e:encodeURIComponent(e),b.expires?"; expires="+b.expires.toUTCString():"",b.path?"; path="+b.path:"",b.domain?"; domain="+b.domain:"",b.secure?"; secure":""].join(""))}b=e||{};var a,f=b.raw?function(h){return h}:decodeURIComponent;return(a=new RegExp("(?:^|; )"+encodeURIComponent(d)+"=([^;]*)").exec(document.cookie))?f(a[1]):null};
