var tip_photo_rating_labels = $H({ '1': "Hate It",
                         '2': "Don't Like It",
                         '3': "Indifferent",
                         '4': "Like It",
                         '5': "Love It" });
var tip_photo_rating_label;

function showTipPhotoRatingLabel(event) {
    var label = event.element().previous('.helpful-label')
    tip_photo_rating_label = label.innerHTML;
    //alert(event.element().src);
    label.innerHTML = tip_photo_rating_labels.get(event.element().src.match(/(\d).gif$/)[1]) + "<img src=\"/images/clear.gif\" width=\"0\" height=\"20\" alt=\"\" />";
}

function restoreTipPhotoRatingLabel(event) {
    event.element().previous('.helpful-label').innerHTML = tip_photo_rating_label;
    // $('member-rating-label').innerHTML = rating_label;
}

function rateTipPhoto(event) {
    event.element().stopObserving('click');
    var rating = event.element().src.match(/(\d).gif$/)[1];
    var tip_photo_id = event.element().id.match(/^.*-(\d.*)$/)[1];
    
    var params = { id: tip_photo_id,
                   rating: rating };

    new Ajax.Request('/tip/rate_photo', { parameters: params }); 
}

function observePhotos() {
  $$('img.tip-photo-rating-img').each(function(element) {
    element.observe('mouseover', showTipPhotoRatingLabel);
    element.observe('mouseout', restoreTipPhotoRatingLabel);
    element.observe('click', rateTipPhoto);
  });
}
