//Carlos Barrantes B

jQuery(function($){
	
	$('a[id^="vote"]').click(function(e){
		
		e.preventDefault();
		
		var submit = this,
			id = submit.id.replace('vote',''),
			$poll = $(submit).parents('.poll'),
			vote = ($c=$poll.find('input:checked').get(0))?$c.id.replace('voteid',''):0;
			opts = {

			async:		false,
			url: 		'includes/polls.php',
			type: 		'GET',
			dataType: 	"html",
			data: 		{id:id,vote:vote},
			beforeSend: function(){
				submit.innerHTML = 'LOADING...';
			},
			error: 		function(){alert('oops an error ocurred!');},
			success: 	function(response){$poll.html(response);},
			complete: 	function(){
				$poll.css('display','none');
				$poll.fadeIn();			
			}
		
		};
		
		if(!vote){
			alert('You must choose an option.');
			return;
		}
			
		
		$.ajax(opts);

		
	});
	
});
