/* 
 * jQuery.imagesLoad.js
 * © 2011 kumagaiyusuke
*/

(function ($) {
  
  $.imagesLoad = function ($target) {
    
    var $images = $target.find("img");
    var count = 0;
    
    if ($images.length === 0) {
      $target.trigger($.imagesLoad.IMAGES_LOAD);
    }

    $images.each(function(i){
      
      var orgSrc = this.src;
      
      if (!$.browser.msie) {
        this.src = "";
      }
      
      $(this).bind("load", function () {
        
        ++count;

        if (count === $images.length) {
          $target.trigger($.imagesLoad.IMAGES_LOAD);
        }
      });
      
      if (!$.browser.msie) {
        this.src = orgSrc;
      }
      
      else if (this.complete || this.complete === undefined) {
        this.src = orgSrc;
      }
      
    });
    
  };
  
  $.imagesLoad.IMAGES_LOAD = "imagesload";
  
})(jQuery);

