$(document).ready(function() {
	$('.star-rating li').click(function(e) {
		e.preventDefault();
		$this = $(this);
		var recipeId = string_subtract($this.parent().attr('id'),'recipe_');
		var amount = $this.find('a').html();
		
		$.ajax({
			url: getBaseURL()+'recipes/rate',
			type: 'POST',	
			dataType: 'json',
			data: {recipeId: recipeId, amount:amount},
			complete: function(xhr, textStatus) {
			  //called when complete
			},
			success: function(data, textStatus, xhr) {
				if(data.status == "success") 
				{
					$this.parent().find('li.current-rating').css('width', 12*data.text);
				}
				else
				{
					alert(data.text);
				}
			},
			error: function(xhr, textStatus, errorThrown) {
			  //called when there is an error
				alert('error occurred');
			}
		});
	});
});

