if (!this.Rf) this.Rf = {};
(function(ns, $) {

ns.Require('Tooltip', ns);

/**
 * ns.Tooltip class that loads content from a URL, and then displays it in a tooltip
 * @param {Object} owner jQuery selector of the object to whom the tooltip pertains
 * @param {String} url The URL from which the tooltip's content is loaded
 * @param {Object} options Settings used to initialize the tooltip
 */
ns.AjaxTooltip = function(owner, url, options) {
	ns.Tooltip.call(this, owner, options);
	this.Url = url;
};
/**
 * (Static) Stores tooltip data loaded by URL for quick re-display of a tooltip
 */
ns.AjaxTooltip.Cache = {};
/**
 * Events that can be dispatched by the AjaxTooltip
 */
ns.AjaxTooltip.Events = {
	/**
	 * Dispatched when data is loaded into the tooltip
	 */
	Data : 'data'
};
ns.AjaxTooltip.prototype = new ns.Tooltip(null, {
	constructor : ns.AjaxTooltip,
	/**
	 * The URL from which the tooltip's content is loaded
	 */
	Url : null,
	/**
	 * Whether or not the tooltip data can be cached for quick reuse
	 */
	AllowCache : true,
	/**
	 * Loads the tooltip's content from the URL or the cache and then displays the tooltip
	 * @param {Function} callback A function that is executed using the acquired data
	 */
	AcquireContent : function(callback) {
		var dataEvent,
			me = this,
			lastly = function(data) {
				me.Dispatch(dataEvent = new ns.Event(ns.AjaxTooltip.Events.Data, me, data));
				callback.call(me, dataEvent.Data)
			};
		if (me.AllowCache && ns.AjaxTooltip.Cache[me.Url]) {
			lastly.call(me, ns.AjaxTooltip.Cache[me.Url]);
		}
		else {
			$.ajax({
				dataType: 'html',
				url: me.Url,
				success: function(response) {
					if (me.AllowCache && response.length > 0) ns.AjaxTooltip.Cache[me.Url] = response;
					lastly.call(me, response);
				}
			});
		}
		return me;
	}
});

})(Rf, jQuery);

