var reloaded = false;

var maxHeight = 600;
var maxWidth = 600;

///
// sets the global variables and loads the LargeImage page
///
function ShowImage(path, title, caption)
{
	ShowImage(path, title, caption, "");
}

///
// sets the global variables and loads the LargeImage page
///
function ShowImage(path, title, caption, credit)
{
	var rootDir = GetRootDirectory();
	var pagePath = rootDir + "images/LargeImage.htm";

	location.href = pagePath + "?path=" + path + "&title=" + title + "&caption=" + caption + "&credit=" + credit;
}

///
// fires when LargeImage.htm loads
///
function OnLoadLargeImage()
{
	var callingPage = " " + window.location;

	if (callingPage.indexOf("PhotoGallery/") > -1)
	{
		GetElement("BackUpLinkSection").innerHTML = "<font size=\"2\" color=\"#272E5A\">" +
				"<a href=\"javascript:history.go(-1);\">" + 
				"Back to Parent Gallery</a> </font>";
		GetElement("BackToGallerySection").innerHTML = "<font size=\"2\" color=\"#272E5A\">" +
				"<a href=\"../PhotoGallery/PhotoGallery.htm\">" + 
				"Back to Main Gallery</a></font>";
	}
	LoadImage();
}

///
// loads the image, caption, and title on LargeImage.htm
///
function LoadImage()
{
	var imagePath = "";
	var pageTitle;
	var imageCaption; 
	var imageCredit = "";
	var altCaption = "";
	
	var paramString = location.search.split("&"); 

	///not sure why, but in Firefox this has to be done.
	while (imagePath == "")
	{
		for (i = 0; i < paramString.length; i++)
		{
			var paramSet = paramString[i].replace("?", "");
			var parts = paramSet.split("=");
			for (j = 0; j < parts.length; j++)
			{
				switch (parts[0])
				{
					case "path":
						imagePath = parts[1];
						break;
					case "title":
						pageTitle = ScrubText(parts[1]);
						break;
					case "caption":
						imageCaption = ScrubText(parts[1]);
						altCaption = RemoveItalicsAndBoldTags(imageCaption);
						break;
					case "credit":
						imageCredit = ScrubText(parts[1]);
						break;
				}
			}
		}
	}
	
	imagePath = "../" + imagePath;
		
	if (imageCredit != "" && imageCredit != "undefined")
	{
		GetElement("creditCell").innerHTML = "<font size='1'>" + imageCredit + "</font>";
	}
	
	GetElement("largeImage").src = imagePath;
	GetElement("largeImage").alt = altCaption;
	GetElement("imageUrl").href = "javascript:history.go( -1 );";
	
	document.title = pageTitle;
	GetElement("captionCell").innerHTML = imageCaption;
	GetElement("captionCell").align = "center";
	GetElement("captionCell").fontSize = "2";
}

///
// Italicizes any group names included in caption
///
function ScrubText(caption)
{
	var res = caption.replace(/Loose Cannons/g, '<i>Loose Cannons</i>');
	res = res.replace(/The Jazz Guardians/g, '<i>The Jazz Guardians</i>');
	res = res.replace(/The Old Flint River Dixieland Band/g, '<i>The Old Flint River Dixieland Band</i>');
	res = res.replace(/~/g,"\'");
	res = res.replace(/%20/g, ' ');
	return res;
}

///
// Removes the italics and bold tags (<i></i> and <b></b>)
///
function RemoveItalicsAndBoldTags(caption)
{
	var res = caption;
	res = res.replace(/<i>/g,"");
	res = res.replace(/<\/i>/g,"");
	res = res.replace(/<b>/g,"");
	res = res.replace(/<\/b>/g,"");
	return res;
}