$j(document).ready(function () {
  $j("div.rating-stars").each(function() {
    var divId = this.id,
        itemName = this.id.substring(0, this.id.indexOf('-')),
        itemId = parseInt(this.id.substring(this.id.indexOf('-n') + 2));
    $j(this).children("img.stars").each(function(index){
        var 
          star1, star2, star3, 
          url = '/rating/VoteForItem/itemname/' + itemName + '/item_id/' + itemId + '/rate/' + (index + 1) + '/div_id/' + divId + '/is_small/',
          path = this.src.substring(0, this.src.lastIndexOf('/') + 1),
          rating = parseInt(this.src.substring(this.src.lastIndexOf("#") + 1));

        if(this.src.match(/[123]{1,1}\.gif/)) {
          star1 = '1.gif';
          star2 = '2.gif';
          star3 = '3.gif';
          url += 'y';
        } else if (this.src.match(/star[\w-]*\.gif/)) {
          star1 = 'star.gif';
          star2 = 'star-grey.gif';
          star3 = 'star-yellow-grey.gif';
          url += 'n';
        }
        star1 = path + star1;
        star2 = path + star2;
        star3 = path + star3;
        $j(this).hover(function() {
          voteOver(this, star1, star2, star3, rating);
        }, function() {
          moveback(this, star1, star2, star3, rating);
        });
        $j(this).click(function () {
          voteClick(this, url, divId);
        });
    });
  });
});



