function votar(event) {
	event.preventDefault();

	var id = $("input[name='poll']:checked").attr("value");
	id = id.replace("opt",'');
	var id_encuesta = $("input[name='id_encuesta']").attr("value");

	$("#encuesta_contenido").fadeOut("fast",function() {
		$.ajax({
			type: "POST",
			url: directorio_encuesta['directorio_admin'] + "encuesta_ajax.php",
			data: "id="+id+"&id_encuesta="+id_encuesta,
			success: function(datos) {
				$("#encuesta_contenido").empty().append(datos).fadeIn("slow",function(){animateResults();});
				$.cookie('vote_id', id, {expires: dias_duracion_cookie});
			}
		});
	});
}

function animateResults(){
  $("#resultados div").each(function(){
      var percentage = $(this).next().text();
      $(this).css({width: "0%"}).animate({
				width: percentage}, 'slow');
  });
}

$(document).ready(function() {
	$("#formulario").submit(votar);

	if ($.cookie('vote_id')) {
		$("#encuesta_contenido").empty();
		votedID = $.cookie('vote_id');
		$("#encuesta_contenido").fadeOut("fast",function() {
			$.ajax({
				type: "POST",
				url: directorio_encuesta['directorio_admin'] + "encuesta_ajax.php",
				data: "id=none",
				success: function(datos) {
					$("#encuesta_contenido").empty().append(datos).fadeIn("slow",function(){animateResults();});
				}
			});
		})
	}
});

