jQuery(document).ready(function($) {

  $("a").filter(".add_clip_rating").click(function() {
    myid = this.id.toString().split("_");

    jQuery.post(rateclip_url,
                {hdnAction : "ADDRATING", hdnRating : myid[2].toString(), hdnClipID : myid[1].toString()},
                function (data)
                 {
                 $('#divClipRating_' + myid[1].toString() + '_' + myid[3].toString()).html(data);
                 }
               );
	});

  $("img").filter(".star_rate").bind("mouseenter", function() {
    myid = this.id.toString().split("_");
    if (myid[2] > 0)
      {
      $("img").filter(".star_rate").filter(function() {
        itid = this.id.toString().split("_");
        match = (itid[0] == myid[0]) &&
                (itid[1] == myid[1]) &&
                (itid[2] <= myid[2]) &&
                (itid[2] > 0);
        return(match);
        }).each(function() { this.src = "images/star_rate_yellow.png"; });
      }
    else
      {
      $("img").filter(function() {
        itid = this.id.toString().split("_");
        match = (itid[0] == myid[0]) &&
                (itid[1] == myid[1]) &&
                (itid[2] == 0);
        return(match);
        }).each(function() { this.src = "images/star_rate_none_on.png"; });
      }
	});

  $("img").filter(".star_rate").bind("mouseleave", function() {
    myid = this.id.toString().split("_");

    $("img").filter(".star_rate").filter(function() {
      itid = this.id.toString().split("_");
      match = ((itid[0] == myid[0]) && (itid[1] == myid[1]));
      return(match);
      }).each( function ()
        {
        id = this.id.toString().split("_");
        if (id[2] == 0)
          {
          this.src = "images/star_rate_none.png";
          }
        else
          {
          this.src = "images/star_rate_grey.png";
          }
        });
	});

  $("span").filter(".clip_rating").bind("mouseenter", function() {
    cid = this.id.toString().split("_");
    // this means that a user  is logged in
    if (cid[2] != 0)
      {
      $("img").filter(".star_rate").filter(function() {
        imgid = this.id.toString().split("_");
        match = (cid[1] == imgid[1]);
        return(match);
      }).each(function() {
        imgid = this.id.toString().split("_");
        if (imgid[2] == 0)
          {
          this.src = "images/star_rate_none.png";
          }
        else
          {
          this.src = "images/star_rate_grey.png";
          }
        });
      }
    else
      {
      $("#spnRatingStars_" + cid[1]).hide();
      $("#spnRatingLoginLink_" + cid[1]).show();
      }
	});

  $("span").filter(".clip_rating").bind("mouseleave", function() {
    cid = this.id.toString().split("_");
    // this means that a user  is logged in
    if (cid[2] != 0)
      {
      $("img").filter(".star_rate").filter(function() {
        itid = this.id.toString().split("_");
        match = (cid[1] == itid[1]);
        return(match);
        }).each( function () {
          id = this.id.toString().split("_");
          if (id[2] == 0)
            {
            name = "images/star_rate_none";
            if (id[3] == "on")
              {
              name = name + "_on";
              }
            name = name + ".png";
            }
          else
            {
            name = "images/star_rate_" + id[3];
            if (id[4] == "half")
              {
              name = name + "_half";
              }
            name = name + ".png";
            }
          this.src = name;
          });
      }
    else
      {
      $("#spnRatingLoginLink_" + cid[1]).hide();
      $("#spnRatingStars_" + cid[1]).show();
      }
	});

}); // jQuery.ready()


