/*
    All variables and functions begin with 'overlay' in order to prevent 
    conflicts with other javascript elements
*/

//to activate the error message for the entire site change this to true
var overlayErrorDisplay = false;
var overlayErrorMessage = "UAT.edu is currently down for maintenance.  Please check back at a later time.";

// dynamic variables based on page and user input for the project
var overlayProjectID = 40;


//paths for the images and flash elements
var overlayImagePath = "/templates/images/overlay/";
var overlayFlashPath = "/templates/flash/";

//the flash height and width variables control the display size of the flash browser and are also used in calculating the
//size of the overlay
var overlayFlashHeight = 120;
var overlayFlashWidth = 488;

//set this to whatever the smallest size the overlay can shrink to, if the flash width increases this should too
var overlayMinWidth = 536;

//other general variables for controlling the size of the areas within the overlay
var overlayImagePadding = 23;
var overlayFooterHeight = 80;

// Sets up the path for the dynamic XML generation page
var overlayXMLPath = "/server_controls/gallery.aspx?project=";

//these variables generally shouldn't be changed
var overlaywWidth;
var overlaywHeight;
var overlayBrowser;
var overlayScreenTop = 0;
var overlayImageOffset = overlayImagePadding * 2 + overlayFlashHeight + overlayFooterHeight;
var overlayRevealed = false;
var overlayTransitioning = false;
var overlayFirstTime = true;
var overlayThumbPosition;
var overlayLargeImages = new Array();
var overlayDescriptions = new Array();
var overlayTitles = new Array();
var overlayWidthGoal;
var overlayHeightGoal;
var overlayTargetImage;
var overlayCurrentGallery = "";
var overlayLoadingGallery = "";

//this needs to be rendered on every page for these functions to work
function renderOverlay()
{
	document.write("<div id='overlayBackHolder'></div>");
	document.write("<div id='overlayImageHolder'></div>");
}

//the functions are in alphabetical order for easy finding


//used for showing and hiding the overlay that contains the flash element
function overlayBasicReveal(id)
{
	var holder = document.getElementById(id);
	if(document.getElementById(id).style.visibility == "visible")
	{
	    holder.innerHTML = "";
		document.getElementById(id).style.visibility = "hidden";
		document.getElementById('overlayBackHolder').style.visibility = "hidden";
	}
	else
	{
		document.getElementById(id).style.visibility = "visible";
		overlayCreateBacking("flash");
		document.getElementById('overlayBackHolder').style.visibility = "visible";
		document.getElementById('overlayBackHolder').style.height = document.body.scrollHeight;
		document.getElementById('overlayBackHolder').style.width = document.body.scrollWidth;
	}
}

// change the gallery in the overlay Flash element
function overlayChangeGallery(filename,position)
{
    var movie = overlayFlashMovie("overlayFlash");
    movie.newLoad(filename,position,true);
    overlayCurrentGallery = filename;
}

function overlayCreateBacking(version)
{
	var thisBrowser = overlaywBrowserType();
	var html = "";
	
	//check to see if it's firefox for the mac, which can't handle the image backing stretched over all the content
	if(thisBrowser != 5)
	{
		html += "<table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'><tr>";
		html += "	<td align='center' valign='middle'>";
		
		//set the javascript that runs the disappearing function based on whether it's an image gallery or displaying a flash file
		if(version == "image")
		{
			html += "<img src='" + overlayImagePath + "back.gif' id='overlayBack' onclick='javascript:overlayReveal();' />";
		}
		else if(version == "flash")
		{
			if(overlayErrorDisplay == false)
			{		
				html += "<img src='" + overlayImagePath + "back.gif' id='overlayBack' onclick='javascript:overlayBasicReveal(\"overlayFlashHolder\");' />";
			}
			else
			{
				html += "<img src='" + overlayImagePath + "back.gif' id='overlayBack' />";
			}
		}
		html += "</td>";
		html += "</tr></table>";
	}
	
	document.getElementById('overlayBackHolder').innerHTML = html;
}

function overlayDelayLoadInline(gallery)
{
    setTimeout("overlayLoadInline('" + gallery + "')", 100);
}

