$(document).ready(function() {
	
	var vote_no = 0;
	
	if($('#poll #submit_poll').length > 0) {
		
		$('#submit_poll').click(function() {
						
			if($('input:radio[name=poll]').is(':checked')) {
				
				var vote = $('input:radio[name=poll]:checked').val();
				
				$.post('system/widgets/poll_widget/inc/poll_widget.inc.php', {action: 'vote', id: $('form[name=poll]').attr('id'), vote: vote}, function(data, textStatus) {
					
					if(textStatus == 'success') {
						
						$('#submit_poll').remove();
						
						var poll_votes = data.split(';');
						var poll_votes_total = 0;
						
						for(no in poll_votes) {
								
							poll_votes_total = eval(poll_votes_total)+eval(poll_votes[no]);
						
						}
												
						$('input:radio[name=poll]').each(function() {
														
							$(this).after('<span class="result">'+Math.round(poll_votes[vote_no] / (poll_votes_total / 100))+' %</span>');
							$(this).parent().after('<span class="percent_bar" style="width: '+((225 / 100) * Math.round(poll_votes[vote_no] / (poll_votes_total / 100)))+'px"></span>');
							$(this).remove(); 
							
							vote_no++
							
						});
						
					}
					
				});
				
			}
			
		});
		
	} else {
		
		
		
	}
	
});
