
var newwindow;
var wheight = 0, wwidth = 0;


function popitup(url, title)
{
	var pwidth, pheight;
	iwidth=100;
	iheight=100;
	colour='black';
	default_title='The Default Title';
	
	// load a default title if one is not passed in
	title=title?title:default_title;

	if ( !newwindow || newwindow.closed )
	{
		pwidth=iwidth+0;
		pheight=iheight+0;
		newwindow=window.open('','imgpopup','width=' + pwidth +',height=' +pheight + ',resizable=1,top=50,left=10');
		wheight=iheight;
		wwidth=iwidth;
	}

	if (wheight!=iheight || wwidth!=iwidth )
	{
		pwidth=iwidth+0;
		pheight=iheight+0;
		newwindow.resizeTo(pwidth, pheight);
		wheight=iheight;
		wwidth=iwidth;
	}

	newwindow.document.clear();
	newwindow.focus();
	newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <script src=\"script/popups.js\"></script> <\/head> <body bgcolor=\"' + colour + '\" onLoad=\"fitpic()\" leftmargin=\"0\" topmargin=\"0\" marginheight=\"0\" marginwidth=\"0\"> <center> ');
	newwindow.document.writeln('<img src=' + url + '>');
	newwindow.document.writeln('<\/center> <\/body> <\/html>');
	newwindow.document.close();
	newwindow.focus();
}


// Routines to tidy up popup windows when page is left
// Call with an onUnload="tidypopups()" in body tag
function tidypopups()
{
	if (newwindow && !newwindow.closed)
	{
		newwindow.close();
	}
}


//once the popup opens, this routine will resize it to fit the image
function fitpic()
{
	var img_w = document.images[0].width;
	var img_h = document.images[0].height;

	window.resizeTo(img_w+10,img_h+33);
	self.focus();
}