var curr;
var yesorno;
	function nextPage(){
		jQuery("#mod-buttons").text("Loading...");
			if(typeof jQuery(".navigation .alignright *:last").attr("href") != "undefined")
				{
				var votes = jQuery(curr).find(".votes").attr('votes');
				var sinks = jQuery(curr).find(".sinks").attr('sinks');
				var pct = 100*(sinks/(1.0*(Number(votes)+Number(sinks))));
				if(isNaN(pct)){pct=100;}
				window.location = jQuery(".navigation .alignright *:last").attr("href").split('?')[0] +"?pct="+pct+"&vt="+yesorno;}
			else
				jQuery("#mod-buttons").text('You are all done voting!!!');
	}
	function prevStory(){
		curr = curr.slideToggle().prev(".post").slideToggle();
		if(!curr.prev(".post").html())
			jQuery("#mod-prev").hide();
	}
	function nextNew(){
		if(!curr.next(".post").html())
			nextPage();
		curr = curr.slideToggle().next(".post").slideToggle();
		jQuery("#mod-prev").show();
		
	}
	
		
jQuery(document).ready(function($){
		$("#votebox").append('<div id="mod-buttons"><div><a class="votebutton" href="#" onclick="return false;" id="mod-report" value="" accesskey="n">No</a><a class="votebutton" href="#" id="mod-skip" value="" accesskey="k" onclick="javascript:nextNew();return false;">Skip</a><a class="votebutton" href="#" id="mod-vote" onclick="return false;" value="" accesskey="y">Yes</a><a class="votebutton" href="#" id="mod-prev" value="" onclick="javascript:prevStory(); return false;">Back</a></div></div>');
		curr = $("div.post").eq(0).show();
		$("#mod-vote").click(function(e){
			
			var votes = $(curr).find(".votes").attr('votes');
			var sinks = $(curr).find(".sinks").attr('sinks');
			var pct =  Math.round(100*(votes/(1.0*(Number(votes)+Number(sinks)))));
			if(isNaN(pct)){pct=100;}
			var inverse = 100 - pct;
			var message3 = "<div class=\"votechoice\">On the last post, you voted <span style=\"color:green\">yes</span>.</div><div class=\"votechoice\">";
			message3= message3+pct+"% of people also voted yes.</div><div class=\"votechoice\">"+inverse+"% of people voted no.</div>";
			$("#agreed").hide();
			$("#agreed").html(message3);
			jQuery("#agreed").fadeIn();
			yesorno=1;
			if(typeof $(curr).find(".bartext a").eq(0).attr("href") != "undefined")
			{window.location = $(curr).find(".bartext a").eq(0).attr("href");}
			nextNew();
		});
		$("#mod-report").click(function(e){
		
			var votes = $(curr).find(".votes").attr('votes');
			var sinks = $(curr).find(".sinks").attr('sinks');
			var pct = Math.round(100*(sinks/(1.0*(Number(votes)+Number(sinks)))));
			if(isNaN(pct)){pct=100;}
			var inverse = 100 - pct;
			var message2 = "<div class='votechoice'>On the last post, you voted <span style='color:red'>no</span>.</div><div class='votechoice'>"+pct+"% of people also voted no.</div><div class='votechoice'>"+inverse+"% of people voted yes.</div>";
			$("#agreed").hide();
			$("#agreed").html(message2);
			$("#agreed").fadeIn();
			yesorno=-1;
			if(typeof $(curr).find(".bartext a").eq(1).attr("href") != "undefined")
			{window.location = $(curr).find(".bartext a").eq(1).attr("href");}
			nextNew();
		});
	});
