
/* const */
var ExpTotalSteps = 10;
var ExpTimeInterval = 25;
/* global var */
var ExpandingFromId = "";
var ExpandingToId = "";
var ExpRect = new Rect(0, 0, 0, 0);
var ExpTimeOut = 0;
var ExpStep = 0;

function GrowPicture(fromId, toId, fullwidth, fullheight)
{
	if (ExpTimeOut != 0)
	{
		clearTimeout(ExpTimeOut);
	}
	if (ExpandingFromId != "" && ExpandingFromId != fromId)
	{
		RestoreThumb();
	}
	if (ExpandingFromId != fromId)
	{
		var img = document.getElementById(toId);
		img.style.display = 'block';
		ExpandingFromId = fromId;
		ExpandingToId = toId;
		ExpStep = 1;
		ExpRect.width = fullwidth;
		ExpRect.height = fullheight;
		ExpRect.top = img.offsetTop;
		ExpRect.left = img.offsetLeft;
	}
	else if (ExpStep < 1)
	{
		ExpStep = 1;
	}
	GrowTimer();
}

function GrowTimer()
{
	ExpTimeOut = 0;
	GrowByOne();
	if (ExpStep < ExpTotalSteps)
	{
		ExpStep++;
		ExpTimeOut = setTimeout("GrowTimer()", ExpTimeInterval);
	}
}
function GrowByOne()
{
	var theWindow = GetRect();
	var thumb = document.getElementById(ExpandingFromId);
	var finalRect = new Rect();
	if (ExpRect.top + thumb.height > theWindow.top + theWindow.height)
	{
		finalRect.top = theWindow.top + theWindow.height - ExpRect.height;
	}
	else
	{
		finalRect.top = ExpRect.top + thumb.height - ExpRect.height;
	}
	if (finalRect.top < theWindow.top)
	{
		finalRect.top = theWindow.top;
	}
	if (ExpRect.left + thumb.width > theWindow.left + theWindow.width)
	{
		finalRect.left = theWindow.left + theWindow.width - ExpRect.width;
	}
	else
	{
		finalRect.left = ExpRect.left + thumb.width - ExpRect.width;
	}
	if (finalRect.left < theWindow.left)
	{
		finalRect.left = theWindow.left;
	}
	var img = document.getElementById(ExpandingToId);
	img.style.top = finalRect.top + ((ExpRect.top - finalRect.top) * (ExpTotalSteps - ExpStep) / ExpTotalSteps) + 'px';
	img.style.left = finalRect.left + ((ExpRect.left - finalRect.left) * (ExpTotalSteps - ExpStep) / ExpTotalSteps) + 'px';
	img.width = thumb.width + ((ExpRect.width - thumb.width) * ExpStep / ExpTotalSteps);
	img.height = thumb.height + ((ExpRect.height - thumb.height) * ExpStep / ExpTotalSteps);
}
function ShrinkPic()
{
	if (ExpTimeOut != 0)
	{
		clearTimeout(ExpTimeOut);
	}
	if (ExpStep > 0)
	{
		ShrinkByOne();
	}
	return false;
}
function ShrinkByOne()
{
	ExpTimeOut = 0;
	GrowByOne();
	if (ExpStep > 0)
	{
		ExpStep--;
		ExpTimeOut = setTimeout("ShrinkByOne()", ExpTimeInterval);
	}
	else
	{
		RestoreThumb();
	}
}
function RestoreThumb()
{
	var img = document.getElementById(ExpandingToId);
	img.style.top = '';
	img.style.left = '';
	img.style.display = 'none';
	ExpandingFromId = "";
	ExpandingToId = "";
}
function Rect(vnLeft, vnTop, vnWidth, vnHeight)
{
	this.left = vnLeft;
	this.top = vnTop;
	this.width = vnWidth;
	this.height = vnHeight;
}
function GetRect()
{
	if (document.all && typeof document.body.scrollTop != "undefined")
	{
		var ieBox = document.compatMode != "CSS1Compat";
		var cont = ieBox ? document.body : document.documentElement;
		var x = new Rect(cont.scrollLeft, cont.scrollTop, cont.clientWidth, cont.clientHeight);
		return x;
	}
	else
	{
		var x = new Rect(window.pageXOffset, window.pageYOffset, window.innerWidth, window.innerHeight);
		return x;
	}
}
