$(document).ready(function($) {
	//flag topic
	$('.flag-topic').live('click', function() {
		var link = $(this);
		var topic_id = $(this).attr('id');

		var users = $(this).attr('rel').split('-');
		var sender_id = users[0];
		var topic_poster_id = users[1];

		$.post('/forum_action/flag_topic',
		{
			topic_id: topic_id,
			sender_id: sender_id,
			topic_poster_id: topic_poster_id
		},
		function(data) {
			if(data.success) {
				window.location.href = "/forum";
			}
		}, "json");
	});

	//flag post
	$('.flag-post').live('click', function() {
		var link = $(this);
		var post_id = $(this).attr('id');
		var post_div = '#post-' + post_id;

		var users = $(this).attr('rel').split('-');
		var sender_id = users[0];
		var poster_id = users[1];

		$.post('/forum_action/flag_post',
		{
			post_id: post_id,
			sender_id: sender_id,
			poster_id: poster_id
		},
		function(data) {
			if(data.success) {
				$(post_div).fadeOut('slow');
			}
		}, "json");
	});
});
