// JavaScript Document


//*******		image functions		********//


	function DetermineBestImgDimensions(objImg, iCustomWidth, iCustomHeight, iMaxWidth, iMaxHeight)
	// gets an image object, custom and max Width & Height,
	// and determines the best dimensions for the image.
	// it returns them in the form of an array - [iImgWidth,iImgHeight].
	{
		// first, find the natural height and width of the img.
		//alert(objImg.src);
		var iImgWidth = objImg.width;
		var iImgHeight = objImg.height;
		if (iCustomWidth>0 && iCustomHeight>0) //if custom width and height are specified, use them.
		{
			iImgWidth = iCustomWidth;
			iImgHeight = iCustomHeight;
		}
		else		// if not, find 	if one or both sizes exceed the max values, and constrain them.								
		{
			var iWidthRatio = iMaxWidth/iImgWidth;
			var iHeightRatio = iMaxHeight/iImgHeight;
			if (iWidthRatio < 1 || iHeightRatio < 1)        
			{
				var iImageRatio = Math.min(iWidthRatio,iHeightRatio);		//the smaller ratio sets the final image dimensions.
				iImgWidth = iImgWidth * iImageRatio;
				iImgHeight = iImgHeight * iImageRatio;
			}
		}
		return([iImgWidth,iImgHeight]);
	}

	function DetermineBestImgDimensions(iCustomWidth, iCustomHeight, iMaxWidth, iMaxHeight)
	// gets an image object, custom and max Width & Height,
	// and determines the best dimensions for the image.
	// it returns them in the form of an array - [iImgWidth,iImgHeight].
	{
		var iImgWidth = iCustomWidth;
		var iImgHeight = iCustomHeight;	
		// find if one or both sizes exceed the max values, and constrain them.			
		var iWidthRatio = iMaxWidth/iImgWidth;
		var iHeightRatio = iMaxHeight/iImgHeight;
		if (iWidthRatio < 1 || iHeightRatio < 1)        
		{
			var iImageRatio = Math.min(iWidthRatio,iHeightRatio);		//the smaller ratio sets the final image dimensions.
			iImgWidth = iImgWidth * iImageRatio;
			iImgHeight = iImgHeight * iImageRatio;
		}
		return([iImgWidth,iImgHeight]);
	}	
//*************************************************************//

	function ResizeImg(objImg, iCustomWidth, iCustomHeight, iMaxWidth, iMaxHeight)
	// gets an image object, custom and max Width & Height,
	// and resizes the image according to them.
	{
		var arrImgDimensions = DetermineBestImgDimensions(objImg, iCustomWidth, iCustomHeight, iMaxWidth, iMaxHeight);
		var iDeterminedWidth = arrImgDimensions[0];
		var iDeterminedHeight = arrImgDimensions[1];
		objImg.width = iDeterminedWidth;
		objImg.height = iDeterminedHeight;		
		objImg.style.visibility = "visible";
	}

	function ResizeAllImgs()
	{
		var objImg;
		for (var i=0; i<document.images.length; i++)
		{
			objImg = document.images[i];
			ResizeImg(objImg, 0, 0, 100, 100);
		}
	}