//for the end of an image transition
function overlayEndImageChange()
{
	//set the new image's source and make it visible again
	var changeImage = document.getElementById('overlayChangeImage');
	var holdingImage = document.getElementById('overlayHoldingImage');
	var textTitle = document.getElementById('overlayImageTitle');
	var textDescription = document.getElementById('overlayImageDesc');
	textTitle.innerHTML = "<b>" + overlayTitles[overlayThumbPosition] + "</b>";
	textDescription.value = overlayDescriptions[overlayThumbPosition];
	textDescription.style.width = holdingImage.width;
	changeImage.src = holdingImage.src;
	changeImage.width = holdingImage.width;
	changeImage.height = holdingImage.height;
	changeImage.style.visibility = "visible";
}

// function used with 'pageshow' event for Firefox, reloads the gallery
function overlayFFcached(event)
{
    if(event.persisted == true)
    {
        if(overlayBrowser == 5 || overlayBrowser == 12 || overlayBrowser == 20) 
	    {
	        if(overlayFlashMovie("overlayInlineFlash"))
		    {
		        setTimeout("overlayLoadInline('"+overlayXMLPath+overlayProjectID+"')",1000);
		    }
	    }
	}
}

// function to display a stand alone Flash element in the overlay display
function overlayFlashBox(source,width,height,title,description)
{
	var holder = document.getElementById('overlayFlashHolder');
	var html = "";
	var newLeft;
	var newTop;
	html += "<center>";
	html += "<table cellpadding='0' cellspacing='0' border='0' style='z-index:2;'><tr>";
	html += "	<td class='infoBar'>";
	html += "		<table cellpadding='0' cellspacing='0' border='0' width='100%' style='position:relative;top:-36px;'><tr><td><b>" + title + "</b></td>";
	html += "		<td><img src='" + overlayImagePath + "close.gif' width='22' height='22' border='0' align='right' onMouseDown='javascript:overlayBasicReveal(\"overlayFlashHolder\");'/></td></tr></table>";
	html += "</tr><tr>";
	html += "	<td align='center'>";
	html += "	<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" + width + "' height='" + height + "' id='overlayDynFlash' align='middle' VIEWASTEXT>";
	html += "	<param name='allowScriptAccess' value='sameDomain' />";
	html += "	<param name='allowFullScreen' value='false' />";
	html += "	<param name='wmode' value='transparent' />";
	html += "	<param name='movie' value='" + source + "' /><param name='quality' value='high' />";
	html += "	<embed src='" + source + "' quality='high' name='overlayDynFlash' align='middle' width='" + width + "' height='" + height + "' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
	html += "	</object></td>";
	html += "</tr><tr>";
	html += "	<td align='left' class='footer'>";
	html += "		<b>Description: </b><br /><textarea id='overlayFlashDesc' class='description' readonly='readonly'></textarea></td>";
	html += "</tr></table>";
	html += "</center>";
	
	holder.innerHTML = html;
	if(width < 400)
	{
		width = 400;
	}
	//finding the values to recenter the overlay
	newLeft = (overlaywWidth - width - 20)/2;
	newTop = (overlaywHeight - height - 150)/2;
	if(newLeft < 0)
	{
		newLeft = 0;
	}
	if(newTop < 0)
	{
		newTop = 0;
	}
	//recentering the overlay
	holder.style.left = newLeft;
	holder.style.top = newTop + overlayScreenTop;
	holder.style.width = width + 20;
	holder.style.height = height + 120;
	
	document.getElementById('overlayFlashDesc').value = description;
	document.getElementById('overlayFlashDesc').style.width = width;
	overlayBasicReveal("overlayFlashHolder");
}

// get the Flash element based on browser needs
function overlayFlashMovie(movieName) 
{
    if (overlayBrowser == 3 || overlayBrowser == 11 || overlayBrowser == 19) 
    {
        return window[movieName];
    }
    else
    {
        /* This check sometimes works, sometimes doesn't, sometimes fixes this call in FF,
           but most just messes things up, so I took it out - AZ
        if(document[movieName].length != undefined)
        {
            return document[movieName][1];
        }
        else
        {*/
            return document[movieName];
        //}
    }
}

