var RatingEditor = Class.create();
RatingEditor.prototype = {

  initialize: function() {
  },
  
  submitRating: function(form, value, url) {
    new Ajax.Request(form.action, {
      method: "post",
      parameters: "value=" + value + "&secretKey=" + form.secretKey.value,
      onSuccess: function(transport) {
        new Ajax.Updater(form.down('.star-rating'), url);
      }
    });
  },

  ratingHover: function(form, value, picNr) {
    var picSrcs = ["http://static.blogr.ch/tenants/ch/modRating/star_hover.gif", "http://static.blogr.ch/tenants/ch/modRating/star_active.gif"];
    var picIndex = picNr ? 1 : 0;
    var stars = form.getElementsBySelector('li img');
    var activeStars = stars.slice(0, value);
    activeStars.each(function(star) {
      star.src = picSrcs[picIndex];
    });
  
    var emptyStars = stars.slice(value, stars.length);
    emptyStars.each(function(star) {
      star.src = "http://static.blogr.ch/tenants/ch/modRating/star_empty.gif";
    });
  },

  ratingBlur: function(form) {
    this.ratingHover(form, form.value.value, true);
  }
  
};

var ratingEditor = new RatingEditor();
