// JavaScript Document
// 图片缓冲加载

$(document).ready(function(){
	$(function(){
	$("body").gxload({placeholder:"",threshold:500});
	})
}); 
	
	
$.fn.gxload = function(op){
	  div = this;
	  threshold = op.threshold;
	  return $.gxload(div,threshold);
	
	}

showimgs = function(div,threshold){
	imgs = div.find("img[src='']");
	//imgs = div.find("img[src='"+placeholder+"']");
		lens = imgs.length;
		  if(lens>0)
		  {
			  imgs.each(
					function(i){
					$(this).wimg(threshold);
								}
					);
			  }
	}

$.gxload = function(div,threshold){
	   //div.find("img[src='']").attr("src",placeholder);
	   showimgs(div,threshold);
	   $(window).bind("scroll",
	      function(){
			         showimgs(div,threshold);
			        }
	                 );
	}

$.fn.wimg = function(threshold){
	    simg = this;
	    return $.wimg(simg,threshold);
	}
	
$.wimg =function(simg,threshold){
    if((simg.offset().top-$(window).scrollTop())<$(window).height()+threshold)
	{
		  simg.fadeOut(function(){
	      src = simg.attr("pic");
			  if(String(src)!=String("undefined"))
			  {
			  simg.attr("src",src).removeAttr("pic").show();
			  }
		});
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
