function autofit(fit_size,image_id){
	var img = document.getElementById(image_id);
	//var t = document.getElementById("good");
	
	// Grab the image's dimensions
	var imgH = img.clientHeight;
	var imgW = img.clientWidth;
	
	// Default = 0 = No need to do resize process
	var resize_is_needed = 0;
	
	// Check whether one of the larger length of the image dimension is greater than 'fit_size'
	// If this is the case, we are going to resize the source image size.
	if (imgH > fit_size || imgW > fit_size) {
		resize_is_needed = 1;		
	}

	// Resize module
	if (resize_is_needed == 1){	
		// Find which dimension is scaled the most
		var scaleH =  fit_size / img.clientHeight;
		var scaleW = fit_size / img.clientWidth;
	
		// Scale the image
		if (scaleH < scaleW) {
			img.style.height = fit_size;
			img.style.width = Math.round(imgW * scaleH) + "px";
		} else {
			img.style.width = fit_size;
			img.style.height = Math.round(imgH * scaleW) + "px";
		}

	} else {
		// No need to resize, set as original dimensions
		img.style.height = imgH; 
		img.style.width = imgW;
	}
}
