//顯示成最大寬為maxWidth，最大高為maxHeight的圖
function ImageResize( image , maxWidth , maxHeight )
{
	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; 
			}
		}
	}
}
