Problem downtown event images on demand

Problem downtown event images on demand

Hello, I am new to jquery and would like to, if possible, solve my problem. Sorry the mistakes, I'm brazilian is not very familiar with English.
Come on!
I have an event of low demand for images. I do not know for what reason, when the roll scroll to load images, the images start flashing before charging. This happens in Mozilla and Chrome, IE9 does not.
my code follows:

lazy:
  1. (function($, window) {
  2.     var $window = $(window);

  3.     $.fn.lazy = function(options) {
  4.         var elements = this;
  5.         var $container;
  6.         var settings = {
  7.             threshold       : 0,
  8.             failure_limit   : 100,
  9.             event           : "scroll", /*pode ser scroll ou click para colocar em um botao*/
  10.             effect          : "fadeIn", /*pode ser fadeIn ou Show para efeito de aparecimento da imagem*/
  11.             container       : window,
  12.             data_attribute  : "src", /* pode ser qualquer nome*/
  13.             skip_invisible  : true,
  14.             appear          : null,
  15.             load            : null
  16.         };

  17.         function update() {
  18.             var counter = 0;
  19.       
  20.             elements.each(function() {
  21.                 var $this = $(this);
  22.                 if (settings.skip_invisible && !$this.is(":visible")) {
  23.                     return;
  24.                 }
  25.                 if ($.abovethetop(this, settings) ||
  26.                     $.leftofbegin(this, settings)) {
  27.                         /* Nada. */
  28.                 } else if (!$.belowthefold(this, settings) &&
  29.                     !$.rightoffold(this, settings)) {
  30.                         $this.trigger("appear");
  31.                         /* se encontra uma imagem que ira carregar, redefinir o contador */
  32.                         counter = 0;
  33.                 } else {
  34.                     if (++counter > settings.failure_limit) {
  35.                         return false;
  36.                     }
  37.                 }
  38.             });

  39.         }
  40.         
  41.         if(options) {
  42.            
  43.             if (undefined !== options.failurelimit) {
  44.                 options.failure_limit = options.failurelimit; 
  45.                 delete options.failurelimit;
  46.             }
  47.             if (undefined !== options.effectspeed) {
  48.                 options.effect_speed = options.effectspeed; 
  49.                 delete options.effectspeed;
  50.             }

  51.             $.extend(settings, options);
  52.         }

  53.         
  54.         $container = (settings.container === undefined ||
  55.                       settings.container === window) ? $window : $(settings.container);

  56.         /* Dispara um evento de rolagem por rolagem. Não um evento de rolagem por imagem. */
  57.         if (0 === settings.event.indexOf("scroll")) {
  58.             $container.bind(settings.event, function(event) {
  59.                 return update();
  60.             });
  61.         }

  62.         this.each(function() {
  63.             var self = this;
  64.             var $self = $(self);

  65.             self.loaded = false;

  66.             /* Quando aparecer é acionado imagem-original. */
  67.             $self.one("appear", function() {
  68.                 if (!this.loaded) {
  69.                     if (settings.appear) {
  70.                         var elements_left = elements.length;
  71.                         settings.appear.call(self, elements_left, settings);
  72.                     }
  73.                     $("<img />")
  74.                         .bind("load", function() {
  75.                             $self
  76.                                 .hide()
  77.                                 .attr("src", $self.data(settings.data_attribute))
  78.                                 [settings.effect](3000);
  79.                             self.loaded = true;

  80.                             /* Remover imagem do array para não exibir na próxima vez. "não repetir imagens" */
  81.                             var temp = $.grep(elements, function(element) {
  82.                                 return !element.loaded;
  83.                             });
  84.                             elements = $(temp);

  85.                             if (settings.load) {
  86.                                 var elements_left = elements.length;
  87.                                 settings.load.call(self, elements_left, settings);
  88.                             }
  89.                         })
  90.                         .attr("src", $self.data(settings.data_attribute));
  91.                 }
  92.             });

  93.             /* Quando o evento imagem-original é acionado, mostra a/as imagem */
  94.             if (0 !== settings.event.indexOf("scroll")) {
  95.                 $self.bind(settings.event, function(event) {
  96.                     if (!self.loaded) {
  97.                         $self.trigger("appear");
  98.                     }
  99.                 });
  100.             }
  101.         });

  102.         /* Verifica se há alguma imagem para aparecer quando a janela é dimensionada */
  103.         $window.bind("resize", function(event) {
  104.             update();
  105.         });

  106.         /* Força verificação se imagem deve aparecer */
  107.         $(document).ready(function() {
  108.             update();
  109.         });
  110.         
  111.         return this;
  112.     };


  113.     $.belowthefold = function(element, settings) {
  114.         var fold;
  115.         
  116.         if (settings.container === undefined || settings.container === window) {
  117.             fold = $window.height() + $window.scrollTop();
  118.         } else {
  119.             fold = $(settings.container).offset().top + $(settings.container).height();
  120.         }

  121.         return fold <= $(element).offset().top - settings.threshold;
  122.     };
  123.     
  124.     $.rightoffold = function(element, settings) {
  125.         var fold;

  126.         if (settings.container === undefined || settings.container === window) {
  127.             fold = $window.width() + $window.scrollLeft();
  128.         } else {
  129.             fold = $(settings.container).offset().left + $(settings.container).width();
  130.         }

  131.         return fold <= $(element).offset().left - settings.threshold;
  132.     };
  133.         
  134.     $.abovethetop = function(element, settings) {
  135.         var fold;
  136.         
  137.         if (settings.container === undefined || settings.container === window) {
  138.             fold = $window.scrollTop();
  139.         } else {
  140.             fold = $(settings.container).offset().top;
  141.         }

  142.         return fold >= $(element).offset().top + settings.threshold  + $(element).height();
  143.     };
  144.     
  145.     $.leftofbegin = function(element, settings) {
  146.         var fold;
  147.         
  148.         if (settings.container === undefined || settings.container === window) {
  149.             fold = $window.scrollLeft();
  150.         } else {
  151.             fold = $(settings.container).offset().left;
  152.         }

  153.         return fold >= $(element).offset().left + settings.threshold + $(element).width();
  154.     };

  155.     $.inviewport = function(element, settings) {
  156.          return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) &&
  157.                 !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
  158.      };

  159.     /*  */

  160.     $.extend($.expr[':'], {
  161.         "below-the-fold" : function(a) { return $.belowthefold(a, {threshold : 0}); },
  162.         "above-the-top"  : function(a) { return !$.belowthefold(a, {threshold : 0}); },
  163.         "right-of-screen": function(a) { return $.rightoffold(a, {threshold : 0}); },
  164.         "left-of-screen" : function(a) { return !$.rightoffold(a, {threshold : 0}); },
  165.         "in-viewport"    : function(a) { return $.inviewport(a, {threshold : 0}); },
  166.         
  167.         "above-the-fold" : function(a) { return !$.belowthefold(a, {threshold : 0}); },
  168.         "right-of-fold"  : function(a) { return $.rightoffold(a, {threshold : 0}); },
  169.         "left-of-fold"   : function(a) { return !$.rightoffold(a, {threshold : 0}); }
  170.     });

  171. })(jQuery, window);
