function openPGWin( windowURL, windowName, windowFeatures ) {
	return window.open( windowURL, windowName, windowFeatures ); 
}

function centerCoords() {						
	if (screen.width && screen.Height) {
		mX = Math.ceil(screen.width / 2);
		mY = Math.ceil(screen.Height / 2);

		mX = isNaN(mX) ? 400: mX;
		mY = isNaN(mY) ? 300: mY;

		return new Array(mX, mY);
	} else {
		return false;
	}
}

function slideShowPop(popUrl) {
	var screenCenter = centerCoords();
	var popWidth = 733;
	var popHeight = 549;
	var popLeft = Math.ceil(screenCenter[0] - (popWidth/2));
	var popTop = Math.ceil(screenCenter[1] - (popHeight/2) - 25);
	
	popLeft = isNaN(popLeft) ? 250: popLeft;
	popTop = isNaN(popTop) ? 250: popTop;

	if (popLeft.toLower == "nan") {
		popLeft = 175;
		popTop = 175;		
	}

	var properties = "width=" + popWidth + ",height=" + popHeight;
		if (popLeft.toString().toLowerCase() != "nan") {
			properties += ",left=" + popLeft + ",top=" + popTop;
		}
		properties += ",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=1";

	slideShowWin = openPGWin(popUrl, "slideShowWin", properties); 
	slideShowWin.focus();
}

function buyPhoto(pictopiaID, photoID, photoPath) {
	var screenCenter = centerCoords();
	var popWidth = 700;
	var popHeight = 710;
	var popLeft = Math.ceil(screenCenter[0] - (popWidth/2));
	var popTop = Math.ceil(screenCenter[1] - (popHeight/2) - 25);
	
	popLeft = isNaN(popLeft) ? 250: popLeft;
	popTop = isNaN(popTop) ? 250 : popTop;

	var properties = "width=" + popWidth + ",height=" + popHeight;
		properties += ",left=" + popLeft + ",top=" + popTop;
		properties += ",toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=1,resizable=1";

	if (photoPath.indexOf("http") == -1 && photoPath.charAt(0) == "/") {
		// This should never get run, but I'm paranoid -rpb.
		photoPath = "http://imagesource.zwire.com" + photoPath;
	}


	var filename = photoPath.substring(photoPath.lastIndexOf("/")+1,photoPath.length)

	// get photo name for pictopia
	// keep image_[photoid] for images where the name begins with 2005 or 2006 and there is an underscore in the 9 char location
	if ((filename.indexOf("2005") == 0 || filename.indexOf("2006") == 0) && filename.substring(0,filename.indexOf("_") == 8)) 
			photoName = "image_" + photoID;
	else
			photoName = filename;

	pUrl = "http://www.pictopia.com/perl/ptp/" + pictopiaID + "?photo_name=" + photoName + "&t_url=" + photoPath;
	if (document.location.href.indexOf("debug=1") > 0) {
		alert("Debug:\n" + pUrl);
	} else {
		buyPhotoWin = openPGWin(pUrl, "buyPhotoWin", properties); 
		buyPhotoWin.focus();
	}
}

