//顯示成最大寬為maxWidth，最大高為maxHeight的圖
function ImageResize( image , maxWidth , maxHeight )
{
	/*
	var img=new Image(); 
    img.src=image.src;
    
    if(img.width>0 && img.height>0){ 
        var rate = (maxWidth/img.width < maxHeight/img.height)?maxWidth/img.width:maxHeight/img.height;
        
        if(rate <= 1){            
            image.style.width = img.width*rate;
            image.style.height =img.height*rate;
        }
        else {
            image.style.width = img.width;
            image.style.height =img.height;
        }
    } 
	*/
	
	
	/*
	var appname = navigator.appName.toLowerCase(); 

	var img = image; //獲取圖片  

	img.alpha = 1;

    var MaxWidth = maxWidth; //設置圖片寬度界限  

	var MaxHeight = maxHeight; //設置圖片高度界限  

	var HeightWidth = img.offsetHeight / img.offsetWidth; //設置高寬比  

	var WidthHeight = img.offsetWidth / img.offsetHeight; //設置寬高比  

	if (appname.indexOf("netscape") == -1) 
	{  
		if (img.readyState != "complete")  
		{
			return false;  
		}
	} 
	else 
	{  
		if (img.complete != true)  
		{
			return false;  
		}
	}
       	
	if (img.offsetWidth > MaxWidth)
	{  
		img.width = MaxWidth;  
		img.height = MaxWidth * HeightWidth;  
	}  
   
	if (img.offsetHeight > MaxHeight) 
	{  
		img.height = MaxHeight;  
		img.width = MaxHeight * WidthHeight;  
	}  
	*/
	
	
	var img = new Image();

	img.src = image.src;
	
	//判斷圖的寬高是否均大於0
	if( ( img.width > 0 ) && ( img.height > 0 ) )
	{
		if( maxWidth != null && maxHeight != null )
		{
			if( img.width / img.height >= maxWidth / maxHeight )
			{
				if( img.width > maxWidth )
				{ 
					image.width = maxWidth;
					image.height = ( img.height * maxWidth ) / img.width;
				}
				else
				{
					image.width = img.width; 
					image.height = img.height;
				}
			}
			else
			{
				if( img.height > maxHeight )
				{ 
					image.height = maxHeight;
					image.width = ( img.width * maxHeight ) / img.height; 
				}
				else
				{
					image.width = img.width; 
					image.height = img.height;
				}
			}
		}
		else if( maxWidth != null && maxHeight == null )
		{
			if( img.width > maxWidth )
			{ 
				image.width = maxWidth;
				image.height = ( img.height * maxWidth ) / img.width;
			}
		}
		else if( maxWidth == null && maxHeight != null )
		{
			if( img.height > maxHeight )
			{ 
				image.height = maxHeight;
				image.width = ( img.width * maxHeight ) / img.height; 
			}
		}
	}
}
