
    $.ajaxSetup({global: true, async: false});
    function setSrc(selector, newsrc)
    {
      if ( $(selector).attr('src') != newsrc )
        $(selector).attr('src', newsrc);
    }

    function restartStars()
    {
      for(x=1; x<=5; x++)
      {
          setSrc( '#star_'+x, './img/gwiazdka_szara.png' );
      }
    }
    
    function resetStars()
    {
      rev = parseFloat( $(".stars, #stars").attr("rev") );
      
      for(x=1; x<=5; x++)
      { 
        if ( rev < x )
          setSrc( '#star_'+x, './img/gwiazdka_szara.png' );
        else
          setSrc( '#star_'+x, './img/gwiazdka_zlota.png' );
      }

      rev = rev.toString();      
      if ( rev.indexOf('.') != -1 )
      {
        aRev = rev.split('.');
        setSrc( '#star_'+(parseInt(aRev[0])+1), './img/gwiazdka_polowa.png' );
      }
    }

  $(document).ready( function()
  {
    $('img[id^=star_]').mouseover( function()
    {
      var number = parseInt( $(this).attr('id').replace('star_', '') );
      
      restartStars();

      for( x=number; x>=0; x-- )
      {
        setSrc('#star_'+x, './img/gwiazdka_zlota.png');
      }
    }).click( function()
    {
      btn = $(this);
      $.get("./scripts/php/isLogged.php", function(data)
      {
        data = parseInt( data );
        if ( data > 0 )
        {
            var number = btn.attr('id').replace('star_', '');
            
            type = $('.stars, #stars').attr('ret');
            
            $.get("./scripts/php/ocen.php", { "id" : $(".stars, #stars").attr("rel"), "ocena" : number, "type" : type }, function(dane)
            {
              arrDane = dane.split('-');
              if ( type == "video" )
              {
                getMsg("videoVoted", "#videoRate", arrDane[1], arrDane[0]);
              }
              else
              {
                getMsg("albumVoted", "#albumRate", number, arrDane[0]);
              }
              $(".stars, #stars").attr("rev", arrDane[1]);
              resetStars();
              alertMsg("thanksRate");
            });     
        }
        else
          alertMsg("nonLogged");
      });
    });
    
    $(".stars, #stars").parent().mouseout( function()
    {
      resetStars();
    });
    
    resetStars();
    
  });
