function openNewWindow(vURL, vWidth, vHeight) {
	window.open(vURL, '_blank', 'width=' + vWidth + ',height=' + vHeight + ',toolbar=no,location=no');
	return false;
}

function openFullScreenWindow(href)
{
	var xOffset;

	xOffset = screen.width - screen.availWidth;
	window.open(href, '_blank', 'width=' + (screen.availWidth - xOffset) + ',height=' + screen.availHeight + ',left=' + xOffset + ',top=0,toolbar=no,location=no');
	return false;
}



var JUResourcesHref = null;

function setupJavascriptUtilities(resourcesHref)
{
    JUResourcesHref = resourcesHref;
}

function fixupThumbnails()
{
    var images = document.images;
    var imageCount = images.length;
    var imageIndex;
    for (imageIndex = 0; imageIndex < imageCount; imageIndex++) {
        var image = images[imageIndex];
	var baseSrc = image.src;
        if (baseSrc != null && baseSrc != undefined) {
            var stringIndex = baseSrc.lastIndexOf(".thumb.");
            if (stringIndex != -1) {
                image.mediumSrc = baseSrc.replace(".thumb.", ".medium.");
            }
        }
    }
}

function openPictureFrame(imagePath, width, height, imageTitle)
{
    if (JUResourcesHref == null) {
        alert("Unable to open picture frame because the Javascript utilities have not been setup (need to call setupJavascriptUtilities() with the href to the resources) so the picture frame HTML file can not be located.");
        return false;
    }

    if (imagePath == null) {
        return false;	// nothing to do
    }

    if (imageTitle == null) {
        var index = imagePath.lastIndexOf("/");
        if (index == -1) {
            imageTitle = imagePath;
        } else {
            imageTitle = imagePath.substring(index + 1);
        }
    }

    if ((imagePath.indexOf("http:") != 0) &&
        (imagePath.indexOf("ftp:") != 0) &&
        (imagePath.indexOf("file:") != 0)) {
        // The image path is a relative path - get the current path, and prepend it to the image path
        var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname;
        var index = currentPath.lastIndexOf("/");
        if (index != -1) {
            // Trim off any trailing filename (such as "index.html")
            currentPath = currentPath.substring(0, index);
        }
        imagePath = currentPath + "/" + imagePath;
    }

    var desiredWidth = parseInt(width) + 160;	// add a border area
    var desiredHeight = parseInt(height) + 160;	// add a border area
    var screen = window.screen;
    var screenWidth = screen.availWidth;
    if (desiredWidth > screenWidth) {
        desiredWidth = screenWidth;
    }
    var screenHeight = screen.availHeight;
    if (desiredHeight > screenHeight) {
        desiredHeight = screenHeight;
    }

    return openNewWindow(JUResourcesHref + "/picture_frame.html?picture=" + imagePath + "&title=" + imageTitle, desiredWidth, desiredHeight);
}

function getURLParameter(url, parameterName, defaultValue)
{
	var returnValue;
	var stringValue;

	parameterName = parameterName + "=";
	returnValue = defaultValue;
	stringValue = url.toString();

	index = stringValue.indexOf("?");
	if (index == -1) {
		return returnValue;
	}
	stringValue = stringValue.substring(index + 1);

	index = stringValue.indexOf(parameterName);
	if (index != -1) {
		returnValue = stringValue.substring(index + parameterName.length);
       }
	return returnValue;
}
