// JavaScript Document


var resize = function(img, maxh, maxw) {
  var ratio = maxh/maxw;
  if (img.height/img.width > ratio){
     // height is the problem
    if (img.height > maxh){
      img.width = maxw;
	  img.height = Math.round(img.height*(maxw/img.width));
    }
  } else {
    // width is the problem
    if (img.width > maxw){
	  img.height = maxh;
      img.width = Math.round(img.width*(maxh/img.height));
    }
  } 
};