var OPT_ID=0;var OPT_TITLE=1;var OPT_VOTES=2;var votedID;var ACTION=null;var RA;var IDP;var ms;var Today=new Date();ms=Today.getMilliseconds();$(document).ready(function(){$("#poll_submit").click(formProcess);ACTION=$("#poll").attr("action");RA=$("#ra").val();IDP=$("#idp").val();if($("#poll-results").length>0){animateResults();}else{if(RA!=null&&IDP!=null)
{if($.cookie('vote_id')){$("#poll-container").empty();votedID=$.cookie('vote_id');$.getJSON(ACTION+"?vote=none&ra="+RA+"&idp="+IDP+"&t="+ms,loadResults);}}}});function formProcess(event){event.preventDefault();if(!$.cookie('vote_id')){var id=$("input[@name='poll']:checked").attr("value");id=id.replace("opt",'');$("#poll-container").fadeOut("slow",function(){$("#poll-container").empty();votedID=id;$.getJSON(ACTION+"?vote="+id+"&ra="+RA+"&idp="+IDP+"&t="+ms,loadResults);$.cookie('vote_id',id,{expires:365,path:'/'});});}
return false;}
function animateResults(){$("#poll-results .bar-percent").each(function(){var percentage=$(this).text();var gap=100-parseInt(percentage);var tot=parseInt($(this).parent().width());var perc=Math.round((tot*gap)/100);if($(this).parent().hasClass("voted"))
{$(this).parent().css({backgroundPosition:"-200px 0px"}).animate({backgroundPosition:"-"+perc+"px 0px"},'slow');}else{$(this).parent().css({backgroundPosition:"-200px -200px"}).animate({backgroundPosition:"-"+perc+"px -200px"},'slow');}});}
function loadResults(data_arr){var total_votes=0;var percent;var data=data_arr['answer'];for(id in data){total_votes=total_votes+parseInt(data[id][OPT_VOTES]);}
if($("#poll-results").css("display")=="block")
{animateResults();return;}else{var results_html="<div id='poll-results'><div class='question'>"+data_arr['quest']+"</div>\n<div class='graph'>\n";for(id in data){if(parseInt(total_votes)>0)
{percent=Math.round((parseInt(data[id][OPT_VOTES])/parseInt(total_votes))*100);}else{percent=0;}
if(data[id][OPT_ID]!==votedID){results_html=results_html+"<div id='bar"+data[id][OPT_ID]+"' class='bar-container"+((id==(data.length-1))?" last":"")+"'><div class='bar-title'>"+data[id][OPT_TITLE]+"</div><div class='bar-percent'>"+percent+"%</div></div>\n";}else{results_html=results_html+"<div id='bar"+data[id][OPT_ID]+"' class='bar-container voted"+((id==(data.length-1))?" last":"")+"'><div class='bar-title'>"+data[id][OPT_TITLE]+"</div><div class='bar-percent'>"+percent+"%</div></div>\n";}}
results_html=results_html+"</div>\n";if(total_votes>9)
{results_html=results_html+"<p>"+TOTAL_VOTE_LABEL+": "+total_votes+"</p>\n";}
results_html=results_html+"<div class='clear-div'></div></div>\n";}
$("#poll-container").append(results_html).fadeIn("slow",function(){animateResults();});}
