$(document).ready(function() {
	$('.add_friend').bind("click",function(event) {
		event.preventDefault();
		toid = $(this).attr('rel');
		
		$.post("/includes/friends_add.php", {
			'toid' : toid
			}, function(data) {
				if(data == 'success') {
					_lag.hover_box('#request_sent');
					setTimeout(function(){window.location.reload();}, 2000);
				} else {
					$(_lag.target).html(_lag.temp);
					$('#hover_box').css({'display' : 'none'});
					$('#modal-overlay').css({'display' : 'none'});
					_lag.popped = false;
					$("#add_friend_container").html(data);
				}
		});
	});
	$('.approve_yes').bind("click",function(event) {
		event.preventDefault();
		toid = $(this).attr('rel');
		
		$.post("/includes/friends_confirm.php", {
			'toid' : toid,
			'approve' : '1'
			}, function(data) {
				if(data == 'success') {
					_lag.hover_box('#request_sent');
					setTimeout(function(){window.location.reload();}, 2000);
				} else {
					$(_lag.target).html(_lag.temp);
					$('#hover_box').css({'display' : 'none'});
					$('#modal-overlay').css({'display' : 'none'});
					_lag.popped = false;
					$("#add_friend_container").html(data);
				}
		});
	});
	$('.approve_no').bind("click",function(event) {
		event.preventDefault();
		toid = $(this).attr('rel');
		
		$.post("/includes/friends_confirm.php", {
			'toid' : toid,
			'approve' : '0'
			}, function(data) {
				if(data == 'success') {
					_lag.hover_box('#request_sent');
					setTimeout(function(){window.location.reload();}, 2000);
				} else {
					$(_lag.target).html(_lag.temp);
					$('#hover_box').css({'display' : 'none'});
					$('#modal-overlay').css({'display' : 'none'});
					_lag.popped = false;
					$("#add_friend_container").html(data);
				}
		});
	});
	$('.friend_delete').each(
		function(idx) {
			$(this).bind(
			"click",
			function(event) {
				event.preventDefault();
				var id = $(this).attr('id');
				var container = $(this).parent().parent();
				$.post("/includes/friends_delete.php", {
					'friendID' : id
					}, function(data) {
						if(data == 'success') {
							$(container).remove();
						}
				});
			});
		}
	);
});
