function reqStars(id) {
	// Build hash of values to POST
	var h = $H({
		mediaId: id
	});
	
	new Ajax.Request('/ajax/stars.asp', {
		parameters: h.toQueryString(),
		onSuccess: function(transport) {
			if(transport.responseText == null) {
				$('starRating').update("");
			}
			else {
				$('starRating').update(transport.responseText);
				setStars($('averageRating').value);
			}
		},
		onFailure: function() {
			$('starRating').update('<p>An error has occured and the rating for this story could not be accessed.</p>');
		}
	});
}

function setStars(stars) {
	var i = 1;
	
	for(i = 1; i <= stars; i++) {
		$('star' + i).src = "/images/full_star.png";
	}
	for(i = stars + 1; i <= 5; i++) {
		$('star' + i).src = "/images/empty_star.png";
	}
}

function submitRating(id, ip, rating) {
	// Build hash of values to POST
	var h = $H({
		mediaId: id,
		ipAddress: ip,
		stars: rating
	});
	
	new Ajax.Request('/ajax/submit_rating.asp', {
		parameters: h.toQueryString(),
		onSuccess: function(transport) {
			reqStars(id);
		},
		onFailure: function() {
			$('starRating').update('<p>An error has occured and the rating for this story could not be submitted.</p>');
		}
	});
}