var imageLoaderPath = baseURL + '/imageloader.php';

var windowMargin	= 40;
var imagePaddingX	= 64;
var imagePaddingY	= 96;

function showWindow(url, windowWidth, windowHeight)
{
	if (!window.open) return true;

	var windowTop, windowLeft, popupWin;

	//adjust width to fit available screen real-estate, and center the window
	if (screen.availWidth && screen.availHeight)
	{
		windowWidth		= Math.min(screen.availWidth - (windowMargin * 2), windowWidth);
		windowHeight	= Math.min(screen.availHeight - (windowMargin * 2), windowHeight);
		windowTop		= (screen.availHeight - windowHeight) / 2;
		windowLeft		= (screen.availWidth - windowWidth) / 2;
	}
	else windowTop = windowLeft = windowMargin;

	popupWin = window.open(url, "", "scrollbars=yes,resizable=yes,status=yes,top=" + windowTop +",left=" + windowLeft + ",width=" + windowWidth + ",height=" + windowHeight);
	if (!popupWin) return true;

	if (popupWin.focus) popupWin.focus();
	return false;
}

function showImage(linkEl, imageWidth, imageHeight, imageTitle)
{
	var url, images;
	var encode			= window.encodeURIComponent ? window.encodeURIComponent : window.escape;
	var imageURL		= linkEl.href;
	var windowWidth		= imageWidth + imagePaddingX;
	var windowHeight	= imageHeight + imagePaddingY;

	if (!imageTitle)
	{
		images = linkEl.getElementsByTagName('img');
		if (images[0] && images[0].alt) imageTitle = images[0].alt;
	}

	url = imageLoaderPath + "?image=" + encode(imageURL);
	if (imageTitle) url += "&title=" + encode(imageTitle);
	return showWindow(url, windowWidth, windowHeight);
}