
//create an ajaxmanager named cacheQueue 
var ajaxManager = $.manageAjax.create('ajaxManager', 
		{
			queue : 'clear',
			abortOld : true,
		    maxRequests: 1
		}); 

jQuery.fn.extend({
		loadOnce: function(URL, params, callback ) {
				 ajaxManager.abort();
				 
				 callback = callback || function(){};
				 
				 // Default to a GET request
				 var type = "GET";
		
				 // If the second parameter was provided
				 if ( params )
					// If it's a function
					if ( jQuery.isFunction( params ) ) {
						// We assume that it's the callback
						callback = params;
						params = null;
		
					// Otherwise, build a param string
					} else {
						params = jQuery.param( params );
						type = "POST";
					}
				 
				 var self = this;
				 
				 ajaxManager.add({
				   type: type,
				   url:  URL,
				   data: params,
				   complete: function(res, status){
								// If successful, inject the HTML into all the matched elements
								if ( status == "success" || status == "notmodified" )
									// See if a selector was specified
									self.html( "" ?
										// Create a dummy div to hold the results
										jQuery("<div/>")
											// inject the contents of the document in, removing the scripts
											// to avoid any 'Permission Denied' errors in IE
											.append(res.responseText.replace(/<script(.|\s)*?\/script>/g, ""))
				
											// Locate the specified elements
											.find(selector) :
				
										// If not, just inject the full result
										res.responseText );
								// Add delay to account for Safari's delay in globalEval
								setTimeout(function(){
									self.each( callback, [res.responseText, status, res] );
								}, 13);		
							}
				});
			}});