$(document).ready(function(){
	if ($(".poll-results").length > 0 ) {
		animateResults();
	}
});

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

function votar(id, formulario, destacado){
	opciones = eval("formulario.poll_option_"+id);
	opcion = 0;
	
	for(i=0;i<opciones.length;i++){
		if(opciones[i].checked){
			opcion = opciones[i].value;
			break;
		}
	}
	
	if(opcion){
		$("#encuesta-"+id).html('<strong>Cargando encuesta...</strong><div class="cargando-poll"><span class="oculto">Cargando</span></div>');
		setTimeout("cargarEncuesta("+id+","+opcion+",'"+destacado+"')",1000);
	}
}

function revotar(id, destacado){
	$("#encuesta-"+id).html('<strong>Cargando encuesta...</strong><div class="cargando-poll"><span class="oculto">Cargando</span></div>');
	setTimeout("recargarEncuesta("+id+",'"+destacado+"')",1000);
}

function cargarEncuesta(id, opcion, destacado){
	$.post("/encuestas/encuesta.php",
		{ id: id, opcion: opcion, destacado: destacado },
		function(data){				
			$("#encuesta-"+id).html(data);
			$("#encuesta-"+id).hide();
			$("#encuesta-"+id).slideDown("slow");
		}
	);
}

function recargarEncuesta(id, destacado){
	$.post("/encuestas/reencuesta.php",
		{ id: id, destacado: destacado },
		function(data){	
			$("#encuesta-"+id).html(data);
			$("#encuesta-"+id).hide();
			$("#encuesta-"+id).slideDown("slow");
		}
	);
}

