$(document).ready(function() {


    $("#rating").css("display","block");

    $(".how-to-vote").hide();



    $(".how-to-vote-link").click(function(e) {

        // prevents the default link behavior
        e.preventDefault();

        $(".how-to-vote").fadeIn("fast", function()
       {
          setTimeout( function()
          {
             $(".how-to-vote").fadeOut("fast");
          }, 6000);
       });

	});





    $('[class^=star_]').mouseenter(
        function() {
            if($(this).parent().data('selected') == undefined) {
                var selectedStar = $(this).parent().find('.hover').length - 1;
                $(this).parent().data('selected', selectedStar)
            }
            $(this).children().addClass('hover');
            $(this).prevAll().children().addClass('hover');
            $(this).nextAll().children().removeClass('hover');
        });

    $('[id^=rating_]').mouseleave(
        function() {
            var selectedIndex = $(this).data('selected')
            var $selected = $(this).find('img').eq(selectedIndex).addClass('hover').parent();
            $selected.prevAll().children().addClass('hover');
            $selected.nextAll().children().removeClass('hover');
    });



	$("[id^=rating_]").children("[class^=star_]").click(function() {

		var current_star = $(this).attr("class").split("_")[1];
		var s = $(this).parent().attr("id").split("_")[1];
        var i = $(this).parent().attr("id").split("_")[2];

		$("#rating_"+s+"_"+i).load('ratings.php', {r: current_star, i: i, s: s});

	});


});
