$(document).ready(function() {
	// set up ratings
	$.fn.rating.options.required = true;
	$.fn.rating.options.starWidth = 12;
	$("div.rating div.options input.rating").rating();
	
	// set up things
	things = $("div.thing div.options label");
	things.click(function() {
		things.each(function() {
			$(this).css("background","none");
		});
		$(this).css("background","#8e2a8b");
		
		var checkbox = $(this).siblings("input")[0];
		checkbox.checked = true;
		
		return false;
	});
	
	$("a.like_button").click(function() {
		vote(this);
		return false;
	});
});


vote = function(element) {
	$(element).hide();
	$(element).parents("div.review").find("p.voted").show();
	
	jQuery.get(element.href, null, function(data) {
		var voteCount = parseInt(data);
		var voteText = "1 person liked this.";
		
		if (voteCount > 1) {
			voteText = voteCount + " people liked this.";
		}

		$(element).parents("div.review").find("span.vote_count").html(voteText);
	}, "text");
}
