//---------------------------------------------------------------
//	Get/set an image URL based on an HTML element ID.
//---------------------------------------------------------------

function set_image(id, image_url) 
{
	document.getElementById(id).src = image_url;

	return(true);
}


function get_image(id) 
{
	var image_url = document.getElementById(id).src;

	return(image_url);
}


function set_image_and_size(
	image_id, 		//	DOM id
	image_url, 		//	http://whatever
	max_dimension	//	400px, etc
){
	var elem, image, height, width, scale;

	//	Create a temporary image so we can get image dimensions

	image		= new Image();
	image.src 	= image_url;
	height 		= image.height;
	width 		= image.width;

	elem 		= document.getElementById(image_id);
	elem.src 	= image_url;

	//	Scale the new image 

	if (max_dimension)
	{
		//	Strip "px"

		max_dimension = max_dimension.replace(/px/gi, "");	

		if (width > height)
			scale = max_dimension / width;
		else
			scale = max_dimension / height;

		width  = Math.round(width  * scale);
		height = Math.round(height * scale);

		elem.style.width 	= width  + "px";
		elem.style.height 	= height + "px";
	}

	return(true);
}