function overlayImageBox(position,large,title,description,gallery)
{
    overlayLoadingGallery = gallery;
	overlayLargeImages = large;
	overlayTitles = title;
	overlayDescriptions = description;
	//reference for finding which thumb needs to be brought forward in the positionFlash function
	overlayThumbPosition = position;
	var changeImage = document.getElementById('overlayChangeImage');
	var flash = document.getElementById('overlayImageHolder');
    
	if(!overlayTransitioning)
	{
		overlaySwitchImage();
		
		//let the flash element know it was a success
		return true;
	}
	else{
		//otherwise let the flash element know it was a failure
		return false;
	}
}

//function that needs to be called when the page loads to set some reference variables
function overlayInitialize()
{
	//finding the browser being used
	overlayBrowser = overlaywBrowserType();
	//finding the width and height of the window depending on whether IE's being used or not
	if (overlayBrowser == 3 || overlayBrowser == 11 || overlayBrowser == 19) 
	{
		overlaywWidth = document.body.offsetWidth;
		overlaywHeight = document.body.offsetHeight;
	}
	else 
	{
		overlaywWidth = window.innerWidth;
		overlaywHeight = window.innerHeight;
	}
	// setup the events for the gallery
	window.onscroll = overlayUpdateScroll;
    window.onpageshow = overlayFFcached;
    
    //if the error message is set on then display it
	if(overlayErrorDisplay == true)
	{
		overlayRenderError();
	}
    
    // ** Return whether the error flag is set or not. - 8/22/07, DF **
    return overlayErrorDisplay;
}

// load the gallery into the inline Flash element
function overlayLoadInline(filename)
{
    var movie = overlayFlashMovie("overlayInlineFlash");
    movie.newLoad(filename,0,false);   
}

//recentering the holding div on the screen
function overlayMoveHolder(holder,width,height)
{
	var newLeft = (overlaywWidth - width - (overlayImagePadding * 2))/2;
	var newTop = (overlaywHeight - height - overlayImageOffset - overlayImagePadding)/2;
	if(newLeft < 0)
	{
		newLeft = 0;
	}
	if(newTop < 0)
	{
		newTop = 0;
	}
	holder.style.left = newLeft;
	holder.style.top = newTop + overlayScreenTop;
}

//switching the gallery that is being displayed
function overlayNewGallery(filename,position)
{
	overlayLargeImages = null;
	overlayDescriptions = null;
	overlayTitles = null;
	overlayReveal();
    setTimeout("overlayChangeGallery('" + filename + "'," + position + ")",200);
}

//add a new onload event without erasing current onload events
function overlayNewOnload(theFunction)
{
    var oldOnLoad = window.onload;
    if (typeof window.onload != 'function') 
    {
        window.onload = theFunction;
    }
    else 
    {
        window.onload = function() 
        {
            oldOnLoad();
            theFunction();
        }
    } 
}

//calling the image to the right through the arrow images
function overlayNextImage()
{
	if(!overlayTransitioning)
	{
		if(overlayThumbPosition + 1 > overlayLargeImages.length - 1)
		{
			overlayThumbPosition = 0;
		}
		else
		{
			overlayThumbPosition += 1;
		}
		
		overlaySwitchImage();
		overlayStartImageChange();
		setTimeout("overlayPositionFlash()",100);
	}
}

// make sure the Flash overlay element is showing the correct thumb image
function overlayPositionFlash()
{
    var movie = overlayFlashMovie("overlayFlash");
    movie.callToFront(overlayThumbPosition);
}

//calling the image to the left through the arrow images
function overlayPrevImage()
{
	if(!overlayTransitioning)
	{
		if(overlayThumbPosition - 1 < 0)
		{
			overlayThumbPosition = overlayLargeImages.length - 1;
		}
		else
		{
			overlayThumbPosition -= 1;
		}
		
		overlaySwitchImage();
		overlayStartImageChange();
		setTimeout("overlayPositionFlash()",100);
	}
}

