
function stringReverse( str )
	{
	var strRev = '';
	for( i=str.length; i>0; i-- )
		{
		strRev += str.charAt(i-1);
		}
	return strRev;
	}

function stringDeMangle( str )
	{
	var newStr = '';
	for( i=str.length; i>0; i-- )
		{
		newStr += String.fromCharCode(str.charCodeAt(i-1));
		}
	return newStr;
	}

var popupObj = null;
var popupWindowObj;
var popupWindow;

function showPopup( popupName )
	{
	if ( popupObj )
		{
		popupObj.style.visibility = 'hidden';
		}
	popupObj = document.getElementById(popupName);
	if ( popupObj )
		{
		positionPopup();
		popupObj.style.visibility = 'visible';
		return false;
		}
	return true;
	}

function hidePopup( popupName )
	{
	popupObj.style.visibility = 'hidden';
	popupObj.style.top = 0;
	popupObj.style.left = 0;
	popupObj = null;
	return false;
	}

if ( window.addEventListener )
	{
	window.addEventListener('scroll', rePositionPopupOnScroll, false);
	}
else if ( document.addEventListener )
	{
	document.addEventListener('scroll', rePositionPopupOnScroll, false);
	}
else
	{
	window.onscroll = function() { rePositionPopupOnScroll() }
	}

function rePositionPopupOnScroll()
	{
	return positionPopup();
	}

function positionPopup()
	{
	if ( popupObj )
		{
		var clientX, clientY;
		if (self.innerHeight) // all except Explorer
			{
			clientX = self.innerWidth;
			clientY = self.innerHeight;
			}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
			{
			clientX = document.documentElement.clientWidth;
			clientY = document.documentElement.clientHeight;
			}
		else if (document.body) // other Explorers
			{
			clientX = document.body.clientWidth;
			clientY = document.body.clientHeight;
			}
		if ( popupObj.offsetHeight+16  > clientY )
			{
			popupObj.style.height = clientY-16;
			}

		var scrollTop = 0;
		if ( document.body.scrollTop )
			{
			scrollTop = document.body.scrollTop;
			}
		else
			{
			scrollTop = window.pageYOffset;
			}
		if ( ! scrollTop )
			{
			scrollTop = 0;
			}
		var left = parseInt((mainBoxWidth - popupObj.offsetWidth) / 2) + 10;
		var top  = scrollTop + parseInt((clientY - popupObj.offsetHeight) / 2);
		if ( left < 0 )
			{
			left = 0;
			}
		if ( top < 0 )
			{
			top = 0;
			}
		popupObj.style.left = left;
		popupObj.style.top = top;
		}
	return false;
	}

function launchPictureWindow( picURL_or_image_id, caption, credit )
	{
	url  = 'pictureWindow.php';
	if ( parseInt(picURL_or_image_id) > 0 )
		{
		url += '?image_id=' + picURL_or_image_id;
		}
	else
		{
		url += '?picURL=' + picURL_or_image_id;
		url += '&caption=' + caption;
		url += '&credit=' + credit;
		}
	return launchPopupWindow( url );
	}

function launchPopupWindow( url )
	{
	popupFeatures = 'height=575,width=575,resizable=yes,screenY=30,top=30,screenX=30,left=30,scrollbars=yes';
	popupWindowObj = window.open(url, 'popupWindow', popupFeatures);
	popupWindowObj.focus();
	return false;
	}

function launchNewBrowserWindow( url )
	{
	window.open( url );
	return false;
	}
