$(document).ready(function() {
  //Hover stars
  $('.star').hover(
   function(){
      var base_src = $(this).attr('src');
      var hover_src;
      
       if(base_src.search(/base/) != -1)
       {
        hover_src = base_src.replace(/base/, 'hover');
       }
       else
       {
        hover_src = base_src.replace(/rating/, 'hover');
       }
      
      $(this).attr('src', hover_src);
      $(this).prevAll().attr('src', hover_src);
    },
    function(){
      var base_src;
      
      if($(this).attr('class').search(/rating/) != -1)
      {
        base_src = $(this).attr('src').replace(/hover/, 'rating');
      }
      else
      {
        base_src = $(this).attr('src').replace(/hover/, 'base');
      }
            
      $(this).attr('src', base_src);
      $(this).prevAll().attr('src', base_src);
    }
  );
  
    //Someone clicks a star to rate a deck
    $('.star').click(
     function(){
      $(this).unbind();
      $(this).prevAll('.star').unbind();
      $(this).nextAll('.star').unbind();
      
      if($('.rate-contact-send-comment').length == 1)
      {
        var deck_id = $(this).parent().parent().siblings('a').children('img').attr('id').substring(4);
      }
      else
      {
        var deck_id = $(this).parent().siblings('a').children('img').attr('id').substring(4);
      }
      
      var rate_value = $(this).prevAll('.star').length + 1;
      
      var url = '/ajax/rateDeck/value/'+rate_value+'/id/'+deck_id;
      
      jQuery.get( url );       
    });
});