//putting the error message into the overlay
function overlayRenderError()
{
	var html = "";
	html += "<center>";
	html += "<table cellpadding='0' cellspacing='0' border='0' style='z-index:2;'><tr>";
	html += "<td colspan='3' class='infoBar'>";
	html += "<table cellpadding='0' cellspacing='0' border='0' width='100%' style='position:relative;top:-27px;'><tr><td><div id='overlayImageTitle'></div></td>";
	html += "<td align='right'></td></tr></table>";
	html += "</tr><tr>";
	html += "<td width='20'>&nbsp;</td>";
	html += "	<td align='center' style='color:#ffffff;height:200px;width:400px;font-size:.9em;'>";
	html += overlayErrorMessage + "</td>";	
	html += "<td width='20'>&nbsp;</td>";
	html += "</tr><tr>";
	html += "	<td colspan='3' align='left' class='footer'>";
	html += "				</td>";
	html += "		</tr></table>";
	html += "</center>";
	
	document.getElementById('overlayImageHolder').innerHTML = html;
	
	//center the message before making it visible based on empty image widths
	overlayMoveHolder(document.getElementById('overlayImageHolder'),overlayMinWidth + overlayImagePadding*2,overlayImageOffset);
	overlayBasicReveal("overlayImageHolder");
}

// insert the inline Flash element into the page and load the gallery
function overlayRenderInlineBrowser(gallery)
{
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" + overlayFlashWidth + "' height='" + (overlayFlashHeight - 10) + "' id='overlayInlineFlash' align='middle' VIEWASTEXT>");
	document.write("<param name='allowScriptAccess' value='sameDomain' />");
	document.write("<param name='movie' value='" + overlayFlashPath + "imageBrowser.swf' />");
	document.write("<param name='quality' value='high' />");
	document.write("<param name='wmode' value='transparent' />");
	//document.write("<param name='flashvars' value='template=" + template_type + "&overlay=false' />");
	document.write("<param name='flashvars' value='template=" + template_type + "&overlay=false&gallery=" + gallery + "' />");
	//document.write("<embed src='" + overlayFlashPath + "imageBrowser.swf' quality='high' wmode='transparent' flashvars='template=" + template_type + "&overlay=false' width='" + overlayFlashWidth + "' height='" + (overlayFlashHeight - 10) + "' name='overlayInlineFlash' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("<embed src='" + overlayFlashPath + "imageBrowser.swf' quality='high' wmode='transparent' flashvars='template=" + template_type + "&overlay=false&gallery=" + gallery + "' width='" + overlayFlashWidth + "' height='" + (overlayFlashHeight - 10) + "' name='overlayInlineFlash' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
	
	//setTimeout("overlayLoadInline('" + gallery + "')",1500);
	//overlayNewOnload(function() { setTimeout("overlayLoadInline('" + gallery + "')",1500); });
	
	//check to see if an error message is being displayed, if not render the overlay browser
	if(overlayErrorDisplay == false)
	{
		overlayRenderOverlayBrowser();
	}
}

// insert the inline Flash element into the page and load the gallery
function overlayReturnInlineBrowser(gallery)
{
	var returnContent = "";
	returnContent = returnContent + "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" + overlayFlashWidth + "' height='" + (overlayFlashHeight - 10) + "' id='overlayInlineFlash' align='middle' VIEWASTEXT>";
	returnContent = returnContent + "<param name='allowScriptAccess' value='sameDomain' />";
	returnContent = returnContent + "<param name='movie' value='" + overlayFlashPath + "imageBrowser.swf' />";
	returnContent = returnContent + "<param name='quality' value='high' />";
	returnContent = returnContent + "<param name='wmode' value='transparent' />";
	returnContent = returnContent + "<param name='flashvars' value='template=" + template_type + "&overlay=false' />";
	returnContent = returnContent + "<embed src='" + overlayFlashPath + "imageBrowser.swf' quality='high' wmode='transparent' flashvars='template=" + template_type + "&overlay=false' width='" + overlayFlashWidth + "' height='" + (overlayFlashHeight - 10) + "' name='overlayInlineFlash' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
	returnContent = returnContent + "</object>";
	setTimeout("overlayLoadInline('" + gallery + "')",1500);
	
	//check to see if an error message is being displayed, if not render the overlay browser
	if(overlayErrorDisplay == false)
	{
		overlayRenderOverlayBrowser();
	}
	return returnContent;
}

