(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
  
  $.fn.cross = function (options) {
      return this.each(function (i) { 
          // cache the copy of jQuery(this) - the start image
          var $$ = $(this);
          
          // get the target from the backgroundImage + regexp
          var target = $$.css('backgroundImage').replace(/^url|[\(\)'"]/g, '');

          // nice long chain: wrap img element in span
          $$.wrap('<span style="position: relative;"></span>')
              // change selector to parent - i.e. newly created span
              .parent()
              // prepend a new image inside the span
              .prepend('<img>')
              // change the selector to the newly created image
              .find(':first-child')
              // set the image to the target
              .attr('src', target);

          if ($.browser.msie || $.browser.mozilla) {
              $$.css({
                  'position' : 'absolute', 
                  'left' : 0,
                  'background' : '',
                  'top' : this.offsetTop
              });
          } else if ($.browser.opera && $.browser.version < 9.5) {
             
              $$.css({
                  'position' : 'absolute', 
                  'left' : 0,
                  'background' : '',
                  'top' : "0"
              });
          } else { // Safari
              $$.css({
                  'position' : 'absolute', 
                  'left' : 0,
                  'background' : ''
              });
          }


          $$.hover(function () {
              $$.stop().animate({
                  opacity: .25
              }, 550);
          }, function () {
              $$.stop().animate({
                  opacity: 1
              }, 550);
          });
      });
  };
  
  
})(jQuery)

