var vo={};var vc={};var ss={};var rc={};function votec(c_id,v,hash){jq=$("div#c_"+c_id+">div.meta");var s_id=$("div.story:first").attr("id").substr(2);if(v<=0){if(jq.find(".votes a.down").is(".inactive")){return;}jq.find("span.v_neg").html(parseInt(jq.find("span.v_neg").html())+1);if(jq.find(".votes a.up").is(".inactive")){var cur_pos=parseInt(jq.find("span.v_pos").html());if(cur_pos>0){jq.find("span.v_pos").html(cur_pos-1);}}jq.find("div.votes .up").removeClass("inactive").addClass("active");jq.find("div.votes .down").removeClass("active").addClass("inactive");showhide(c_id);jq.find(".s_h, #report"+c_id).removeClass("hide");}else{if(jq.find(".votes a.up").is(".inactive")){return;}jq.find("span.v_pos").html(parseInt(jq.find("span.v_pos").html())+1);if(jq.find(".votes a.down").is(".inactive")){var cur_neg=parseInt(jq.find("span.v_neg").html());if(cur_neg>0){jq.find("span.v_neg").html(cur_neg-1);}}jq.find(".votes .up").removeClass("active").addClass("inactive");jq.find(".votes .down").removeClass("inactive").addClass("active");}if(!objPropExists(vc,s_id)){vc[c_id]={};vc[c_id].count=1;}else{vc[c_id].count++;}if(vc[c_id].count>3){return;}else{$.ajax({type:"POST",url:"/story/"+s_id+"/comments/"+c_id+"/vote/",data:constructQueryString("votec",v,hash),dataType:"html"});}}function vote(s_id,v,hash){jq=$("div#s_"+s_id);if(jq.find(".votes").length>0){if(v<=0){if(jq.find(".votes a.down").is(".inactive")){return;}jq.find("span.v_neg").html(parseInt(jq.find("span.v_neg").html())+1);if(jq.find(".votes a.up").is(".inactive")){var cur_pos=parseInt(jq.find("span.v_pos").html());if(cur_pos>0){jq.find("span.v_pos").html(cur_pos-1);}}jq.find(".votes .up").removeClass("inactive").addClass("active");jq.find(".votes .down").removeClass("active").addClass("inactive");}else{if(jq.find(".votes a.up").is(".inactive")){return;}jq.find("span.v_pos").html(parseInt(jq.find("span.v_pos").html())+1);if(jq.find(".votes a.down").is(".inactive")){var cur_neg=parseInt(jq.find("span.v_neg").html());if(cur_neg>0){jq.find("span.v_neg").html(parseInt(jq.find("span.v_neg").html())-1);}}jq.find(".votes .up").removeClass("active").addClass("inactive");jq.find(".votes .down").removeClass("inactive").addClass("active");}}if(!objPropExists(vo,s_id)){vo[s_id]={};vo[s_id].count=1;}else{vo[s_id].count++;}if(vo[s_id].count>3){return;}else{$.ajax({type:"POST",url:"/story/"+s_id+"/vote/",data:constructQueryString("vote",v,hash),dataType:"html"});}}function hide_all(){}function vote_current(v){if($("div#stories div.story:visible:first").length==0){return;}var s_id=$("div#stories div.story:visible:first").attr("id").substr(2);var hash=$("div#stories div#s_"+s_id+" input.hash").val();vote(s_id,v,hash);show_next();}var skipped={};function skip_current(){if(s_index.length>0){skipped[stories[s_index[story_index]][0]]=true;show_next();}}function show_next(){story_index++;if(story_index>=s_index.length){story_index=s_index.length-1;upcoming();}else{var jq=$("div#stories div.story:visible:first");if(s_index.length>story_index){jq.find("div.sc").html(stories[s_index[story_index]][1]);jq.attr("id","s_"+stories[s_index[story_index]][0]);jq.find("input.hash").val(stories[s_index[story_index]][2]);}}}upcoming_enabled=true;function upcoming(){if(upcoming_enabled){$.ajax({type:"POST",url:"/upcoming/",data:constructQueryString("upcoming"),dataType:"json",success:function(result){if(!result){s_index=[];stories=false;upcoming_unset_skipped();}else{stories=result[0];s_index=result[1];upcoming_unset_skipped();story_index=-1;show_next();hide_all();}}});}}function upcoming_unset_skipped(){var mark=[];for(var i in s_index){if(objPropExists(skipped,s_index[i])){delete stories[s_index[i]];mark.push(i);}}if(mark.length>0){for(var i in mark){if(s_index.length>0){s_index.remove(mark[i]-i);}}}if(s_index.length==0){upcoming_enabled=false;$("div#stories").html("<p>There are no more stories to vote on at this time.  Please check back shortly</p>");$("div#vote_on_submissions").hide();stories=false;}}function save(s_id){$.ajax({type:"POST",url:"/story/"+s_id+"/save/",data:constructQueryString("save"),dataType:"html",success:function(result){$("div#s_"+s_id+" span.save_link").html("Saved");}});}function save(s_id){$.ajax({type:"POST",url:"/story/"+s_id+"/save/",data:constructQueryString("save"),dataType:"html",success:function(result){$("div#s_"+s_id+" span.save_link").html("Saved");}});}function unsave(s_id){$.ajax({type:"POST",url:"/story/"+s_id+"/unsave/",data:constructQueryString("unsave"),dataType:"html",success:function(result){$("div#stories.saved div#s_"+s_id).remove();if($("div#storiesi.saved div.sstory").length==0){$("div#stories.saved").html("<p>You have no saved stories</p>");}}});}function report(c_id){var s_id=$("div.story:first").attr("id").substr(2);if(r_hash.length>0){$.ajax({type:"POST",url:"/story/"+s_id+"/comments/"+c_id+"/report/",data:constructQueryString("report",r_hash),dataType:"html",success:function(result){result=result.split("||||",2);if(result[0]=="true"){r_hash=result[1];}$("#report"+c_id).remove();}});}}function comment(){var s_id=$("div.story:first").attr("id").substr(2);var par=$("div#addcomment input.addcomment.parent").val();var msg_div=$("div#addcomment div.error");if(c_hash.length>0){$(msg_div).html("Submitting...");$.ajax({type:"POST",url:"/story/"+s_id+"/postcomment/",data:constructQueryString("comment",c_hash,$("div#addcomment textarea.addcomment.content").val(),par),dataType:"html",success:function(result){result=result.split("||||",3);if(result[0]!="false"){c_hash=result[0];if(par!=-1){$("div#c_"+par+">div.c_thread").append(result[2]);}else{$("div#comments > .panel").append(result[2]);}reply("-1");$("div#addcomment textarea.addcomment.content").val("");$(msg_div).html("");window.location.hash="c_"+result[1];}else{$("div#addcomment div.error").html(result[1]);}}});}}function reply(c_id){$("div#addcomment input.parent").val(c_id);$("div#c_"+c_id+">div.content").after($("div#addcomment"));$("div#addcomment div.error").html("");$("div#addcomment textarea.content").focus();}function showhide(c_id){var cdiv=$("div#c_"+c_id);var clink=$("div#c_"+c_id+" > .meta > .s_h");if($(cdiv).hasClass("clpsd")){$(cdiv).removeClass("clpsd");$(clink).html("[ - ]");}else{$(cdiv).addClass("clpsd");$(clink).html("[ + ]");}}function objPropExists(object,property){if(typeof(object)=="undefined"){return false;}if(typeof(object[property])!="undefined"){return true;}return false;}function constructQueryString(){if(arguments.length==1&&typeof(arguments[0])=="object"){arguments=arguments[0];}var qs="function="+arguments[0];for(i=0;i<arguments.length-1;i++){qs+="&arg_"+i+"="+URLEncode(arguments[i+1]);}return qs;}function URLEncode(clearString){var output="";var x=0;clearString=clearString.toString();var regex=/(^[a-zA-Z0-9_.]*)/;while(x<clearString.length){var match=regex.exec(clearString.substr(x));if(match!=null&&match.length>1&&match[1]!=""){output+=match[1];x+=match[1].length;}else{if(clearString[x]==" "){output+="+";}else{var charCode=clearString.charCodeAt(x);var hexVal=charCode.toString(16);output+="%"+(hexVal.length<2?"0":"")+hexVal.toUpperCase();}x++;}}return output;}Array.prototype.remove=function(from,to){var rest=this.slice((to||from)+1||this.length);this.length=from<0?this.length+from:from;return this.push.apply(this,rest);};
