var aistatus = new Object();

	/**
	 *	Function:					aistatus.init
	 *	Purpose:					initializes by adding a click listener to a container
	 */	

	aistatus.init = function () {
		if(document.getElementById("idolStatusUpdaterDefault")) {
			YAHOO.util.Event.addListener("idolStatusUpdaterDefault", "click", aistatus.initEditBox);
		}
	}
	
	/**
	 *	Function:					aistatus.createEditBox
	 *	Purpose:					Creates and returns the field necessary for the user to edit status
	 */	

	aistatus.createEditBox = function () {
		this.box = document.createElement('input');
		this.box.setAttribute('type', 'text');
		this.box.id = "statusUpdateInputBox";
		this.box.setAttribute("maxlength", "95");
		this.keyer = new YAHOO.util.KeyListener(this.box, {keys:13},{fn:aistatus.submitStatus});
		this.keyer.enable();
		YAHOO.util.Event.addListener(document.body, "click", aistatus.killEditBox);
		return this.box;
	}
	
	/**
	 *	Function:					aistatus.createEditButton
	 *	Purpose:					Creates and returns the button to initiate the update call
	 */	

	aistatus.createEditButton = function () {
		this.button = document.createElement('button');
		this.button.id = 'statusUpdateSubmitButton';
		this.button.innerHTML = '<span>Update</span>';
		YAHOO.util.Event.addListener(this.button, 'click', aistatus.submitStatus);
		return this.button;
	}
	
	/**
	 *	Function:					aistatus.checkForEnter
	 *	Purpose:					Checks to see if the enter key was pressed
	 */	

	aistatus.checkForEnter = function () {
		
	}
	
	/**
	 *	Function:					aistatus.killEditBox
	 *	Purpose:					Removes the update field and button from the DOM, unhides default text
	 */	

	aistatus.killEditBox = function () {
		this.editBox = document.getElementById('statusUpdateInputBox');
		this.editButton = document.getElementById('statusUpdateSubmitButton');
		this.editBox.parentNode.removeChild(this.editBox);
		this.editButton.parentNode.removeChild(this.editButton);
		YAHOO.util.Dom.setStyle('idolStatusUpdaterDefault', 'display', '');
		YAHOO.util.Event.removeListener(document.body, "click", aistatus.killEditBox);
	}
	
	/**
	 *	Function:					aistatus.initEditBox
	 *	Purpose:					Calls methods to create input field and button, inserts them into the DOM
	 */	

	aistatus.initEditBox = function (e) {
		YAHOO.util.Event.stopEvent(e);
		this.statusBox = aistatus.createEditBox();
		this.statusButton = aistatus.createEditButton();	
		YAHOO.util.Dom.setStyle('idolStatusUpdaterDefault', 'display', 'none');
		document.getElementById('idolStatusUpdater').appendChild(this.statusBox);
		document.getElementById('idolStatusUpdater').appendChild(this.statusButton);
		this.statusBox.focus();
	}
	
	/**
	 *	Function:					aistatus.submitStatus
	 *	Purpose:					Gets status message from input field, initiates AJAX call
	 */	

	aistatus.submitStatus = function (e) {
		YAHOO.util.Event.stopEvent(e);
		var params = new Array();
		params['responseFunction'] = aistatus.updateStatusText;
		params['status'] = document.getElementById('statusUpdateInputBox').value;
		params['type'] = 'both';
		params['action'] = 'updateStatus';
		params['responseType'] = 'JSON';
		params['responseFormat'] = 'JSON';
		params['handlerName'] = 'one_ajax_statusHandler';
		params['requestType'] = 'class';
		params['sdb'] = 1;
		this.editBox = document.getElementById('statusUpdateInputBox');
		this.editButton = document.getElementById('statusUpdateSubmitButton');
		
		this.editBox.setAttribute('disabled', 'disabled');
		this.editButton.innerHTML = '<span>Updating</span>';
		this.editButton.setAttribute('disabled', 'disabled');

		//Make the request
		OneAjax.request(params);	
	}
	
	/**
	 *	Function:					aistatus.updateStatusText
	 *	Purpose:					updates user's status message in the DOM, initiates aistatus.killEditBox method
	 *
	 *	@param object response		returned from AJAX call, JSON array containing success/failure message and updated status message
	 */	

	aistatus.updateStatusText = function (response) {
		document.getElementById('ownerStatusMessage').innerHTML = response.status_text;
		/*document.getElementById('ownerStatusUpdated').innerHTML = response.time;*/
		aistatus.killEditBox();
	}

YAHOO.util.Event.onDOMReady(aistatus.init);