scrollstop:
  1. (function(){
  2.     
  3.     var special = jQuery.event.special,
  4.         uid1 = 'D' + (+new Date()),
  5.         uid2 = 'D' + (+new Date() + 1);
  6.         
  7.     special.scrollstart = {
  8.         setup: function() {
  9.             
  10.             var timer,
  11.                 handler =  function(evt) {
  12.                     
  13.                     var _self = this,
  14.                         _args = arguments;
  15.                     
  16.                     if (timer) {
  17.                         clearTimeout(timer);
  18.                     } else {
  19.                         evt.type = 'scrollstart';
  20.                         jQuery.event.handle.apply(_self, _args);
  21.                     }
  22.                     
  23.                     timer = setTimeout( function(){
  24.                         timer = null;
  25.                     }, special.scrollstop.latency);
  26.                     
  27.                 };
  28.             
  29.             jQuery(this).bind('scroll', handler).data(uid1, handler);
  30.             
  31.         },
  32.         teardown: function(){
  33.             jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
  34.         }
  35.     };
  36.     
  37.     special.scrollstop = {
  38.         latency: 300,
  39.         setup: function() {
  40.             
  41.             var timer,
  42.                     handler = function(evt) {
  43.                     
  44.                     var _self = this,
  45.                         _args = arguments;
  46.                     
  47.                     if (timer) {
  48.                         clearTimeout(timer);
  49.                     }
  50.                     
  51.                     timer = setTimeout( function(){
  52.                         
  53.                         timer = null;
  54.                         evt.type = 'scrollstop';
  55.                         jQuery.event.handle.apply(_self, _args);
  56.                         
  57.                     }, special.scrollstop.latency);
  58.                     
  59.                 };
  60.             
  61.             jQuery(this).bind('scroll', handler).data(uid2, handler);
  62.             
  63.         },
  64.         teardown: function() {
  65.             jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
  66.         }
  67.     };
  68.     
  69. })();
and the call is made so:
  1. <script src="<%=urlhttp%>js2/jquery.1.7.0.min.js" type="text/javascript" charset="utf-8"></script>
  2.   <script src="<%=urlhttp%>js2/jquery.scrollstop.js" type="text/javascript" charset="utf-8"></script>
  3.   <script src="<%=urlhttp%>js2/jquery.lazy.js" type="text/javascript" charset="utf-8"></script>
  4.   <script type="text/javascript" charset="utf-8">
  5.   jQuery.noConflict();
  6.   jQuery(document).ready(function($){
  7.           $("img").lazy({
  8.               event: "scrollstop"
  9.           });
  10.       });
  11. </script>
when I hide the comment, not true flashing images, but does not happen in the fadein slow.