var i = 1;         //incrementer for extra windows
var numOfWins = 5; //max number of windows

//detect browser type
var isIE = (navigator.appName == "Microsoft Internet Explorer"
	&& parseInt(navigator.appVersion) >= 4) ? true : false;
var isNS = (navigator.appName == "Netscape" && 
	parseInt(navigator.appVersion) >= 4) ? true : false;

function picWin(url, alt)
{
	//set parameters for the image's window and open the window
	var winParms = 'copyhistory=no,directories=no,location=no,' +
		'menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no';
	var pop = window.open('', 'pop' + i, winParms);

	//increment i if i is not equal to the max number of windows
	i == numOfWins ? i = 1 : i++;
	
	//create html to write to the new window
	var popString = '';

	if (isNS && parseInt(navigator.appVersion) >= 5)
	{
		popString += '<head>\r';
		popString += '<script language="Javascript">\r';
		popString += 'function winResize() {\r';
		popString += '\twindow.innerHeight = document.images[0].height;\r';
		popString += '\twindow.innerWidth = document.images[0].width;\r';
		popString += '\twindow.moveTo((screen.width - window.innerWidth) / 2, ';
		popString += '(screen.height - window.innerHeight) / 2);\r';
		popString += '}\r';
		popString += '</script>\r';
		popString += '</head>\r';
		popString += '\r';
	}

	popString += '<body onload="winResize()" leftmargin="0" topmargin="0" ' +
		'marginheight="0" marginwidth="0" margin="0">\r';
	popString += '<img alt="' + alt + '" src="' + url + '">\r';
	popString += '</body>';

	//open the document in the window and write the image to it
	pop.document.open();
	pop.document.write(popString);
	pop.document.close();
	pop.document.title = alt;
	
	if (isIE)
	{
		//get the height and width of the image
		imgHeight = pop.document.images[0].offsetHeight;
		imgWidth = pop.document.images[0].offsetWidth;

		//resize document body to dimensions of the image
		pop.document.body.height = Math.ceil(imgHeight);
		pop.document.body.width  = Math.ceil(imgWidth);

		//resize window to dimensions of the image
		pop.resizeTo(0, 0);
		pop.resizeBy(Math.ceil(imgWidth)-91, Math.ceil(imgHeight)-71);
	}
	else if (isNS)
	{
		//get the height and width of the image
		imgHeight = pop.document.images[0].height;
		imgWidth = pop.document.images[0].width;
		
		//resize window to dimensions of the image
		pop.innerHeight = imgHeight;
		pop.innerWidth = imgWidth;
	}
	else
		alert("Please use a browser that is compatible with this script.");

	//center the image window on the screen and give it focus
	var globalLeft = (screen.width - imgWidth) / 2;
	var globalTop  = (screen.height - imgHeight) / 2;
	pop.moveTo(globalLeft, globalTop);
	pop.focus();
}
