window.addEvent('domready', function() {
	$('poll-vote').addEvent('submit', function(e) {
		e.stop();
		var choice = $('poll-vote').toQueryString();
		showPollResults(choice);
	});
});

function showPollResults(choice) {
	var req = new Request({
		url: 'ajax-poll.aspx?' + choice,
		method: 'get',
		onRequest: function() {
			$('poll').set('html', '<div class="loader"><img src=\'/images/ajax-loader.gif\' width=\'31\' height=\'31\' alt=\'Loading\' /></div>');
		},
		onSuccess: function(responseText) {
			$('poll').set('html', responseText);
			bars();
		}
	}).send();
}

function bars() {
	$('poll-results').getElements('li').each(function(y) {
		var bar = y.getElement('.results');
		var percent = y.getElement('.percent').get('html').replace('%','');
		var fx = new Fx.Tween(bar, {'duration':'long'});
		fx.start('background-position', '-190px', -190 + parseInt((percent*.01)*190) + 'px');
	})
}