// JavaScript Document
/**
Usage:
<img src="flash_old.jpg" onload="resize(this,'500','200')" />
**/
function resize(elem, maxw, maxh) 
{  
    if (elem == undefined || elem == null) return false;
    var w = elem.width;
	var h = elem.height;
    var nh;
    var nw;
	var ratio;
  	
	if (w > maxw || h > maxh) {
	    if( w > h ) {
			ratio = w / h;
			nw = maxw;
			nh = nw / ratio;
			if (nh > maxh) {
				nh = maxh;
				nw = nh * ratio;
			}
		} else {
			ratio = h / w;
			nh = maxh;
			nw = nh / ratio;
			if (nw > maxw) {
				nw = maxw;
				nh = nw * ratio;
			}
		}
	} else {
		nw = w;
		nh = h;
	}
	
	elem.width = nw;
	elem.height = nh;
}
