var gHost = location.protocol + '//' + location.host;

$(document).ready(function() {
  $(".posBtn").bind("click", function() {
    changeRating($(this).attr("id"), $(this).attr("type"), 1);
    return false;
  });

  $(".negBtn").bind("click", function() {
    changeRating($(this).attr("id"), $(this).attr("type"), -1);
    return false;
  });
});

function changeRating(anObjID, aTypeID, aDelta) {
  vPath = "/js/data/change_user_rating.php";
  vParams = {
    obj_id: anObjID,
    type_id: aTypeID,
    direction: aDelta
  };
  vResult = performRequest(vPath, vParams, "POST", "html");
  $("#ratingPanelDiv").html(vResult.responseText);
  $("#ratingPanelDiv").css('font-weight', 'bold');
  $("#ratingPanelDiv").css('margin', '10px');
}

function performRequest(aPath, aParams, aType, aDataType) {
  var aDataObj = $.ajax({
    url: gHost + aPath,
    async: false,
    type: aType,
    dataType: aDataType,
    data: aParams
  });
  return aDataObj;
}
