$(function(){

$("#poll_session").hide();

if($("#poll_session").html()=='true'){

var option1=Math.round(eval($("#option1_result").html()));
var option2=Math.round(eval($("#option2_result").html()));
var option3=Math.round(eval($("#option3_result").html()));
var total_vote=option1+option2+option3;

var option1_perc=(option1*100)/total_vote ;
var option2_perc=(option2*100)/total_vote ;
var option3_perc=(option3*100)/total_vote ;

var option1_width=(180*option1_perc)/100;
var option2_width=(180*option2_perc)/100;
var option3_width=(180*option3_perc)/100;	
$("#poll_cont").hide();
$("#results").show();
$("#option1_color").animate({width: option1_width }, 1500 );
$("#option2_color").animate({width: option2_width }, 1500 );
$("#option3_color").animate({width: option3_width }, 1500 );
}

//alert(option1_width);

$("#vote").live("click",function(){
if($('input[id=poll1]').is(":checked")){
$.post("poll_insert.php",{"option_value":option1,"option_num":"option1","poll_id":$("#vote").attr("alt")},
function(data){	

$("#option1_result").html(Math.round(eval($("#option1_result").html()))+1);
$("#option1_color").animate({width: option1_width }, 1500 );
$("#option2_color").animate({width: option2_width }, 1500 );
$("#option3_color").animate({width: option3_width }, 1500 );
//alert(data);
});	
}
if($('input[id=poll2]').is(":checked")){
$.post("poll_insert.php",{"option_value":option2,"option_num":"option2","poll_id":$("#vote").attr("alt")},
function(){
$("#option2_result").html(Math.round(eval($("#option2_result").html()))+1);
$("#option1_color").animate({width: option1_width }, 1500 );
$("#option2_color").animate({width: option2_width }, 1500 );
$("#option3_color").animate({width: option3_width }, 1500 );

	//alert(data);
});	
}
if($('input[id=poll3]').is(":checked")){
$.post("poll_insert.php",{"option_value":option3,"option_num":"option3","poll_id":$("#vote").attr("alt")},
function(){	

$("#option3_result").html(Math.round(eval($("#option3_result").html()))+1);
$("#option1_color").animate({width: option1_width }, 1500 );
$("#option2_color").animate({width: option2_width }, 1500 );
$("#option3_color").animate({width: option3_width }, 1500 );

	//alert(data);
});	
}	


	
var option1=Math.round(eval($("#option1_result").html()));
var option2=Math.round(eval($("#option2_result").html()));
var option3=Math.round(eval($("#option3_result").html()));
var total_vote=option1+option2+option3;
var option1_perc=(option1*100)/total_vote ;
var option2_perc=(option2*100)/total_vote ;
var option3_perc=(option3*100)/total_vote ;
var option1_width=(180*option1_perc)/100;
var option2_width=(180*option2_perc)/100;
var option3_width=(180*option3_perc)/100;
$("#poll_cont").hide();
$("#results").show();	

});
});