/*  Design Haus UK Ltd
 *  selfPopup() : an image gallery script - opens an image in a new window
 *  Usage: add  onclick="return selfpopup(this)" to the anchor that links to an image
 *  <a href="images/large.jpg" onclick="return selfpopup(this)"><img src="images/thumbnail.jpg"/></a>
*/

var selfpopup_img;
function selfpopup( ref )
{	
	// create and load the image
	selfpopup_img = new Image();
	selfpopup_img.onload = selfpopup_openwindow;
	selfpopup_img.src = ref.href; 
	return false;
}

function selfpopup_openwindow()
{
	var imgWidth;
	var imgHeight;
	var imgSrc;
	var divHeight;
	var LeftPosition;
	var TopPosition;

	// read the image properties
	divHeight = 30;
	imgWidth  = selfpopup_img.width;
	imgHeight = selfpopup_img.height;
	imgSrc    = selfpopup_img.src;

	// work out center point
	LeftPosition = (screen.width)  ? (screen.width-imgWidth)/2   : 0;
	TopPosition  = (screen.height) ? (screen.height-imgHeight)/2 : 0;

	// Open a new window with the exact dimensions of the image, centred on screen
	mywindow = window.open("","","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width="+imgWidth+",height="+(selfpopup_img.height+divHeight)+',left='  +LeftPosition +  ',top='  +TopPosition +"");
	mywindow.document.write('<html><head><title>Gallery</title><style>' +
		' body{ margin:0; font:68.9%/1em sans-serif; text-align:center; }' +
		' a {color:black;}' +
		' div{ height: '+divHeight+'px; padding-top: 5px; }' +
		' </style></head><body><img/><div><a href="javascript:window.close();">Close window</a></div></body></html>');
	mywindow.document.images[0].src = selfpopup_img.src;
	return false;
}