function resizeImage(id, max) {
	var pic = document.getElementById(id);
	if(pic.width > max)
	{
		ratio = pic.width / pic.height;
		if(ratio < 1)
		{
			pic.height = max;
			pic.width = pic.height * ratio;
		}
		else
		{
			pic.width = max;
			pic.height = pic.width / ratio;
		}
	}
}

function resizeLargeImages()
{
	var post_images = document.getElementsByClassName('post_image');
	var max = 800;
	for(var i = 0; i < post_images.length; i++)
	{
		var pic = post_images[i];

		if(pic.className != "post_image noresize")
		{
			if(pic.width > max)
			{
				ratio = pic.width / pic.height;
				if(ratio < 1)
				{
					pic.height = max;
					pic.width = pic.height * ratio;
				}
				else
				{
					pic.width = max;
					pic.height = pic.width / ratio;
				}
				
				var wrapper = new Element('div', { 'style': 'width: ' + pic.width + 'px; padding: 3px; background-color: #FFFFAA; border: 1px solid #999999;' });
				pic.wrap(wrapper);
				var dummy = new Element('div').update("<div style='font-weight: bold; padding: 3px;'>This image has been resized. <a href='" + pic.src + "' target='blank' style=''>Click here to view the full size version</a></div>"); 
				Element.insert(wrapper, {top: dummy});  
 			}
		}
	}
}