friend =  
{
// Variables
	elmt: null,
	type: null,

// Functions
	action: function(called_by, userid, type)
	{
		friend.elmt = called_by;
		friend.type = type;

		if(type == 'delete_confirm' || type == 'deny_confirm')
		{
			friend.confirm(userid, type);
			return;
		}
		var params =
		{
			userid: userid,
			action: type
		}
		var url = '/json/friend.php';
		$.getJSON(url, params, friend.action_handler);
	},
	action_handler: function(o)
	{
		var msg;
		if(o.error)
			return;
		if(o.type)
			friend.type = o.type;

		
		switch(friend.type)
		{
			case 'request':
				msg = "Request Pending";
				break;
			case 'confirm':
				msg = "Friend Added";
				break;
			case 'is_friend':
				msg = "Already friends";
				break;
			case 'delete':
				msg = "Friend Deleted";
				break;
			case 'deny':
				msg = "Friend Denied";
				break;
		}
		$(friend.elmt).html(msg);;
		$(friend.elmt).removeClass('link');
	},
	confirm: function(userid, type)
	{
		$(friend.elmt).html("Seriously!?");
		var next_action = type.replace('_confirm', '');
		friend.elmt.onclick = function() { friend.action(friend.elmt, userid, next_action); }
	}
	
	
};