// insert all the needed overlay elements into the page
function overlayRenderOverlayBrowser()
{
    var html = "";
    html += "<div id='overlayHoldingPen'></div>";
	html += "<div id='overlayFlashHolder'></div>";
	html += "<center>";
	html += "<table cellpadding='0' cellspacing='0' border='0' style='z-index:2;'><tr>";
	html += "<td colspan='3' class='infoBar'>";
	html += "<table cellpadding='0' cellspacing='0' border='0' width='100%' style='position:relative;top:-27px;'><tr><td><div id='overlayImageTitle'></div></td>";
	html += "<td><img src='" + overlayImagePath + "close.gif' width='22' height='22' border='0' align='right' onMouseDown='javascript:overlayReveal();'/></td></tr></table>";
	html += "</tr><tr>";
	html += "	<td colspan='3' align='center'>";
	html += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" + overlayFlashWidth + "' height='" + overlayFlashHeight + "' id='overlayFlash' align='middle' VIEWASTEXT>";
	html += "<param name='allowScriptAccess' value='sameDomain' />";
	html += "<param name='movie' value='" + overlayFlashPath + "imageBrowser2.swf' />";
	html += "<param name='quality' value='high' />";
	html += "<param name='wmode' value='transparent' />";
	html += "<param name='flashvars' value='template=" + template_type + "&overlay=true' />";
	html += "<embed src='" + overlayFlashPath + "imageBrowser2.swf' quality='high' wmode='transparent' flashvars='template=" + template_type + "&overlay=true' width='" + overlayFlashWidth + "' height='" + overlayFlashHeight + "' name='overlayFlash' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
	html += "</object>";
	html += "<br /></td>";
	html += "</tr><tr>";
	html += "	<td align='right'><img src='" + overlayImagePath + "prev.gif' width='23' height='25' border='0' onmouseover=\"this.style.cursor='pointer';\" onmouseout=\"this.style.cursor='default';\" onMouseDown='javascript:overlayPrevImage();'/></td>";
	html += "	<td align='center'><img id='overlayChangeImage' src='" + overlayImagePath + "back.gif'/></td>";
	html += "	<td align='left'><img src='" + overlayImagePath + "next.gif' width='23' height='25' border='0' onmouseover=\"this.style.cursor='pointer';\" onmouseout=\"this.style.cursor='default';\" onMouseDown='javascript:overlayNextImage();'/></td>";
	html += "</tr><tr>";
	html += "	<td colspan='3' align='left' class='footer'>";
	html += "				<b>Description: </b><br /><textarea id='overlayImageDesc' class='description' readonly='readonly'></textarea></td>";
	html += "		</tr></table>";
	html += "</center></div>";
	
	document.getElementById('overlayImageHolder').innerHTML = html;
}

// resize the overlay till it is the correct size
function overlayResize()
{
	if(overlayFirstTime)
	{
		//the browser doesn't seem to have time to register the image change and all its properties 
		//so it needs a moment to process the change
		overlayFirstTime = false;
		setTimeout("overlayResize()",100);
	}
	else
	{
		//find what the new target width and height are
		overlayWidthGoal = overlayTargetImage.width + overlayImagePadding * 2;
		if(overlayWidthGoal < overlayMinWidth)
		{
			//make sure the goal isn't smaller than the flash object
			overlayWidthGoal = overlayMinWidth;
		}
		overlayHeightGoal = overlayTargetImage.height + overlayImageOffset;
		var flash = document.getElementById('overlayImageHolder');
		var table = document.getElementById('overlayFlashTable');
		var textDescription = document.getElementById('overlayImageDesc');
		//find the float values of the width and height styles
		var width = overlayStyleToFloat(flash.style.width);
		var height = overlayStyleToFloat(flash.style.height);
		//get the new target values
		width += ((overlayWidthGoal - width)/2);
		height += ((overlayHeightGoal - height)/2);
		
		//if the new target values are very close to the goals
		if((Math.round(width) == Math.round(overlayWidthGoal)) && (Math.round(height) == Math.round(overlayHeightGoal)))
		{
			//set the width and height to their goals
			flash.style.width = overlayWidthGoal;
			flash.style.height = overlayHeightGoal;
			//textDescription.style.width = widthGoal - imagePadding;
			//set the flags back to their default values
			overlayTransitioning = false;
			overlayFirstTime = true;
			//run the final section of the script
			overlayEndImageChange();
		}
		//if it's not very close to the goals
		else
		{
			//set the width and height to the new targets
			flash.style.width = width;
			flash.style.height = height;
			textDescription.style.width = width - overlayImagePadding * 2;
			//move the div to keep it centered
			overlayMoveHolder(document.getElementById('overlayImageHolder'),width,height - overlayImageOffset);
			//run the script again
			setTimeout("overlayResize()",50);
		}
	}
}

