	
friendship = 
{
	completeDialog : function(obj, publicId, displayName)
	{
		$('add_pal_name').innerHTML = displayName;
		friendship.obj = obj;
		friendship.publicId = publicId;
		resetForm('addpal');
		showDialog('addpal');
	},
	
	completeCommentDialog : function(obj, postId, postName,commentBy)
	{
		//$('blog_post_name').innerHTML = postName;
		friendship.obj = obj;
		friendship.publicId = commentBy;
		resetForm('add_blog_comment');
		showDialog('add_blog_comment');
	},
	
	blog_comment_submit : function()
	{
		var message = $('pal_message').value;	
		new Ajax.Request('/friendship/commentblogpost?'+Math.random(),
		{
				method : 'get',
				parameters: {'member' : friendship.publicId, 'message' : message },
				onSuccess: function(data){
					var j = data.responseJSON;
					if(j.error)
						alert(j.error);
					else
						friendshipUIActions.updateButtons(friendship.obj, j.success);
				}
			}
		);
		hideDialogs();
		return false;
	},
	
	request : function()
	{
		var message = $('pal_message').value;	
		new Ajax.Request('/friendship/request?'+Math.random(),
		{
				method : 'get',
				parameters: {'member' : friendship.publicId, 'message' : message },
				onSuccess: function(data){
					var j = data.responseJSON;
					if(j.error)
						alert(j.error);
					else
						friendshipUIActions.updateButtons(friendship.obj, j.success);
				}
			}
		);
		hideDialogs();
		return false;
	},

	cancel : function(obj, publicId)
	{
		if (confirm("are you sure you want to decline the friendship?"))
		{	
			new Ajax.Request('/friendship/cancel?'+Math.random(),
				{
					method : 'get',
					parameters: {'member' : publicId},
					onSuccess: function(data){
						var j = data.responseJSON;
						if(j.error)
							alert(j.error);
						else
							friendshipUIActions.updateButtons(obj, j.success);
					}
				}
			);
		}
		return false;
	},
	
	remove : function(obj,publicid,name)
	{	
		var confirmString = "Are you sure you want to remove "+name+" from your pals?";
		if(window.confirm(confirmString))
		{
			new Ajax.Request('/friendship/remove?'+Math.random(),
				{
					method : 'get',
					parameters: {'member' : publicid},
					onSuccess: function(data){
						var j = data.responseJSON;
						if(j.error)
							alert(j.error);
						else
						{
							var parent = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
							new Effect.Parallel([new Effect.BlindUp(parent), new Effect.Fade(parent), new Effect.Appear($('remove-pal-message'))],{duration: 1});
						}
					}
				}
			);
		}
		return false;
	}
	
};

friendshipUIActions = 
{
	updateButtons : function(obj, action)
	{
       var parent = $(obj).parentNode;
		var grandparent = parent.parentNode;
		new Effect.Fade(parent,{
			afterFinish: function() {
				var el = $(grandparent).getElementsByClassName(action);
				new Effect.Appear(el[0]);
			}
		});
	}
}