(function($){
    $.fn.zoom = function(settings){
        //一些默认配置；
        settings = $.extend({
            height:0,
            width:0,
            loading:"/plugin/imgloading/jquery-img-loading.gif"
            },settings);
        
        var images = this;
        $(images).hide();
        var loadding = new Image();
        loadding.className="loadding"
        loadding.src = settings.loading;
        $(images).after(loadding);
        
        //预加载
        var preLoad = function($this){
            var img = new Image();
            img.src = $this.src;
            if (img.complete) { 
                processImg.call($this);
                return;
            }
            img.onload = function(){
                processImg.call($this);
                img.onload=function(){};
            }
        }
        
        //计算图片尺寸；
        function processImg(){
                var m = this.height-settings.height;
                var n = this.width - settings.width;
                if(m>n)                        
                    this.height = this.height>settings.height ? settings.height : this.height;
                else
                    this.width = this.width >settings.width ? settings.width : this.width;
                $(this).next(".loadding").remove()
                $(this).show();
        }
        
        return $(images).each(function(){
            preLoad(this);
        });
    }
})(jQuery);
