function friend_ini(){
//	$j('#friend_button').fadeOut('slow', function() {
//		$j('#friend_button').unbind('click');
//		if(are_friends){
//			$j('#friend_button').html('<img src="/modules/people/images/trav_friend.gif" />');
//			$j('#friend_button').click(function(){ friend_info(this_member, del_display, became_friends); });
//		} else {
//			$j('#friend_button').html('<img src="/modules/people/images/trav_friend_add.gif" />');
//			$j('#friend_button').click(function(){ add_friend(this_member); });
//		}
//	});
//	$j('#friend_button').fadeIn('slow');
	
	$j('#friend_button_small').fadeOut('slow', function() {
		$j('#friend_button_small').unbind('click');
		if(are_friends){
			$j('#friend_button_small').text('You are their friend!');
			$j('#friend_button_small').addClass('isfriend');
			$j('#friend_button_small').click(function(){ friend_info(this_member, del_display, became_friends); });
		} else {
			$j('#friend_button_small').text('Add them as a friend!');
			$j('#friend_button_small').removeClass('isfriend');
			$j('#friend_button_small').click(function(){ add_friend(this_member); });
		}
	});
	$j('#friend_button_small').fadeIn('slow');
}

function remove_check(this_member, del_display, became_friends){
	var html = '<h2>Remove This Friend: Are you sure?</h2><p>If you wish to remove them as a friend, <a href="javascript:del_friend(\''+this_member+'\', \''+del_display+'\');">you can click here</a>.</p><p>After removing them, you will no longer recieve updates from them and they won\'t show up as a friend on your profile.</p>';
	$j.facebox(html);
}

function add_friend(friend){
	$j.ajax({
		type: 'POST',
		url: base_url+'/peopleFriend/add_friend?ajax=1',
		dataType: 'json',
		data: 'friend='+friend,
		success: function(msg){
			if(msg['error']){
				$j.facebox(msg['error']);
				return;
			}
			are_friends = true;
			friend_ini();
		},
		error: function(msg){
			$j.facebox('There was a problem adding this friend. Please try again later.');
		}
	});
}

function del_friend(friend, display){
	//alert('Friend Deleted! '+friend+'/'+display); return;
	$j.ajax({
		type: 'POST',
		url: base_url+'/peopleFriend/del_friend?ajax=1',
		dataType: 'json',
		data: 'friend='+friend,
		success: function(msg){
			if(msg['error']){
				$j.facebox(msg['error']);
				return;
			}		
			are_friends = false;
			$j.facebox('That friend has been removed.');
			if(display == 1){
				// If they are on a profile page, change the button to "add a friend".
				friend_ini();
			} else {
				// ...otherwise simply hide the item that has an id of 'friend-#'.
				$j('#friend-'+friend).fadeOut('slow');
			}
		},
		error: function(msg){
			$j.facebox('There was a problem removing this friend. Please try again later.');
		}
	});
}

function mute_toggle(friend){
	//Figure out if we are muting or unmuting!
	var html =  $j('#friend-'+friend+' a.mute_button').html();
	if(html == 'Mute'){
		var mute = 'y';
	} else {
		var mute = 'n';
	}
	$j.ajax({
		type: 'POST',
		url: base_url+'/peopleFriend/mute_friend?ajax=1',
		dataType: 'json',
		data: 'friend='+friend+'&mute='+mute,
		success: function(msg){
			if(msg['error']){
				$j.facebox(msg['error']);
				return;
			}		
			var mute_button = $j('#friend-'+friend+' a.mute_button');
			mute_button.fadeOut('slow', function(){
				if(mute == 'y'){
					mute_button.html('Unmute');
					$j('#friend-'+friend+' span.mute_status').html('You have muted this friend!');
				} else {
					mute_button.html('Mute');
					$j('#friend-'+friend+' span.mute_status').html('');
				}			
			});
			mute_button.fadeIn('slow');
		},
		error: function(msg){
			$j.facebox('There was a problem modifying this friend\'s mute settings. Please try again later.');
		}
	});
}
