// JavaScript Document

var photo = null;

function displayPhoto(path, desc)
{
	photo = document.getElementById("photo");
	var divParent = document.getElementById("pic_frame");	
	
	if (photo)
	{
		// destroy the photo first
		divParent.removeChild(photo);
	}
	
	photo = new Image();
	photo.name  = "photo";
	photo.id = "photo";
	photo.onload = resize;
	
	divParent.appendChild(photo);
	
	photo.src = path;
	
	var divDesc = document.getElementById("pic_desc");	
	divDesc.innerHTML = "<center>" + desc + "</center>";	
}

function resize()
{
	var elem = document.getElementById("photo");
	
	if (elem == undefined || elem == null)
		return false;
	
	var	max = 400;

	if (elem.width > elem.height)
	{
		var diff = elem.width - 400;
		
		if (diff > 0 && elem.height > 400)
		{
			// Calculate reduction ratio
			var ratio = Math.floor(diff * 100 / elem.width);
			elem.height = elem.height - Math.floor(ratio * elem.height / 100);
		}
		
		elem.width = max;
  	} 
	else
	{
		var diff = elem.height - 400;
		
		if (diff > 0 && elem.width > 400)
		{
			// Calculate reduction ratio
			var ratio = Math.floor(diff * 100 / elem.height);
			elem.width = elem.width - Math.floor(ratio * elem.width / 100);
		}
		
		elem.height = max;
  	}
	
	elem.style.position = "absolute";
	elem.style.left = ((400 - elem.width) / 2) + "px";
	elem.style.top = ((400 - elem.height) / 2) + "px";
}