var PopUpWindow = null;
var ZoomImage = null;

function PopUpW( w )
{
	var r = 10;		// This was fine tuned with Win XP, chrome theme, may vary on others
	if( w + r > window.screen.width )  w = window.screen.width  - r;
	return w;
}
function PopUpH( h )
{
	var t = 68;		// This was fine tuned with Win XP, chrome theme, may vary on others
	if( h + t > window.screen.height ) h = window.screen.height - t;
	return h;
}

function PopUp( src, w, h, sName )
{
	if( PopUpWindow ) PopUpWindow.close();
	PopUpWindow = window.open( src, sName || "PopUp", "width="+PopUpW(w)+",height="+PopUpH(h)+",scrollbars=1,resizable=1" );
}

function Zoom( src, w, h )
{
	if( src.match( /\.(jpe?g|gif)$/i ) )
	{
		if( !w && !h )	// Automatically obtain image's dimensions
		{
			ZoomImage = new Image();
			ZoomImage.src = src;
			ppWait4ZoomImage( src );
			return false;
		}
	}
	else
		src = "/PopUps/Zoom/?pg=" + src;
	var margin = 5;
	w += margin + margin;
	h += margin + 40 + margin;
	if( PopUpWindow ) PopUpWindow.close();
	PopUpWindow = window.open( src, "PopUp", "width="+PopUpW(w)+",height="+PopUpH(h)+",scrollbars=0,resizable=0" );
	if( src.match( /\.(jpe?g|gif)$/i ) )
		WrapZoomImage( PopUpWindow.document, src );
	return false;
}

function ppWait4ZoomImage( src )
{
	if( ZoomImage.width != 0 && ZoomImage.height != 0 )
		Zoom( src, ZoomImage.width + 20, ZoomImage.height + 0 );
	else
		setTimeout( "ppWait4ZoomImage('" + src + "')", 20 );
}

function WrapZoomImage( doc, src )
{
	doc.close();
	doc.open();
	doc.writeln( '<html><head><title>Zoom Image</title></head><body bgcolor="#000000"><table width="100%" height="100%"><tr><th><img src="../Copy%20of%20home_files/%27%20+%20src%20+%20%27"></th></tr></table></body></html>\n' );
	doc.close();
}

