function friendFeedTasks(id) {
	this.id = id;
	
	this.toggleComments = "ff_togglecommentslink_" + id;
	this.discussions = 'friendfeeddiscussions_' + id;
	this.newComment = 'ff_newcomment_' + id;
	this.loadingImg = 'ff_loadingimage_' + id;
	this.userName = 'ff_username_' + id;
	this.apiKey = 'ff_apikey_' + id;
	this.authSaved = 'ff_authsaved_' + id;
	this.authEntry = 'ff_authentry_' + id;
	this.commentsForm = 'ff_commentsform_' + id;
	this.likeButton = 'ff_likeentry_' + id;
	this.logoutButton = 'ff_forgetauth_' + id;
	this.commentsList = 'friendfeedcommentslist_' + id;
	this.likesList = 'friendfeedlikeslist_' + id;
	this.remember = 'ff_remember_' + id;
	this.usernameDisplay = 'ff_usernamedisplay_' + id;
	
	this.toggleDiscussions = function (e) { 
		Event.stop(e);

		$(this.discussions).toggle(); 
		$(this.toggleComments).update((!$(this.discussions).visible() ? 'show' : 'hide'));  
	}
	
	this.addComment = function (e) {
		Event.stop(e);
		
		if ($F(this.newComment)) {
			this.sendAjaxRequest('comment');
		}
	}
	
	this.addLike = function (e) { 
		Event.stop(e);
		this.sendAjaxRequest('like');
	}

	this.logout = function (e) {
		Event.stop(e);
		this.sendAjaxRequest('logout');
	}
	
	this.sendAjaxRequest = function (action) {
		var form = $(this.commentsForm);
		var id = this.id;
		$(this.loadingImg).show();

		if (action != 'logout' && ((!$F(this.userName) || !$F(this.apiKey)) && !$(this.authSaved).visible())) {
			alert('Please enter your FriendFeed username (nickname) and API Key.');
			$(this.userName).focus();
		} else {		
			body = Form.serialize(form, true);
			body.ac = action;
			Form.disable(form);

			new Ajax.Request(friendFeedServicePath + "friendfeed_ajax.php", {
				method : 'get',
				parameters : body,
				postBody : body,
				onSuccess : function(resp) { 
					if (action == 'logout') {
						$(this.userName).clear();
						$(this.apiKey).clear();
						$(this.authEntry).show();
						$(this.authSaved).hide();
						$(this.likeButton).enable();					
					} else {				
						$(action = 'comment' ? this.commentsList : this.likesList).update(resp.responseText); 
						if ($(this.remember).checked && $(this.authEntry).visible()) {
							$(this.usernameDisplay).update($F(this.userName));
							$(this.authEntry).hide();
							$(this.authSaved).show();							
						}
						$(this.newComment).clear();
					}
				},
				onFailure : function(e) { 
					if (e.status == 401) {
						alert("Sorry, the username & API key don't match");
						$(this.userName).focus();
					} else {
						alert("Sorry, an error occured: (" + e.status + ") " + e.statusText + "\n" + e.responseText);
						$(this.newComment).focus();
					}
				},
				onComplete : function() { 
					Form.enable(form); 
					 $(this.loadingImg).hide();
				}
			 });
		}
	}
	
	this.observeForm = function() {
		$(this.commentsForm).observe('submit', this.addComment.bindAsEventListener(this));
		$(this.likeButton).observe('click', this.addLike.bindAsEventListener(this));
		$(this.logoutButton).observe('click', this.logout.bindAsEventListener(this));
	}
	
	this.observeShowHide = function() {
		$(this.toggleComments).observe('click', this.toggleDiscussions.bindAsEventListener(this));
	}
}