//
//	Revision History:
//	2007-09-04	ML	New file.
//
var WindowObjectReference = null;
var prevWidth = 0;
var prevHeight = 0;
var previousImage;
var doc;

function displayInNewWindow( image, width, height, name, date, media, comments, price, available, size )
	{
	fns = "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,location=no,width=";
	num_width = Number( width ) + 200;		// add arbitrary room for picture details.
	fns += num_width;
	fns += ",height=";
	num_height = Number( height ) + (.05 * Number( height ));	// Assume code below uses 5% cellpadding.
	fns += num_height;
	if ( WindowObjectReference == null )
		{
		WindowObjectReference = window.open("", "SingleSecondaryWindowName", fns );
		}
	else if ( WindowObjectReference.closed )
		{
		WindowObjectReference = window.open("", "SingleSecondaryWindowName", fns );
		}
	else if ( previousImage != image )
		{
		// If the resource to load is different, then we load it in the already opened secondary window and then
		// we bring such window back on top/in front of its parent window.
		if ( (height != prevHeight) || (width != prevWidth) )
			{
			// If height or width of new image is different, we have to close the old window. MSIE 7 doesn't seem
			// to let you change the height or width of an existing window.
			WindowObjectReference.close( );
			WindowObjectReference = window.open("", "SingleSecondaryWindowName", fns );
			}
		else
			WindowObjectReference = window.open("", "SingleSecondaryWindowName", fns );
		WindowObjectReference.focus();
		}
	else
		{
		WindowObjectReference.focus();
		}
  	// We store the current url, height, & width in order to compare url in the event of another call of this function.
	previousImage = image;
	prevWidth = width;
	prevHeight = height;

	doc = WindowObjectReference.document; 
	doc.open();
	doc.write( displayBigPicture( image, width, name, date, media, comments, price, available, size ) );
	doc.close();
	}
	
// ML: Should change to use keywords & variable arg list.
function displayBigPicture( image, width, name, date, media, comments, price, available, size )
	{
	toolTip = "<head><title>";
	toolTip += name;
	toolTip += "</title>";
	toolTip += "<style type='text/css' media='screen'>";
	toolTip += "@import '../SSScripts/css_convert.php?c=emx_nav_left_php.css';</style></head>";
	toolTip += "<body><div class='itemInfo'><table width='auto' cellpadding='5%'><tbody><tr><td>";
	toolTip += "<img src='";
	toolTip += image;
//	toolTip += "' width='";
//	toolTip += width;		// If we don't specify the width, comes out wrong on the first click. ML: Suspect a bug in
							// how wz_tooltip: tt_FormatTip calculates the width, need to fix this later.
	toolTip += "' />";
	toolTip += "</td><td><div id='itemInfo'><table width='100%' border='0' cellpadding='0' cellspacing='5%'>";
	toolTip += "<tr><td align='left'><b>";
	toolTip += name;
	toolTip += "</b></td></tr>";
	toolTip += "<tr><td align='left'>";
	toolTip += date;
	toolTip += "</td></tr>";
	toolTip += "<tr><td align='left'>";
	toolTip += media;
	toolTip += "</td></tr>";
	toolTip += "<tr><td align='left'><i>";
	toolTip += comments;
	toolTip += "</i></td></tr>";
	toolTip += "<tr><td align='left'>";
	toolTip += size;
	toolTip += "</td></tr>";
	toolTip += "<tr><td align='left'>";
	toolTip += price;
	toolTip += "</td></tr>";
	toolTip += "<tr><td align='left'>";
	toolTip += available;
	toolTip += "</td></tr>";
	toolTip += "</table></div></td></tr></tbody></table></div></body>";
	
	return( toolTip );
	}
	
function displayDetails( name, date, media, comments, price, available, size )
	{
	toolTip = "<div id='itemInfo'><table width='100%' border='0' cellpadding='0' cellspacing='5%'><tbody>";
	toolTip += "<tr><td align='left'><b>";
	toolTip += name;
	toolTip += "</b></td></tr>";
	toolTip += "<tr><td align='left'>";
	toolTip += date;
	toolTip += "</td></tr>";
	toolTip += "<tr><td align='left'>";
	toolTip += media;
	toolTip += "</td></tr>";
	toolTip += "<tr><td align='left'><i>";
	toolTip += comments;
	toolTip += "</i></td></tr>";
	toolTip += "<tr><td align='left'>";
	toolTip += size;
	toolTip += "</td></tr>";
	toolTip += "<tr><td align='left'>";
	toolTip += price;
	toolTip += "</td></tr>";
	toolTip += "<tr><td align='left'>";
	toolTip += available;
	toolTip += "</td></tr>";	
	toolTip += "</table></div></td></tr></tbody></table></div>";
	return( toolTip );
	}

function CalcFixXY( width, height )
	{
	var xy = new Array(2);
	var xOff = 0;
	var yOff = 0;
	
	xy[0] = 0;
	xy[1] = 0;

	if( typeof( window.innerWidth ) == 'number' )
		{	//Non-IE
		if ((xy[0] = window.innerWidth) < width)
			window.innerWidth = width;
		if ((xy[1] = window.innerHeight) < height)
			window.innerHeight = height;
		}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{	//IE 6+ in 'standards compliant mode'
		if ((xy[0] = document.documentElement.clientWidth) < width)
			document.documentElement.clientWidth = width;
		if ((xy[1] = document.documentElement.clientHeight) < height)
			document.documentElement.clientHeight = height;
		}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{	//IE 4 compatible
		xy[0] = document.body.clientWidth;
		xy[1] = document.body.clientHeight;
		}
	if( typeof( window.pageYOffset ) == 'number' )
		{	//Netscape compliant
		yOff = window.pageYOffset;
		xOff = window.pageXOffset;
		}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{	//DOM compliant
		yOff = document.body.scrollTop;
		xOff = document.body.scrollLeft;
		}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
		{	//IE6 standards compliant mode (but above if is not true for IE7)
		yOff = document.documentElement.scrollTop;
		xOff = document.documentElement.scrollLeft;
		}
	if (xOff != 0)
		xy[0] = xOff;
	if (yOff != 0)
		xy[1] = yOff;
	return( xy );
	}

function CalcOffX( width )
	{
	var xOff = 0;
	
	if( typeof( window.pageYOffset ) == 'number' )
		{	//Netscape compliant
		xOff = window.pageXOffset;
		}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{	//DOM compliant
		xOff = document.body.scrollLeft;
		}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
		{	//IE6 standards compliant mode (but above if is not true for IE7)
		xOff = document.documentElement.scrollLeft;
		}
	else if( document.documentElement && document.documentElement.offsetLeft )
		{	// IE7
		xOff = document.documentElement.offsetLeft;
		}
	return( xOff );
	}
function CalcOffY(  height )
	{
	var yOff = 0;

	if( typeof( window.pageYOffset ) == 'number' )
		{	//Netscape compliant
		yOff = window.pageYOffset;
		}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{	//DOM compliant
		yOff = document.body.scrollTop;
		}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
		{	//IE6 standards compliant mode (but above if is not true for IE7)
		yOff = document.documentElement.scrollTop;
		}
	else if( document.documentElement && document.documentElement.offsetTop )
		{	// IE7
		yOff = document.documentElement.offsetTop;
		}
	return( yOff );
	}
