$(function(){

  $('.button').mousedown(function(event){$(this).removeClass("mouseout");$(this).removeClass("mouseover");$(this).addClass("pressed"); event.stopImmediatePropagation();});
  $('.button').hover(function(){$(this).removeClass("pressed");$(this).removeClass("mouseout");$(this).addClass("mouseover");},function(){$(this).removeClass("pressed");$(this).removeClass("mouseover");$(this).addClass("mouseout");});
  $('.button').mouseup(function(){$(this).removeClass("mouseover");$(this).removeClass("pressed");$(this).addClass("mouseout");});


  $('.nutPlaceholder label').mouseover(function(){$('#descs div').hide();$('#desc_'+$(this).attr('for')).show();});

$(".starBg").hover(
	function()
	{
		// only animate if was not yet clicked
		if($("input[name=vote]").val() != "")
			return;
		//reverse order:
		highlightStars($(this).nextAll(".starBg").length);
		//correct order:
		//highlightStars(4-$(this).nextAll(".star").length);
	}
	,
	function()
	{
		//$(".star").removeClass("highlight");
	}
).click(
	function()
	{
		//reverse order:
		var index = $(this).nextAll(".starBg").length;
		highlightStars(index);
		$("input[name=vote]").val(index+1);
		//correct order:
		//highlightStars(4-index);
	}
);

$("#stars").hover(function(){},
	function()
	{
		if($("input[name=vote]").val() != "")
			return;
		$(".starBg").removeClass("highlight");
	}
);

});

// activeStarIndex: 0 = bad, 4 = super (reverse order of definition in html)
function highlightStars(activeStarIndex)
{
	$("#stars .starBg").slice(0,4-activeStarIndex).removeClass("highlight");
	$("#stars .starBg").slice(4-activeStarIndex).addClass("highlight");
}
