/*
 * autor: Ciro Feitosa - http://cirofeitosa.com.br
 * fevereiro/2008
 */

var nota_atual;
var nota_i;

nota_estrelas = function(id, pid)
{
	for (nota_i=1; nota_i<=parseInt(id); nota_i++)
		$('#nota_'+pid+'_'+nota_i).attr('src', '/_img/star-on.gif');

	if (id < 5)
	{
		for (nota_i=parseInt(id)+1; nota_i<=5; nota_i++)
			$('#nota_'+pid+'_'+nota_i).attr('src', '/_img/star-off.gif');
	}
}

nota_estrelas_off = function(id, pid)
{
	for (nota_i=1; nota_i<=parseInt(id); nota_i++)
		$('#nota_'+pid+'_'+nota_i).attr('src', '/_img/star-off.gif');
}

nota_nota = function(id, pid, equ)
{
	$('#avalia_'+pid).fadeOut('normal', function()
	{
		$('#avalia_'+pid).text('Avaliando...').fadeIn();

		$.post('/ajax/voto', { nota: id, id: pid, equipe: equ }, function (data)
		{
			$('#avalia_'+pid).fadeOut('fast', function()
			{
				$('#avalia_'+pid).text('Obrigado pela avaliação!').fadeIn('fast');
			});
		});
	});
}

$(document).ready(function()
{
	/*
	 * ativa links para notas
	 */
	$('.avalia img').each(function()
	{
		$(this)
			.mouseover(function()
			{
				nota_estrelas($(this).attr('nota'), $(this).attr('rel'));
			})
			.mouseout(function()
			{
				nota_estrelas_off($(this).attr('nota'), $(this).attr('rel'));
			})
			.click(function()
			{
				nota_nota($(this).attr('nota'), $(this).attr('rel'), $(this).attr('equipe'));
			});
	});
});
