/** 
* @description TWITSTEPS object
* @object TWITSTEPS
* @public
*/
var TWITSTEPS = TWITSTEPS || {

	/** 
	* @description Strings table
	* @object oStrings
	* @private
	*/
	strings: {
		
		deletePost: 'Are you sure you want to delete this post?',
		genericError: 'Sorry, an error occurred. Try refreshing the page and submitting your request again.',
		loading: 'loading...',
		loginFailed: 'You\'re credentials could not be verified.\n\nTwitter may be over capacity.\n\nPlease wait a moment and try again.',
		noSitesAlert: 'You don\'t have any widgets defined yet!\n\nClick on the "Create new widget" link to the left.',
		noSitesBody: 'You made it! Click the "Create new widget" link to the left to get started!',
		noTabSelected: 'You\'ll need to show at least one of the tabs.',
		settingsSaved: 'You\'re settings have been saved.',
		siteNameInValid: 'Letters and numbers only please (no spaces) and 20 characters max.'
		
	}


};

/** 
* @description TWITSTEPS object ext
* @object TWITSTEPS.base
* @public
*/
TWITSTEPS.base = function(){

	// initialize locals
	var _d = YAHOO.util.Dom,
		_e = YAHOO.util.Event,
		_c = YAHOO.util.Connect;

	// log out link
	var elLogOut = _d.get('log_out');

	/** 
	* @description Logs user out of twitter
	* @method doLogOut
	* @private
	*/
	var doLogOut = function(e){

		// will represent the request object
		var oRequest = null;

		/** 
		* @description Success handler
		* @method handleSuccess
		* @private
		*/
		var handleSuccess = function(){

			// forward to login
			window.location.href = g_sBasePath;

		}

		/** 
		* @description Failure handler
		* @method handleFailure
		* @private
		*/
		var handleFailure = function(){

			// alert user
			alert(TWITSTEPS.strings.genericError);

		}

		return {
		
			/** 
			* @description Send the request to the logout svc.
			* @method send
			* @public
			*/
			send: function(e){

				// stop event from bubbling
				if (e){
					_e.stopEvent(e)
				}

				// get out if call in progress (in case
				// of multiple clicking)
				if (_c.isCallInProgress(oRequest)){
					return;
				}

				// service call
				oRequest = _c.asyncRequest(
					'POST',
					g_sBasePath + 'services/logout',
					{success:handleSuccess,	failure:handleFailure}
				);

			}
		
		}

	}();

	_e.on(elLogOut, 'click', doLogOut.send);

}();

