jQuery.noConflict();
/*
 * 图片延迟加载 + 等比例自动缩放
*/
jQuery.fn.loadImage=function(isScaling,isHighMiddle,isLineMiddle,errImgUrl){
 
	jQuery(this).each(function(){
			var m_this = jQuery(this);
			var revise = function() {
				var imageLoader = {
						//自动缩放图片
						scaling: function(){

									if(isScaling){
										var widthValue = 0;
										var heightValue = 0;
										if(img.width/img.height>=width/height){ 
											if(img.width>width){

												widthValue = width;
												heightValue = (img.height*width)/img.width;
											}else{ 

												widthValue = img.width;
												heightValue = img.height;
											} 
										}else{ 
											if(img.height>height){
							
												widthValue = (img.width*height)/img.height;
												heightValue = height;
											}else{ 
						  
												widthValue = img.width;
												heightValue = img.height;
											} 
										}
										// 赋值
										if(null != widthValue && 0 < widthValue){
						
											t.width(widthValue); 
										}
										if(null != heightValue && 0 < heightValue){
						
											t.height(heightValue);
										}
									}
						},
						// 图片居中
						center: function(){
									// 居中
									if(isHighMiddle){// 高居中
								
										var imgHeightStr = jQuery(t).css("height");
										var imgHeight = imgHeightStr.substring(0, imgHeightStr.length - 2);
										var marginTop = parseInt(Number((height - imgHeight) / height / 2 * 100));
										if(0 < marginTop){
								
											jQuery(t).css("margin-top", marginTop + "%");
										}
									}
									if(isLineMiddle){// 行居中
								
										var imgWidthStr = jQuery(t).css("width");
										var imgWidth = imgWidthStr.substring(0, imgWidthStr.length - 2);
										var marginLeft = parseInt(Number((width - imgWidth)/ width / 2 * 100));
										if( 0 < marginLeft){
								
											jQuery(t).css("margin-left", marginLeft + "%");
										}
									}
						}
				}
				var width = m_this.attr("width");
				var height = m_this.attr("height");
				var t=m_this;
				var img=new Image();
				img.onload = function(){
					imageLoader.scaling();
					imageLoader.center();
				}
				img.src=m_this.attr("src");
			}
			var loadErrImg = function() {
				if (!errImgUrl) {
					errImgUrl = 'http://pic1.eachnet.com/upload/itempic_188x188.GIF';
				}
				m_this.attr("src", errImgUrl);
			};
			var realSrc = m_this.attr('realSrc');
			if (!!realSrc) {
				var imgObj = new Image();
				imgObj.onload = function() {
					m_this.attr("src", this.src);
					revise();
				}
				imgObj.onerror = function() {
					loadErrImg();
				}
				imgObj.src = realSrc;
			} else {
				if (realSrc == null) {
					revise();
				} else {
					loadErrImg();
				}
			}
		}
	);
}
