/*
 * jQuery Object Cache 0.1  
 * By Luciano Germán Panaro (http://www.decodeuri.com)
 * Project site: http://www.decodeuri.com/selection-cache 
 *
 * Copyright (c) 2009 Luciano Germán Panaro
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.gnu.org/licenses/gpl-2.0.txt) licenses.
*/

; if(window.jQuery) {

  _$$ = window.$$; //in case overwrite
  
  window.jQueryCache = window.$$ = function($) {
   
      // Add object_cache dictionary to jQuery 
      $.extend({
          object_cache: {}    
      });      

      $.fn.extend({
                  
          cache: function (key) {
              if (typeof key == "string") {
                  $.object_cache[key] = this;
              }              
              return this;
          }
          
      });

      // $$() function and methods
      
      var jQueryCache = function( key ) {
          if (!key || typeof key != "string" || !$.object_cache[key]) return false;
          return $.object_cache[key];
      };
      
      jQueryCache.remove = function( key ) {          
          $.object_cache[key] = null;      
      };
      
      jQueryCache.clear = function() {
          $.object_cache = [];
      };      
      
      jQueryCache.noConflict = function() {
          window.$$ = _$$;
          return jQueryCache;
      }      

      return jQueryCache;
  
  }(jQuery);
  
}

