$(function() {
	$('.user_group_tip').hover(function() { $(this).parent().find('.user_group_tooltip').show(); }, function() { $(this).parent().find('.user_group_tooltip').hide(); });
	
	$('.post_hidden_message a').click(function () {
		$(this).parent().parent().removeClass('post_hidden');
		return false;
	});
	
	$('.vote_up_button, .vote_down_button').click(function() {
		$.ajax({
			type: 'GET',
			url: $(this).attr('href'),
			dataType: 'json',
			success: function(data) {
				if (data.error != null) {
					alert(data.error);
				} else if (data.postid != null) {
					if (data.should_close) {
						$('#post' + data.postid).addClass('post_hidden');
					} else {
						$('#post' + data.postid).removeClass('post_hidden');
					}
					
					var rating_html = 'Rating (';
			
					if (data.rating >= 0) {
						rating_html += '<span class="rating_positive">+' + data.rating + '</span>';
					} else {
						rating_html += '<span class="rating_negative">' + data.rating + '</span>';
					}
			
					rating_html += ')';
					
					$('#post' + data.postid + ' .post_rating').html(rating_html);
					$('#post' + data.postid + ' .vote_up_button, #post' + data.postid + ' .vote_down_button').hide();
				}
			}
		});
		
		return false;
	});
});