// show the overlay elements
function overlayReveal()
{
	overlayCreateBacking("image");
	var holder = document.getElementById('overlayBackHolder');
	var flash = document.getElementById('overlayImageHolder');
	var image = document.getElementById('overlayChangeImage');
	var holdingImage = document.getElementById('overlayHoldingImage');
	//center the image before making it visible based on empty image widths
	overlayMoveHolder(flash,overlayMinWidth + overlayImagePadding*2,overlayImageOffset);
	//if the holder is currently visible, hide it and all of its elements
	if(holder.style.visibility == "visible")
	{
		holder.style.visibility = "hidden";
		flash.style.visibility = "hidden";
		image.style.visibility = "hidden";
		overlayRevealed = false;
	}
	//if it's not visible yet, make everything visible
	else
	{
		holder.style.visibility = "visible";
		flash.style.visibility = "visible";
		holder.style.height = document.body.scrollHeight;
		//assigning some initial values to the holding div, to be referenced by later scripts
		flash.style.width = overlayMinWidth + overlayImagePadding*2;
		flash.style.height = 100 + overlayImageOffset;
		overlayRevealed = true;
	}
}

// transition the elements to display the next image in the overlay
function overlayStartImageChange()
{
	//check to make sure it's not already in the middle of a transition
	if(!overlayTransitioning)
	{
		//if the image holder isn't showing then show it
		if(!overlayRevealed)
		{		    
		    if(overlayCurrentGallery == overlayLoadingGallery)
		    {
			    overlayReveal();
			    //the flash element seems to need a moment to be visible before the positioning code can be executed
			    setTimeout("overlayPositionFlash()",100);
			}
			else
			{
				overlayCurrentGallery = overlayLoadingGallery;
				overlayNewGallery(overlayLoadingGallery,overlayThumbPosition);
			}
		}
		//set the flag to keep the transition from triggering again if it's already in the middle of a change
		overlayTransitioning = true;
		//call the resize function
		overlayResize();
	}
}

//returning an integer version of a stylesheet's width value
function overlayStyleToFloat(style)
{
	//the last two pieces of the string are "px", just chopping those off and converting it to a float and returning it
	var styleHolder = style.slice(0,-2);
	return parseFloat(styleHolder);
}

// change the displayed images in the overlay
function overlaySwitchImage()
{
	//set the html for the holding image, when the image loads it will call the startImageChange function
	var holdingImage = "<img src=\"" + overlayLargeImages[overlayThumbPosition] + "\" id=\"overlayHoldingImage\"  onLoad=\"overlayStartImageChange();\" >";
	//hide the image that's changing
	var changeImage = document.getElementById("overlayChangeImage");
	changeImage.style.visibility = "hidden";
	//changeImage.src = "";
	
	//create the holding image and make it the targetImage for reference in other things
	document.getElementById('overlayHoldingPen').innerHTML = holdingImage;
	overlayTargetImage = document.getElementById('overlayHoldingImage');
	if(changeImage.width > overlayTargetImage.width)
	{
		changeImage.width = overlayTargetImage.width;
	}
	if(changeImage.height > overlayTargetImage.height)
	{
		changeImage.height = overlayTargetImage.height;
	}
}

