/**
 * @author Hollin Wilkins
 */

if( !YAHOO.widget.Module.prototype.HTTPInit ) {
	
	/**
	 * @namespace YAHOO.widget
	 * @class Module
	 */
	
	/**
	 * @method HTTPInit
	 * @param {String} url The URL that contains the panel
	 * @param {String} id The ID of the panel
	 * @param {Object} userCondif The configuration parameter for a module
	 */
	YAHOO.widget.Module.prototype.HTTPInit = function(url, id, userConfig) {
		var callback = {
			success:YAHOO.widget.Module._HTTPInitCallback.success,
			failure:YAHOO.widget.Module._HTTPInitCallback.failure,
			scope:this,
			argument: {id: id, userConfig: userConfig}
		};
		
		/**
		 * Whether or not the module has completed loading
		 * @property _READY
		 * @type Boolean
		 * @private
		 */
		this._READY = false;
		
		if( YAHOO.util.Connect && !document.getElementById(id) ) {
			YAHOO.util.Connect.asyncRequest("GET", url, callback);
		}
	};
	
	/**
	 * Ajax callback for initializing a Module.
	 * @property _HTTPInitCallback
	 * @private
	 */
	YAHOO.widget.Module._HTTPInitCallback = {
		/**
		 * Handles success case of loading a module
		 * @property _HTTPInitCallback.success
		 * @type Function
		 * @private
		 */
		success:function(o) {
			if( !document.getElementById(o.argument.id) ) {
				var containerDiv = document.createElement("div");
				containerDiv.innerHTML = o.responseText;
				document.body.appendChild(containerDiv);

				this.init(o.argument.id, o.argument.userConfig);
				
				this._READY = true;
			}
		},
		
		/**
		 * Handles failure case of loading a module
		 * @property _HTTPInitCallback.success
		 * @type Function
		 * @private
		 */
		failure:function(o) {
			// do nothing
		}
	}
}