$(function(){
	
	$('.close').click(function(){
		$(this).parent().fadeOut(200, function(){
			$(this).remove();
		});
	});
	
	$('.vote-button').click(function(){
		if ($('.custom-radio label').hasClass('checked')){
			var questionario_id = $('#questionario_id').val();
			var resposta_id = $('#poll-form .respostas:checked').val();
			$.ajax({
				url: 'home/questionario',
				type: 'POST',
				data: {
					questionario : questionario_id,
					resposta : resposta_id
				},
				dataType: 'json',
				success: function(data) {
					if (data.success == true){
						$('.errormessage').text('Agradecemos o seu voto.').css('color','#D77979');
						$('#poll-container').wait(3000).fadeOut(200, function(){
							$(this).remove();
						});
					} else {
						$('#poll-container').effect("shake", { times:3 }, 100);
						$('.errormessage').text('Houve um erro na requisição, tente novamente.');
					}
				}
			});
			$('.errormessage').text('');
		}else{
			$('#poll-container').effect("shake", { times:3 }, 100);
			$('.errormessage').text('Escolha ao menos uma opção.');
		}
	});
	
});

