var reset, distance;

function windowOpen(imageLocation, imageWidth, imageHeight)
{

	displayWindow=window.open("","dynamicWindow","toolbar=no,location=0,width=10,height=10,directories=no,status=no,scrollbars=no,resizable=no,menubar=no");
	displayWindow.document.write('<div style="position:absolute; top:0px; left:0px; z-index:3;">');
    	displayWindow.document.write('<img src="'+imageLocation+'" width="'+imageWidth+'" height="'+imageHeight+'" border="0"');
	//original of the code above --> displayWindow.document.write('<a href="javascript:window.close();"><img src="'+imageLocation+'" width="'+imageWidth+'" height="'+imageHeight+'" border="0" alt="Click to close window"></a>');
	displayWindow.document.write('</div>');
	displayWindow.document.bgColor = '#000000';
	displayWindow.document.close();
	displayWindow.window.focus();
	resizeStart(imageWidth+12,imageHeight+35);
}

function resizeStart(targetWidth,targetHeight)
{ 
	if (reset) { clearTimeout(reset); }
	var currentWidth = (window.innerWidth) ? displayWindow.window.innerWidth : parseInt(displayWindow.document.body.clientWidth);
	var currentHeight = (window.innerHeight) ? displayWindow.window.innerHeight : parseInt(displayWindow.document.body.clientHeight);
	resizeCycle(targetWidth,targetHeight,currentWidth,currentHeight);
}

function resizeCycle(targetWidth,targetHeight,currentWidth,currentHeight)
{ 
	if ((currentWidth != targetWidth) && (currentHeight != targetHeight))
	{ 
		if (currentWidth < targetWidth)
		{ distance = targetWidth - currentWidth;
			distance = (distance/10);
			distance = Math.round(distance);
			distance = (distance<1)?1:distance;
			currentWidth += distance;
		} 
		else
		{ distance = currentWidth - targetWidth;
			distance = (distance/10);
			distance = Math.round(distance);
			distance = (distance<1)?1:distance;
			currentWidth -= distance;
		}
		if (currentHeight < targetHeight)
		{ distance = targetHeight - currentHeight;
			distance = (distance/10);
			distance = Math.round(distance);
			distance = (distance<1)?1:distance;
			currentHeight += distance;
		} 
		else
		{ distance = currentHeight - targetHeight;
			distance = (distance/10);
			distance = Math.round(distance);
			distance = (distance<1)?1:distance;
			currentHeight -= distance;
		}
		displayWindow.window.resizeTo(currentWidth,currentHeight);
		reset = setTimeout('resizeCycle('+targetWidth+','+targetHeight+','+currentWidth+','+currentHeight+')','10');
	}
	return;
}