var oldPw = null;
var previousURL="";
var nextURL="";
var hereNow = 0;
var Harray = new Array();
var test = "";
var wasBackForw = 0;
var Hmax = 0;

function previous()
{
	if (previousURL != "")
	{
		top.textFrame.location=previousURL;
	}
}

function next()
{
	if (nextURL != "")
	{
		top.textFrame.location=nextURL;
	}
}

function Hback()
{
	if (hereNow < Harray.length - 1)
	{
		wasBackForw = 1;
		hereNow++;
		top.textFrame.location=Harray[hereNow];
	}
}

function Hforward()
{
	if (hereNow > 0)
	{
		hereNow--;
		top.textFrame.location=Harray[hereNow];
		wasBackForw = 1;
	}
}

function Hadd(strURL)
{
	if (wasBackForw == 0)
	{
		for (var i = 0; i < hereNow; i++)
		{
			array_shift();
		}
		array_unshift(strURL);
		hereNow = 0;
	}
	wasBackForw = 0;
}

//I hate IExplorer for this
function array_unshift(args)
{
	Harray.reverse();
	Harray[Harray.length] = args;
	Harray.reverse();
	return Harray.length
}

//and this.
function array_shift()
{
	var numeroUno = this[0];
	Harray.reverse();
	Harray.length = Math.max(Harray.length-1,0);
	Harray.reverse();
	return numeroUno;
}

function OWW(strImage)
{
	pWidth = 400;
	pHeight = 400;
	if ((oldPw != null) && (!oldPw.closed))
	{
		oldPw.close();
	}

	xPos = (screen.availWidth - pWidth) / 2;
	yPos = (screen.availHeight - pHeight) / 2;
	wAttr = "resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,height=" + pHeight + ",width=" + pWidth + ",left=" + xPos + ",top=" + yPos;
	pw = window.open("","PictureWindow", wAttr);
	writeDocument(strImage, pw);

	oldPw = pw;
}

function OPWR(strImage)
{
	pWidth = 600;
	pHeight = 600;
	if ((oldPw != null) && (!oldPw.closed))
	{
		oldPw.close();
	}
	for (i = 0; i < strImage.length; i++)
	{
		if (strImage.charAt(i) == "/")
		{
			var beginIndex = i + 1;
			break;
		}
	}
	if (beginIndex > strImage.length + 6)
	{
		pWidth = 600;
		pHeight = 600;
	}
	if (strImage.charAt(beginIndex) == 'P')
	{
		pWidth = 450;
		pHeight = 600;
	}
	else if (strImage.charAt(beginIndex) == 'S')
	{
		pWidth = 392;
		pHeight = 600;
	}
	else if (strImage.charAt(beginIndex) == 'A')
	{
		pWidth = 369;
		pHeight = 600;
	}
	else if (strImage.charAt(beginIndex) == 'R')
	{
		pWidth = 400;
		pHeight = 600;
	}
	else
	{
		pWidth = 600;
		pHeight = 600;
	}
	xPos = (screen.availWidth - pWidth) / 2;
	yPos = (screen.availHeight - pHeight) / 2;
	wAttr = "resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,height=" + pHeight + ",width=" + pWidth + ",left=" + xPos + ",top=" + yPos;
	pw = window.open("","PictureWindow", wAttr);
	writeDocument(strImage, pw);

	oldPw = pw;
}

function OPW(strImage) 
{
	pWidth = 200;
	pHeight = 400;
	if ((oldPw != null) && (!oldPw.closed))
	{
		oldPw.close();
	}
	for (i = 0; i < strImage.length; i++)
	{
		if (strImage.charAt(i) == "/")
		{
			var beginIndex = i + 1;
			break;
		}
	}
	if (beginIndex > strImage.length + 6)
	{
		pWidth = 200;
		pHeight = 400;
	}
	if (strImage.charAt(beginIndex) == 'P')
	{
		pWidth = 800;
		pHeight = 600;
	}
	else if (strImage.charAt(beginIndex) == 'S')
	{
		pWidth = 800;
		pHeight = 523;
	}
	else if (strImage.charAt(beginIndex) == 'A')
	{
		pWidth = 800;
		pHeight = 472;
	}
	else if (strImage.charAt(beginIndex) == 'R')
	{
		pWidth = 800;
		pHeight = 533;
	}
	else
	{
		pWidth = 300;
		pHeight = 500;
	}

	xPos = (screen.availWidth - pWidth) / 2;
	yPos = (screen.availHeight - pHeight) / 2;
	wAttr = "resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,height=" + pHeight + ",width=" + pWidth + ",left=" + xPos + ",top=" + yPos;
	pw = window.open("","PictureWindow", wAttr);

	writeDocument(strImage, pw);

	oldPw = pw;
}

