/*
 * @author:         vebinua
 * @copyright:      August 20, 2009 :)
 * @description:    Star rating system base class. This is used for both videos and games.
 *
 */

$(function(){

    $('.starRating').click(function(){
        var _rating;
        var _randomNumber;
        var _videoID;

        _rating = $(this).attr('id');

        //cache buster
        _randomNumber = Math.floor(Math.random()*1000001);

        _videoID = $('#videoID').attr('value');

        //show activity indicator
        $('.ratingblock').html("<div align='center'><img src='../images/loading.gif'></div>");

        //processed vote through AJAX
        $.ajax({
            type: "POST",
            url: "ajax/processors/ajax.CountVote.php",
            data: "voteRating=" + _rating + "&id=" + _videoID + "&deCache=" + _randomNumber,
            success: function() {

                $('.ratingblock').load(
                    "ajax/processors/ajax.ReloadStarRating.php",
                    "voteRating=" + _rating + "&id=" + _videoID + "&deCache=" + _randomNumber
                );

                $('#numberOfVotes').load(
                    "ajax/processors/ajax.ReloadNumberOfVotes.php",
                    "id=" + _videoID + "&deCache=" + _randomNumber
                );
            }
        });

    return false;
    });
});
