(function(){

	//Create the namespace for the shoutbox
	YAHOO.namespace("OurTown.modules.ShoutBox");

	//Create shortcuts to YAHOO objects
	var Dom = YAHOO.util.Dom;
	var Connect = YAHOO.util.Connect;


	//Create the class with our static methods
	OurTown.modules.ShoutBox = {
		baseFolder : "",

		addShout: function(iId){
			//Get name, comment, and sticky status
			var oNameEl = Dom.get("ourtown-module-fullshoutbox" + iId + "-name");
			var oCommentEl = Dom.get("ourtown-module-fullshoutbox" + iId + "-message");

			if (oNameEl && oCommentEl){
				var sName, sComment, bSticky;
				sName = oNameEl.value;
				sComment = oCommentEl.value;

				var oStickyEl = Dom.get("ourtown-module-fullshoutbox" + iId + "-sticky");
				if (oStickyEl){
					bSticky = oStickyEl.checked;
				} else {
					bSticky = false;
				}

				//Build URL for request
				var sUrl = this.baseFolder + "/modules/fullshoutbox/AddShout.asp?";
				sUrl += "txtComment=" + sComment;
				sUrl += "&txtName=" + sName;
				sUrl += "&chkSticky=" + bSticky;

				//Send request to server
				Connect.asyncRequest("GET", sUrl);
			}
		},

		getShouts: function(iId){
			//Build Url for request
			var sUrl = this.baseFolder + "/modules/fullshoutbox/GetShouts.asp?id=" + iId;

			//Send request and set callback handler
			Connect.asyncRequest("GET", sUrl, {
				success: this.handleGetShoutsSuccess,
				failure: this.handleGetShoutsFailure,
				argument: iId,
				cache: false
			});
		},

		deleteShout: function(iCommentId){
			//Build Url for request
			var sUrl = this.baseFolder + "/modules/fullshoutbox/DeleteShout.asp?ShoutboxItemID=" + iCommentId;

			//Send request and set callback handler
			Connect.asyncRequest("GET", sUrl, {
				success: this.handleDeleteShoutSuccess,
				failure: this.handleDeleteShoutFailure
			});
		},

		resetInputs: function(iId){
			//Reset two form inputs to default state
			var oNameEl = Dom.get("ourtown-module-fullshoutbox" + iId + "-name");
			var oCommentEl = Dom.get("ourtown-module-fullshoutbox" + iId + "-message");

			if (oNameEl && oCommentEl){
				oNameEl.value = "Name";
				oCommentEl.value = "Comment";
			}
		},

		handleGetShoutsSuccess: function(oResponse){
			//Replace the shouts list with the response
			var sResponse = oResponse.responseText;
			//Get id from argument passed in
			var iId = oResponse.argument;
			var oList = Dom.get("ourtown-module-fullshoutbox" + iId + "-comments");
			if (oList){
				oList.innerHTML = sResponse;
			}
		},

		handleGetShoutsFailure: function(e){

		},

		handleDeleteShoutSuccess: function(e){

		},
		
		handleDeleteShoutFailure: function(e){

		}
	};

	//Set base folder
	OurTown.modules.ShoutBox.baseFolder = OurTown.util.getBaseUrl();
	
})();