function OPW2(strImage) 
{
	pWidth = 200;
	pHeight = 400;
	if ((oldPw != null) && (!oldPw.closed))
	{
		oldPw.close();
	}

	beginIndex = 0;

	if (beginIndex > strImage.length + 6)
	{
		pWidth = 200;
		pHeight = 400;
	}
	if (strImage.charAt(beginIndex) == 'P')
	{
		pWidth = 800;
		pHeight = 600;
	}
	else if ((strImage.charAt(beginIndex) == 'S') || (strImage.charAt(beginIndex + 2) == 'S'))
	{
		pWidth = 800;
		pHeight = 523;
	}
	else if (strImage.charAt(beginIndex) == 'A')
	{
		pWidth = 800;
		pHeight = 472;
	}
	else if (strImage.charAt(beginIndex) == 'R')
	{
		pWidth = 800;
		pHeight = 533;
	}
	else
	{
		pWidth = 300;
		pHeight = 500;
	}

	xPos = (screen.availWidth - pWidth) / 2;
	yPos = (screen.availHeight - pHeight) / 2;
	wAttr = "resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,height=" + pHeight + ",width=" + pWidth + ",left=" + xPos + ",top=" + yPos;
	pw = window.open("","PictureWindow", wAttr);
	writeDocument(strImage, pw);

	oldPw = pw;
}

function OPWR2(strImage)
{
	pWidth = 600;
	pHeight = 600;
	if ((oldPw != null) && (!oldPw.closed))
	{
		oldPw.close();
	}

	beginIndex = 0;

	if (beginIndex > strImage.length + 6)
	{
		pWidth = 600;
		pHeight = 600;
	}
	if (strImage.charAt(beginIndex) == 'P')
	{
		pWidth = 450;
		pHeight = 600;
	}
	else if ((strImage.charAt(beginIndex) == 'S') || (strImage.charAt(beginIndex + 2) == 'S'))
	{
		pWidth = 392;
		pHeight = 600;
	}
	else if (strImage.charAt(beginIndex) == 'A')
	{
		pWidth = 369;
		pHeight = 600;
	}
	else if (strImage.charAt(beginIndex) == 'R')
	{
		pWidth = 400;
		pHeight = 600;
	}
	else
	{
		pWidth = 600;
		pHeight = 600;
	}
	xPos = (screen.availWidth - pWidth) / 2;
	yPos = (screen.availHeight - pHeight) / 2;
	wAttr = "resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,height=" + pHeight + ",width=" + pWidth + ",left=" + xPos + ",top=" + yPos;
	pw = window.open("","PictureWindow", wAttr);
	writeDocument(strImage, pw);

	oldPw = pw;
}

function OCW(strFile, cWidth, cHeight, isScroll) 
{
	if ((oldPw != null) && (!oldPw.closed))
	{
		oldPw.close();
	}
	xPos = (screen.availWidth - cWidth) / 2;
	yPos = (screen.availHeight - cHeight) / 2;
	wAttr = "resizable=no,toolbar=no,menubar=no,location=no,scrollbars=" + isScroll + ",height=" + cHeight + ",width=" + cWidth + ",left=" + xPos + ",top=" + yPos;
	pw = window.open(strFile,'PictureWindow', wAttr);
	oldPw = pw;
}

function OGW(strImage, cWidth, cHeight, isScroll) 
{
	if ((oldPw != null) && (!oldPw.closed))
	{
		oldPw.close();
	}
	xPos = (screen.availWidth - cWidth) / 2;
	yPos = (screen.availHeight - cHeight) / 2;
	wAttr = "resizable=no,toolbar=no,menubar=no,location=no,scrollbars=" + isScroll + ",height=" + cHeight + ",width=" + cWidth + ",left=" + xPos + ",top=" + yPos;
	pw = window.open("","PictureWindow", wAttr);
	writeDocument(strImage, pw);

	oldPw = pw;
}

function writeDocument(strImage, pw)
{
	pw.document.open();
	pw.document.writeln("<html>");
	pw.document.writeln("<head>");
	pw.document.writeln("<title>Picture Window</title>");
	pw.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>");
	pw.document.writeln("</head>");
	pw.document.writeln("<body bgcolor='#FFFFFF' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>");
	pw.document.writeln("<p><a href='javascript:close()'><img src=" + strImage + " name='thePic' width='100%' height='100%' border='0'></a></p>");
	pw.document.writeln("</body>");
	pw.document.writeln("</html>");
	pw.document.close();
}

function fitWindowSize()
{
	pw.innerWidth = pw.document.layers[0].document.images[0].width;
	pw.innerHeight = pw.document.layers[0].document.images[0].height;
}
