// Rating list script file

// rating list class
function ratingList(id) {
 var inst = this;
 this.rate = $("a.rateon", this.id).length;
 this.id = id;
 
 $("a", ".ratingList").each(function(i) {
  this.ratingList = inst;
  $(this).hover(
   function () {inst.showRate(i+1)},
   function () {inst.showRate(inst.rate)}
  )
  .click(function(){inst.loadRate(this); return false;});
 })
}

// loading text
ratingList.prototype.LOADING = '<div class="loading">Loading...</div>';

// show specified rating
ratingList.prototype.showRate = function(r) {
 $("a", this.id).removeClass();
 $("a", this.id).slice(0, r).addClass("rateon");
 $("a", this.id).slice(r).addClass("rateoff");
} 

// set new rating and refresh list
ratingList.prototype.setRate = function(r) {
 if (this.rate != r) {
  this.rate = r;
  this.showRate(r);
 }
} 

// loads new rate
ratingList.prototype.loadRate = function(a) {
 $("a", this.id).hide();
 $(this.id).append(this.LOADING);
 
 var inst = this;
 jQuery.get(a.href+'&ajax=1', function(data) {inst.loadSuccess(data)} );
}

// success load handler
ratingList.prototype.loadSuccess = function(data) {
 if (data > 0)
   this.setRate(data);
 $(".loading", this.id).remove();
 $("a", this.id).show();
}


