var savedElementWidths = new Object();
var timers = new Object();

function resize(element, maxWidth, growFactor, grow)
{

	var currentWidth = document.images[element.uniqueID].width;
	if(savedElementWidths[element.uniqueID] == null) 
	{
		savedElementWidths[element.uniqueID] = currentWidth;
	}
	if(currentWidth <= maxWidth && grow == true)
	{
		if(element.style.position != "absolute")
		{
			element.style.left = element.offsetLeft;
			element.style.top = element.offsetTop - 14;
			element.style.position = "absolute";
			element.style.zIndex = 101;
		}
		if(timers[element.uniqueID] != null)
		{
			window.clearTimeout(timers[element.uniqueID]);
		}
		element.style.width = currentWidth + growFactor;
		timers[element.uniqueID] = window.setTimeout(function() { resize(element, maxWidth, growFactor, grow); }, 25);
	}
	else if(element.width > savedElementWidths[element.uniqueID] && savedElementWidths[element.uniqueID] != null && grow == false)
	{
		if(timers[element.uniqueID] != null)
		{
			window.clearTimeout(timers[element.uniqueID]);
		}
		element.style.width = currentWidth - growFactor;
		timers[element.uniqueID] = window.setTimeout(function() { resize(element, maxWidth, growFactor, grow); }, 10);
		if((currentWidth - growFactor)<= savedElementWidths[element.uniqueID])
		{
			element.style.position = "relative";
			element.style.top = "";
			element.style.left = "";
			element.style.zIndex = 100;
		}
	}
}