function doLikeDislike(newsID,thumbValue) {
	// SEND AJAX POST REQUEST (MORE LIKE AJAJ REALLY)
	$.post("/xhr-thumbs.php",{
		NewsID: newsID,
		Thumb:  thumbValue
	},function(responseJSON) {
		// CALLBACK
		if (responseJSON.success == 0) {
			// FAILED
			$("#dialog").html("<p>" + responseJSON.error + "</p>").dialog("option","title","Update Failed").dialog("open");
		} else {
			// UPDATE THE COUNTERS
			theLikeLink    = $(".like a[rel=" + newsID + "]");
			theDislikeLink = $(".dislike a[rel=" + newsID + "]");
			
			theLikeLink.fadeOut("slow",function() {
				theLikeLink.html("<img src='/images-layout/thumbs-up.gif' alt='like'>(" + responseJSON.thumbs_up + ")");
				theLikeLink.fadeIn();
			});
			
			theDislikeLink.fadeOut("slow",function() {
				theDislikeLink.html("<img src='/images-layout/thumbs-down.gif' alt='dislike'>(" + responseJSON.thumbs_down + ")");
				theDislikeLink.fadeIn();
			});		
		}
	},"json");
}

$(document).ready(function() {
	// DEFAULT SETUPS
	$.ajaxSetup({
		cache: false
	});
	
	$.ui.dialog.defaults.bgiframe = true;
	
	// ERROR DIALOG - JUST IN CASE
	$("<div id='dialog'></div>").appendTo("body").dialog({
		autoOpen: false,
		draggable: false,
		modal: true,
		resizable: false
	});
	
	// SET UP THE THUMBS UP / THUMBS DOWN LINKS
	$(".like a[rel]").click(function() {
		doLikeDislike($(this).attr("rel"),1);
		return false;
	});
	
	$(".dislike a[rel]").click(function() {
		doLikeDislike($(this).attr("rel"),-1);
		return false;
	});
});