/*
 * @author:         vebinua
 * @copyright:      August 28, 2009 :)
 * @desciption:     Initializes the star rating system for the games
 * 
 */

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

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

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

      _gameID = $('#gameID').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=" + _gameID + "&deCache=" + _randomNumber,
        success: function() {

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

                });

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

   return false;
   });
});
