/*
 * Global variables
 */
var win;



/*
 * Name:		ExternalLinks
 * Description:	Cycles through all "a" tags.  If the tag has an href attribute,
 *				a class attribute, and the class name is "external", set the
 *				target of the tag to whatever the title attribute is.
 */
	function ExternalLinks(doc)
	{

		if (!doc.getElementsByTagName) 
		{
			return;
		}
		else
		{
		}

		var anchors = doc.getElementsByTagName('a');

		for (var i = 0; i < anchors.length; i++)
		{
			var anchor = anchors[i];

			if (anchor.getAttribute('href') != null || anchor.href != null)
			{
				if (anchor.className != null || anchor.getAttribute('class') != null)
				{
					if (anchor.className == 'external' || anchor.getAttribute('class') == 'external')
					{
						anchor.target = anchor.getAttribute('title');
					}
				}

			}

		}

	}

/*
 * Name:		NewWindow
 * Description:	Accepts a URL string, name, width, height, and a string holding
 *				the other window open parameters and returns the result of calling
 *				window.open with those parameters.
 *				Basically, just a wrapper for window.open.
 */
	function NewWindow(sURL, sName, iWidth, iHeight, sOptions)
	{
		var winReturn;
		if (sOptions == '')
		{
			winReturn = window.open(sURL, sName, 'HEIGHT=' + iHeight + ',WIDTH=' + iWidth);
		}
		else
		{
			winReturn = window.open(sURL, sName,'HEIGHT=' + iHeight + ',WIDTH=' + iWidth + ',' + sOptions);
		}
		return(winReturn);
	}


/*
 * Name:		PopupImage
 * Description:	Acts as a wrapper for the NewWindow function when displaying an image.
 */
		function PopupImage(img)
		{

			var sHTML = '';

			sHTML = '<html>'
			sHTML += '	<head>'
			sHTML += '		<title>' + img.alt + '</title>';
			sHTML += '		<style type="text/css" media="screen">';
			sHTML += '			@import url("css/gph_screen.css");';
			sHTML += '		</style>';
			sHTML += '		<script type="text/javascript" src="js/gph.js"></script>';
			sHTML += '	</head>'
			sHTML += '	<body onload="ResizeImageWindow(window);" style="margin: 1em;text-align: center;">';
			sHTML += '		<p><img src="' + img.src.replace('_sm', '') + '"></p>';
			sHTML += '		<p align="center" style="margin: auto;width: 90%;">' + img.alt + '</p>';
			sHTML += '		<p align="center" style="margin: auto;width: 90%;"><a href="#" onclick="window.close();">close window</a></p>';
			sHTML += '	</body>';
			sHTML += '</html>';

			if (win)
			{
				win.close();
			}

			win = window.open('about:blank', 'WinImage', 'directories=no,location=no,menubar=no,scrollbars=no,status=no');

			win.blur();
			win.document.open();
			win.document.write(sHTML);
			win.document.close();
			win.focus(newwindow.focus());

		}

/*
 * Name:		ResizeImageWindow
 * Description:	Accepts a window object as its only parameter and adjusts the size of the window
 *				according to the size of the image it holds.
 */
		function ResizeImageWindow(win)
		{

			// only one image on the page, so we're resizing the window based on its dimensions
			var img = document.images[0];

			win.blur();
			win.resizeTo((img.width + 75), (img.height + 150));
			win.focus();

		}
