/************************************
*	describe:
*	author:	jay
* date:		2008-2-1
************************************/
/*
* 等比放缩W，以最大边为准,f=1一空白填充矩形，f=2 填充父窗口
*/
function resize2(o,w,f){
	if(!w)return;
	var img=new Image();
	img.onerror=function(){return false;}
	img.onload=function(){
		if(this.readyState!='complete')return;
		var W=img.width,H=img.height;
		var p=w/Math.max(W,H);
		o.className="";
		o.width=p*W;o.height=p*H;
    if(f==1){
      if(o.width<w)o.hspace=(w-o.width)/2;
      if(o.height<w)o.vspace=(w-o.height)/2;
    }else if(f==2){
      W=o.parentNode.offsetWidth;
      H=o.parentNode.offsetHeight;
      if(o.width<W){
        o.hspace=(W-o.width)/2;
      }
      if(o.width<H){
        o.height=(H-o.height)/2;
      }
    }
	}
	img.src=o.src;
}
//图片等比放缩W，以最小边为准，如果超出裁减
function resize(o,w,f){
	if(!w)return;
	var img=new Image();
	img.onerror=function(){return false;}
	img.onload=function(){
		if(!this.width)return;
		o.className="";
		var W=img.width,H=img.height;
		if(f==1 && Math.max(W,H)<w)return ;
		var r=w/Math.min(W,H);
		o.width=Math.ceil(r*W);
		o.height=Math.ceil(r*H);
	}
	img.src=o.src;
}
function LE(o){
	o.style.display="none";
}

//最佳适应父窗口
function resize1(o,w,h,f){
  if(!o.parentNode)return ;
	var img=new Image();
	img.onerror=function(){return false;}
	img.onload=function(){
		if(this.readyState!='complete')return;
		var W=img.width,H=img.height;
    w=w||o.parentNode.offsetWidth;
    h=h||o.parentNode.offsetHeight;
		var p=Math.min(w/W,h/H);
		o.width=p*W;o.height=p*H;
    if(f){
      if(o.width<w){
        o.hspace=(w-o.width)/2;
      }
      if(o.height<h){
        o.vspace=(h-o.height)/2;
      }
    }
	}
	img.src=o.src;
}
//给定长度，按照ｘ边的放缩比例放缩ｙ边．
function resizebyw(o,w){
	if(!w)return;
	var img=new Image();
	img.onerror=function(){return false;}
	img.onload=function(){
		var W=img.width,H=img.height;
    var h=(w*H)/W;
    o.width=w;o.height=h;
	}
	img.src=o.src;
}
//给定高度度，按照ｙ边的放缩比例放缩ｗ边．
function resizebyh(o,h){
	if(!h)return;
	var img=new Image();
	img.onerror=function(){return false;}
	img.onload=function(){
		var W=img.width,H=img.height;
    var w=(h*W)/H;
    o.width=w;o.height=h;
	}
	img.src=o.src;
}
function resizebyp(o,p,f){
  if(o.width==0)return ;
	if(!p)return;
	var img=new Image();
	img.onerror=function(){return false;}
	img.onload=function(){
		var W=img.width,H=img.height;
    var w =p.offsetWidth,h=p.offsetHeight;
    var r=f==1?Math.min(w/W,h/H):Math.max(w/W,h/H);
    o.width=W*r;o.height=H*r;
    if(f==1){
      if(o.width<w)o.hspace=(w-o.width)/2;
      if(o.height<h)o.vspace=(h-o.height)/2;
    }else{
      if(o.width>w)p.scrollLeft = (o.width-w)/2
      if(o.height>h)p.scrollTop = (o.height-h)/2
    }
	}
	img.src=o.src;
}