$(document).ready(function(){
	
	var ancho_estrella = 16;
	var alto_estrella = 16;
	var cantidad = 5;
	var ancho = ancho_estrella*cantidad;
	$(".puntaje").css("width", ancho_estrella*cantidad+"px");
	$(".puntaje, .puntaje > span").css("height", alto_estrella+"px");
	$(".puntaje").each(function(){
		$(this).find("span").css("width",($(this).find("span").width()*ancho)/100 + "px");
	});
	//alert($(".puntaje > span").width());
	//alert(ancho);
	$(".puntaje").css("background", "url('imagenes/estrella_bn.png') repeat-x");
	
	var i;
	var votacion = 0;
	for (i=0;i<cantidad;i++)
	{
		$("<a />").hover(function(){
			$(this).css("background","url('imagenes/estrella.png') repeat-x");
			$(this).prevAll("a").css("background","url('imagenes/estrella.png') repeat-x");
			$(this).nextAll("a").css("background","url('imagenes/estrella_bn.png') repeat-x");
		},
		function(){
			$(this).parent().find("a").css("background","none");
		}).css("display", "inline-block").width(ancho_estrella).height(alto_estrella).attr("href","javascript:void(0);").click(function(){
			if(votacion == 0)
			{
				votacion++;
				var juego = $(this).parent().attr("rel")
				var link = $(this);
				link.parent().find("a").removeAttr("href").hide();
				var porc = (link.attr("rel")*100)/cantidad;
				$.ajax({
				   type: "POST",
				   url: "ajax/votar.php",
				   data: "juego=" + juego + "&voto=" + porc,
				   success: function(msg){
					link.parent().find("span").animate({width: ((msg*ancho)/100) + "px"},500);
					link.parent().find("a").remove();
					votacion = 0;
				   }
				 });
			 }
		}).css("position","relative").css("z-index","2").attr("rel", (i+1)).appendTo($(".puntaje"));
	}
	
	
});