// function to show elements from the Flash object
function overlayTestAlert(message)
{
    alert(message);
}

// update the position, so when the user clicks a thumb, the overlay is centered
function overlayUpdateScroll()
{
	overlayScreenTop = document.body.scrollTop;
    document.getElementById('overlayBackHolder').style.width = document.body.scrollWidth;
    document.getElementById('overlayBackHolder').style.height = document.body.scrollHeight;
}

//Joe's script to figure out which browser is being used
function overlaywBrowserType() 
{
	/*
	__ net_browser flag values based on OS/Browser __
		0 = Undetermined OS / Browser
		17 = Undetermined OS / Browser
	MAC OS:
		2 = Unknown Browser
		3 = Internet Explorer
		4 = Safari
		5 = Firefox
		6 = Netscape
		7 = Opera
		8 = Camino
		9 = Firebird
	WINDOWS OS:
		10 = Unknown Browser
		11 = Internet Explorer
		12 = Firefox
		13 = Netscape
		14 = Opera
		15 = Camino
		16 = Firebird
	UNKNOWN OS:
		17 = Unknown Browser
		18 = Safari
		19 = Internet Explorer
		20 = Firefox
		21 = Netscape
		22 = Opera
		23 = Camino
		24 = Firebird
	*/
	var btfound = 0;
	var net_browser; 
	var browser_detect = navigator.userAgent.toLowerCase();

	if ((browser_detect.indexOf("konqueror") + 1)) { btfound = 1; net_browser = 1; }

	if ((browser_detect.indexOf("mac_powerpc") + 1)) { btfound = 1; net_browser = 3; }

	if (btfound == 0) {
		// MAC OS
		if ((browser_detect.indexOf("macintosh") + 1)) {
			if ((browser_detect.indexOf("safari") + 1)) { btfound = 1; net_browser = 4; }
			else if ((browser_detect.indexOf("firefox") + 1)) { btfound = 1; net_browser = 5; }
			else if ((browser_detect.indexOf("netscape") + 1)) { btfound = 1; net_browser = 6; }
			else if ((browser_detect.indexOf("opera") + 1)) { btfound = 1; net_browser = 7; }
			else if ((browser_detect.indexOf("camino") + 1)) { btfound = 1; net_browser = 8; }
			else if ((browser_detect.indexOf("firebird") + 1)) { btfound = 1; net_browser = 9; }
			else { btfound = 1; net_browser = 2; }
		}
		
		// Windows OS
		if ((browser_detect.indexOf("windows") + 1) && btfound == 0) {
			if ((browser_detect.indexOf("msie") + 1)) { btfound = 1; net_browser = 11; }
			else if ((browser_detect.indexOf("firefox") + 1)) { btfound = 1; net_browser = 12; }
			else if ((browser_detect.indexOf("netscape") + 1)) { btfound = 1; net_browser = 13; }
			else if ((browser_detect.indexOf("opera") + 1)) { btfound = 1; net_browser = 14; }
			else if ((browser_detect.indexOf("camino") + 1)) { btfound = 1; net_browser = 15; }
			else if ((browser_detect.indexOf("firebird") + 1)) { btfound = 1; net_browser = 16; }
			else { btfound = 1; net_browser = 10; }
		}
		
		// Unknown OS
		if (btfound == 0) {
			if ((browser_detect.indexOf("safari") + 1)) { net_browser = 18; }
			else if ((browser_detect.indexOf("msie") + 1)) { net_browser = 19; }
			else if ((browser_detect.indexOf("firefox") + 1)) { net_browser = 20; }
			else if ((browser_detect.indexOf("netscape") + 1)) { net_browser = 21; }
			else if ((browser_detect.indexOf("opera") + 1)) { net_browser = 22; }
			else if ((browser_detect.indexOf("camino") + 1)) { net_browser = 23; }
			else if ((browser_detect.indexOf("firebird") + 1)) { net_browser = 24; }
			else { net_browser = 17; }
		}
	}
	
	return net_browser;
}