function fitAllImages(imagesName, height, width) {
	var reducingHeight, reducingWidth;
	var images = document.getElementsByName(imagesName);
		
	for( i=0; i<images.length; i++ ) {
		fitImage(images[i], height, width);
	}
}
		
function fitOneImage(imageId, height, width) {
	var image = document.getElementById(imageId);
	fitImage(image, height, width);
}
			
function fitImage(image, height, width) {
	var imageHeight = image.height;
	var imageWidth = image.width;
	var reducingHeight = image.height - height;
	var reducingWidth = image.width - width;
	
	if( reducingWidth >= reducingHeight && reducingWidth > 0 ) {
		imageHeight = image.height - reductionCalculation( image.height, image.width, 0, reducingWidth );
		imageWidth = image.width - reducingWidth;
	} else if( reducingHeight >= reducingWidth && reducingHeight > 0 ) {
		imageWidth = image.width - reductionCalculation( image.height, image.width, reducingHeight, 0 );
		imageHeight = image.height - reducingHeight;
	}
	image.setAttribute('width',imageWidth);
	image.setAttribute('height',imageHeight);
}
			
function reductionCalculation( height, width, reducingHeight, reducingWidth ) {
	var res, reductionIndex;
	if( reducingWidth > 0 ) {
		reductionIndex = reducingWidth/width;
		res = height*reductionIndex;
	} else {
		reductionIndex = reducingHeight/height;
		res = width*reductionIndex;
	}
	return res;
}

