/***********************************************************************************
* Script By J. Steve Hamaker                                                       *
* Script Last Updated on 4/15/2011                                                 *
* Version: 0.4                                                                     *
* Edited for HamakersMuseum.com                                                    *
*                                                                                  *
* Purpose: This script opens images on the same page, allowing forward and back    *
*   through the images linked to in the page.                                      *
*                                                                                  *
* Requires: This script relies on functions in cookies.js. The script to include   *
*   this file is within this script, so a second include is not required. For      *
*   layout, this file requires slideshow_screen.css. Required files are in the     *
*   ssimage/ folder.                                                               *
*                                                                                  *
* Usage: Include this script with any pages that you want to activate this usage   *
*   Set the link relation (rel) to "thumb", and this script will act upon that.    *
*   If there are more pages, the script will recognize "next", "previous", "first",*
*   and "last" relations as well. If someone uses the next or previous page links  *
*   from the script, it will automatically load the slideshow when the new page    *
*   loads.                                                                         *
*                                                                                  *
* Known Issues:                                                                    *
*   This only works properly in IE if the page is XHTML strict.                    *
*   Flash and quicktime movies cannot auto-detect size                             *
*   Description box is under movies and flash, not over like it should be          *
*                                                                                  *
* NOTE: This script adds to the onload, onmousemove, and onresize elements.        *
*   Overiding these elements will disrupt this script.                             *
*                                                                                  *
* Changes in v0.4:                                                                 *
*   Added the ability to add a description to the image. The description box will  *
*     be open and closable and lockable.                                           *
*                                                                                  *
* Changes in v0.3.3:                                                               *
*   Extended the mov code so it works in IE. Added download link code to Quicktime *
*     and Flash in case user has those disabled.                                   *
*                                                                                  *
* Changes in v0.3.2:                                                               *
*   Added quicktime mov file format. Attempts to add avi and mpg format failed.    *
*                                                                                  *
* Changes in v0.3.1:                                                               *
*   Added the ability to specify an image or flash movie size in a comment.        *
*                                                                                  *
* Changes in v0.3:                                                                 *
*   Basic Flash Movie Support.                                                     *
*                                                                                  *
* Changes in v0.2:                                                                 *
*   Moved images to variables so they can be easily changed or moved               *
***********************************************************************************/

/***************************** User Set Variables *********************************/
OPEN_CLOSE_SPEED = 20; // Speed slideshow opens and closes, min=1 max=100, 50+ is pretty much instant
RESET_ZOOM = false; // If set to true, zoom mode will be reset to fit-to-screen with each image
DESCRIPTION_WIDTH = 700; // Width of the description box, over 700 may cause issues to people with small resolution screens (Set in CSS too)
DESCRIPTION_CHARS = 50; // Number of characters the description box crops to

/*****************************     Image List     *********************************/
// SSi is image location (relative to web page, not to script), SSx is width, SSy is height
SSi_close = 'ssimage/icon_close.png'; // Close Icon
SSx_close = 25;
SSy_close = 25;
SSi_zoomin = 'ssimage/icon_zoomin.png'; // Zoom In Icon
SSx_zoomin = 25;
SSy_zoomin = 25;
SSi_zoomout = 'ssimage/icon_zoomout.png'; // Zoom Out Icon
SSx_zoomout = 25;
SSy_zoomout = 25;
SSi_first = 'ssimage/icon_first.png'; // First Image Icon
SSx_first = 25;
SSy_first = 25;
SSi_back = 'ssimage/icon_back.png'; // Previous Image Icon
SSx_back = 25;
SSy_back = 25;
SSi_next = 'ssimage/icon_next.png'; // Next Image Icon
SSx_next = 25;
SSy_next = 25;
SSi_last = 'ssimage/icon_last.png'; // Last Image Icon
SSx_last = 25;
SSy_last = 25;
var SSi_page = new Array();
var SSx_page = new Array();
var SSy_page = new Array();
SSi_page[0] = 'ssimage/icon_page0.png'; // First Page Icon
SSx_page[0] = 180;
SSy_page[0] = 24;
SSi_page[1] = 'ssimage/icon_page1.png'; // Previous Page Icon
SSx_page[1] = 180;
SSy_page[1] = 24;
SSi_page[2] = 'ssimage/icon_page2.png'; // Next Page Icon
SSx_page[2] = 180;
SSy_page[2] = 24;
SSi_page[3] = 'ssimage/icon_page3.png'; // Last Page Icon
SSx_page[3] = 180;
SSy_page[3] = 24;
SSi_loading = 'ssimage/loading.gif'; // Loading image
SSx_loading = 200;
SSy_loading = 200;
SSi_descOpen = 'ssimage/descopen.png'; // Open Description Box Icon
SSx_descOpen = 40;
SSy_descOpen = 15;
SSi_descClose = 'ssimage/descclose.png'; // Close Description Box Icon
SSx_descClose = 15;
SSy_descClose = 15;
SSi_descLock = 'ssimage/desclock.png'; // Description Box is Locked Open Icon
SSx_descLock = 15;
SSy_descLock = 15;
SSi_descUnlock = 'ssimage/descunlock.png'; // Description Box is Unlocked Icon
SSx_descUnlock = 15;
SSy_descUnlock = 15;
SSi_cookies = 'ssimage/cookies.js'; // Cookies Javascript
SSi_screencss = 'ssimage/slideshow_screen.css'; // CSS file





/******************** No Editable Content Past this point *************************/
// Global variables
var slides_numberOfImages = 0;
var slides_imageLink = new Array();
var slides_imageType = new Array();
var slides_imageTitle = new Array();
var slides_imageChkHeight = new Array();
var slides_imageChkWidth = new Array();
var slides_imageDesc = new Array();
var slides_pageLinks = new Array(); // 0-First Page, 1-Previous Page, 2-Next Page, 3-Last Page
var slides_pageActive = new Array();
for(var i=0;i<4;i++){
	slides_pageActive[i] = false;
}
slides_masterDIV = "slideshow_div";
var slides_size = 0;
var slides_currentImage = 0;
var slides_imageFullSize = false;
var slides_imagePreload;
var slides_imageHeight = 0;
var slides_imageWidth = 0;
var slides_maxHeight = 0;
var slides_maxWidth = 0;
var slides_imageLoaded = false;
var slides_mouseWidth = 0;
var slides_mouseHeight = 0;
var slides_descLock = false;
var slides_descOpen = false;

// InitializeThumbnails function
// Purpose: Adds the proper functions to 'thumb' links and keeps track of all of the
//   thumb links for the slideshow. It also determines if there are 'next', 'first',
//   'last', or 'previous' links and keeps track of them.
// Attributes: none
// Returns: none
function InitializeThumbnails() {
	// clear variables
	slides_numberOfImages = 0;
	for(var i=0;i<4;i++) {
		slides_pageActive[i] = false;
	}
	
	// go through each link
	if( document.getElementsByTagName ) {
		// if a slideshow DIV does not exist, create it
		if( document.getElementById( slides_masterDIV ) == null ) {
			document.getElementsByTagName( "body" )[0].innerHTML += '<div id="' + slides_masterDIV + '"></div>';
		}
		documentLinks = document.getElementsByTagName( "a" );
		for( var nextLink in documentLinks ) {
			// if the link is valid
			if( typeof documentLinks[ nextLink ] != 'undefined' ) {
				var docrelate = documentLinks[ nextLink ].rel;
				var relatedLink = -1;
				switch( docrelate ) {
				case 'thumb':
					// link is a thumb
					//     increase number of images
					slides_numberOfImages++;
					//     add function to link
					documentLinks[ nextLink ].onclick = new Function( "return OpenSlideshow( " + slides_numberOfImages + " );" );
					//     add link to array
					slides_imageLink[ slides_numberOfImages ] = documentLinks[ nextLink ];
					//     get the title of the link
					slides_imageTitle[ slides_numberOfImages ] = documentLinks[ nextLink ].title;
					// Additional information to be pulled about the object
					textToParse = documentLinks[ nextLink ].innerHTML;
					// Pattern to grab a width
					widthParse = /\*\*width:[0-9]+\*\*/im;
					// Pattern to grab a height
					heightParse = /\*\*height:[0-9]+\*\*/im;
					// Pattern to grab a description
					descParse = /\*\*desc:[^*]*\*\*/im;
					typeParse = /\*\*type:[^*]*\*\*/im;
					// get the information
					detectWidth = textToParse.match( widthParse );
					detectHeight = textToParse.match( heightParse );
					detectDesc = textToParse.match( descParse );
					detectType = textToParse.match( typeParse );
					// check and store valid information
					//     get file type of link
					if( detectType != null ) {
						slides_imageType[ slides_numberOfImages ] = GetFileTypeByType( String( detectType ).slice( 7, -2 ) );
					}
					else {
						slides_imageType[ slides_numberOfImages ] = GetFileTypeByExtension( documentLinks[ nextLink ].href );
					}
					if( detectWidth != null ) {
						slides_imageChkWidth[ slides_numberOfImages ] = parseInt(String(detectWidth).slice( 8, -2 ) );
					}
					else {
						slides_imageChkWidth[ slides_numberOfImages ] = 0;
					}
					if( detectHeight != null ) {
						slides_imageChkHeight[ slides_numberOfImages ] = parseInt(String(detectHeight).slice( 9, -2 ) );
					}
					else {
						slides_imageChkHeight[ slides_numberOfImages ] = 0;
					}
					if( detectDesc != null ) {
						slides_imageDesc[ slides_numberOfImages ] = String( detectDesc ).slice( 7, -2 );
					}
					else {
						slides_imageDesc[ slides_numberOfImages ] = '';
					}
					break;
				case 'first':
					relatedLink = 0;
					break;
				case 'previous':
					relatedLink = 1;
					break;
				case 'next':
					relatedLink = 2;
					break;
				case 'last':
					relatedLink = 3;
					break;
				}
				// if link is 'first', 'last', 'previous', or 'next'
				if( relatedLink >= 0 ) {
					//     set associated link as active
					slides_pageActive[ relatedLink ] = true;
					//     add link to page array
					slides_pageLinks[ relatedLink ] = documentLinks[ nextLink ];
				}
			}
		}
		// if there is at least 1 image, and a cookie is set to open the gallery open the slideshow
		if( slides_numberOfImages > 0 && readCookie( 'slides_autoOpen' ) == 'true' ) {
			OpenSlideshow( 1 );
		}
		else {
			// otherwise close the slideshow (it makes sure it's closed)
			CloseSlideshow();
		}
		eraseCookie( 'slides_autoOpen' );
		// set mouse move function
		document.getElementById( slides_masterDIV ).onmousemove = MouseMoveLoc;
		
		// Set up onresize to change code
		slides_oldOnResize = window.onresize;
		if( typeof slides_oldOnResize == "function" ) {
			window.onresize = function() {
				if( slides_oldOnResize ) {
					slides_oldOnResize();
				}
				SetResizeBrowser();
			}
		}
		else {
			window.onresize = SetResizeBrowser;
		}

	}
}

// Non-distructively add the Initialize code to onLoad
slideshowOldEvent = window.onload;
if( typeof slideshowOldEvent == "function" ) {
	window.onload = function() {
		if(slideshowOldEvent) {
			slideshowOldEvent();
		}
		InitializeThumbnails();
	}
}
else {
	window.onload = InitializeThumbnails;
}

// ResizeSlideshow function
// Purpose: Opens or closes the slideshow
// Attributes: timeout value - smaller numbers open and close faster,
//   direction - negative closes the slideshow while positive opens it - larger numbers is faster usually -1 or +1
// Returns: none
function ResizeSlideshow( timeout, direction ) {
	MAX_SIZE = 100;
	MIN_SIZE = 0;
	// change the slideshow size by direction amount
	slides_size += direction;
	// if size is greater than max, than set size to max
	if( slides_size > MAX_SIZE ) {
		slides_size = MAX_SIZE;
	}
	// if size is smaller than min, than set size to min
	if( slides_size < MIN_SIZE ) {
		slides_size = MIN_SIZE;
	}
	
	// set the slideshow to the size calculated
	slides_style = document.getElementById( slides_masterDIV ).style;
	slides_style.height = slides_size + '%';
	slides_style.width = slides_size + '%';

	// if size is greater than min and less than max, than timeout to call this function again
	if( slides_size < MAX_SIZE && slides_size > MIN_SIZE ) {
		setTimeout( 'ResizeSlideshow(' + timeout + ',' + direction + ')', timeout );
	}
	else if( slides_size <= MIN_SIZE ) {
		// Clear HTML once slideshow is closed to stop any animations
		document.getElementById( slides_masterDIV ).innerHTML = '';
	}
	if( direction > 0 ) {
		SetResizeBrowser();
	}
}

// OpenSlideshow function
// Purpose: Opens the slideshow starting at the image number requested
// Attributes: image number
// Returns: false (always returns false to keep the links from actually loading)
function OpenSlideshow( startImage ) {
	var openSpeed = OPEN_CLOSE_SPEED;
	if( openSpeed < 1 ) openSpeed = 1;
	LoadImage( startImage );
	ResizeSlideshow( 10, openSpeed );
	return false;
}

// CloseSlideshow function
// Purpose: Closes the slideshow
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading)
function CloseSlideshow() {
	var closeSpeed = 0 - OPEN_CLOSE_SPEED;
	if( closeSpeed > -1 ) closeSpeed = -1;
	ResizeSlideshow( 5, closeSpeed );
	return false;
}

// ImageNext function
// Purpose: Loads up the next image
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading)
function ImageNext() {
	if( slides_currentImage < slides_numberOfImages ) {
		LoadImage( slides_currentImage + 1 );
	}
	return false;
}

// ImageBack function
// Purpose: Loads up the previous image
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading)
function ImageBack() {
	if( slides_currentImage > 1 ) {
		LoadImage( slides_currentImage - 1 );
	}
	return false;
}

// ImageFirst function
// Purpose: Goes to the first image in the page
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading)
function ImageFirst() {
	LoadImage( 1 );
	return false;
}

// ImageLast function
// Purpose: Goes to the last image in the page
// Attributes: none
// Returns: false (alwys returns false to keep the link from actually loading)
function ImageLast() {
	LoadImage( slides_numberOfImages );
	return false;
}

// PageNext function
// Purpose: Goes to the next page, if a next page link exists
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading)
function Page2() {
	PageLoad( 2 );
	return false;
}

// PageBack function
// Purpose: Goes to the previous page, if a previous page link exists
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading)
function Page1() {
	PageLoad( 1 );
	return false;
}

// PageFirst function
// Purpose: Goes to the first page, if a first page link exists
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading)
function Page0() {
	PageLoad( 0 );
	return false;
}

// PageLast function
// Purpose: Goes to the last page, if a last page link exists
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading)
function Page3() {
	PageLoad( 3 );
	return false;
}

// PageLoad function
// Purpose: Activates the link requested
// Attributes: link to be followed
// Returns: none
function PageLoad( activatePage ) {
	// check to make sure the page to activate is active
	if( slides_pageActive[ activatePage ] ) {
		// set cookie to auto open
		createCookie( 'slides_autoOpen', 'true', 1 );
		// check to see if there is an onclick function, and respond to it if there is
		checkOnClick = slides_pageLinks[ activatePage ].onClick;
		if( typeof checkOnClick == "function" && checkOnClick ) {
			if( checkOnClick() ) {
				location.href = slides_pageLinks[ activatePage ].href;
			}
		}
		else {
			// go to the page
			location.href = slides_pageLinks[ activatePage ].href;
		}
	}
}

// LoadHTML function
// Purpose: Loads the proper HTML onto the page
// Attributes: none
// Returns: none
function LoadHTML() {
	// create blank code variable
	var outHTML = '';
	var backShift = false;
	htmlTitle = ( slides_imageTitle[ slides_currentImage ].length > 0 ? slides_imageTitle[ slides_currentImage ] : slides_imageLink[ slides_currentImage ] );
	
	// start by putting the title in the code variable
	outHTML += '<h1>' + htmlTitle + '</h1>';
	
	// HTML code will depent on image type
	switch( slides_imageType[ slides_currentImage ] ) {
	// for images (type 'image')
	case 'image':
		// if the image is loaded
		if( slides_imageLoaded ) {
			// if image is smaller than max
			if( slides_imageHeight <= slides_maxHeight && slides_imageWidth <= slides_maxWidth ) {
				// add code for close button
				outHTML += '<p id="slides_closeResize"><a href="#" onclick="return CloseSlideshow();">';
				outHTML += '<img src="' + SSi_close + '" style="height:' + SSy_close + 'px;width:' + SSx_close + 'px;" alt="Close Image" /></a></p>';
				// add code for image with position
				outHTML += '<p id="slides_smallImage"><img src="' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href ) + '"';
				outHTML += ' style="height:' + slides_imageHeight + 'px;width:' + slides_imageWidth + 'px;" alt="';
				outHTML += htmlTitle + '" /></p>';
			}
			// else
			else {
				// if fullsize is active
				if( slides_imageFullSize ) {
					// add code for resize and close button
					outHTML += '<p id="slides_closeResize"><a href="#" onclick="return SwitchZoom();">';
					outHTML += '<img src="' + SSi_zoomout + '" style="height:' + SSy_zoomout + 'px;width:' + SSx_zoomout + 'px;" alt="Zoom Out" /></a>';
					outHTML += '<a href="#" onclick="return CloseSlideshow();">';
					outHTML += '<img src="' + SSi_close + '" style="height:' + SSy_close + 'px;width:' + SSx_close + 'px;" alt="Close Image" /></a></p>';
					// add code for image with position
					outHTML += '<p id="slides_largeImagePar"><span id="slides_largeImage" style="display:inline-block;height:';
					outHTML += ( slides_imageHeight > slides_maxHeight ? slides_maxHeight : slides_imageHeight ) + 'px;width:';
					outHTML += ( slides_imageWidth > slides_maxWidth ? slides_maxWidth : slides_imageWidth ) + 'px;';
					outHTML += 'background-image:url(\'' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href ) + '\');">&nbsp;</span></p>';
					// mark for imageshift
					backShift = true;
				}
				// else
				else {
					// add code for resize and close button
					outHTML += '<p id="slides_closeResize"><a href="#" onclick="return SwitchZoom();">';
					outHTML += '<img src="' + SSi_zoomin + '" style="height:' + SSy_zoomin + 'px;width:' + SSx_zoomin + 'px;" alt="Zoom In" /></a>';
					outHTML += '<a href="#" onclick="return CloseSlideshow();">';
					outHTML += '<img src="' + SSi_close + '" style="height:' + SSy_close + 'px;width:' + SSx_close + 'px;" alt="Close Image" /></a></p>';
					// add code for image with position
					resizeRatio = ( slides_maxHeight / slides_imageHeight > slides_maxWidth / slides_imageWidth ? slides_maxWidth / slides_imageWidth : slides_maxHeight / slides_imageHeight );
					resizeHeight = Math.floor( slides_imageHeight * resizeRatio );
					resizeWidth = Math.floor( slides_imageWidth * resizeRatio );
					outHTML += '<p id="slides_largeImageResize"><img src="' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href ) + '"';
					outHTML += ' style="height:' + resizeHeight + 'px;width:' + resizeWidth + 'px;" alt="';
					outHTML += htmlTitle + '" /></p>';
				}
			}
		}
		// else
		else {
			// add code for close button
			outHTML += '<p id="slides_closeResize"><a href="#" onclick="return CloseSlideshow();">';
			outHTML += '<img src="' + SSi_close + '" style="height:' + SSy_close + 'px;width:' + SSx_close + 'px;" alt="Close Image" /></a></p>';
			// add code for loading image with position
			outHTML += '<p id="slides_loadingImage"><img src="' + SSi_loading + '"';
			outHTML += ' style="height:' + SSy_loading + 'px;width:' + SSx_loading + 'px;" alt="';
			outHTML += htmlTitle + '" /></p>';
		}
		break;
		
	case 'flash':
		var flashHeight = 0;
		var flashWidth = 0;
		if( slides_imageWidth > slides_maxWidth || slides_imageHeight > slides_maxHeight ) {
			resizeRatio = ( slides_maxHeight / slides_imageHeight > slides_maxWidth / slides_imageWidth ? slides_maxWidth / slides_imageWidth : slides_maxHeight / slides_imageHeight );
			flashHeight = Math.floor( slides_imageHeight * resizeRatio );
			flashWidth = Math.floor( slides_imageWidth * resizeRatio );
		}
		else {
			flashHeight = slides_imageHeight;
			flashWidth = slides_imageWidth;
		}
		outHTML += '<p id="slides_closeResize"><a href="#" onclick="return CloseSlideshow();">';
		outHTML += '<img src="' + SSi_close + '" style="height:' + SSy_close + 'px;width:' + SSx_close + 'px;" alt="Close Image" /></a></p>';
		outHTML += '<object id="slides_flash" type="application/x-shockwave-flash" data="' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href );
		outHTML += '" width="' + flashWidth + '" height="' + flashHeight + '">';
		outHTML += '<param name="movie" value="' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href ) + '" />';
		outHTML += '<param name="quality" value="high" />';
		outHTML += '<param name="play" value="true" />';
		outHTML += '<param name="loop" value="true" />';
		outHTML += '<param name="wmode" value="window" />';
		outHTML += '<param name="scale" value="showall" />';
		outHTML += '<param name="menu" value="true" />';
		outHTML += '<param name="allowScriptAccess" value="sameDomain" />';
		outHTML += '<p id="slides_downloadFile"><a href="' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href ) + '">';
		outHTML += 'Click here to download this file</a></p>';
		outHTML += '</object>';
		break;
	
	case 'movie_mov':
		var movHeight = 0;
		var movWidth = 0;
		if( slides_imageWidth > slides_maxWidth || slides_imageHeight > slides_maxHeight ) {
			resizeRatio = ( slides_maxHeight / slides_imageHeight > slides_maxWidth / slides_imageWidth ? slides_maxWidth / slides_imageWidth : slides_maxHeight / slides_imageHeight );
			movHeight = Math.floor( slides_imageHeight * resizeRatio );
			movWidth = Math.floor( slides_imageWidth * resizeRatio );
		}
		else {
			movHeight = slides_imageHeight;
			movWidth = slides_imageWidth;
		}
		// Close Button Code
		outHTML += '<p id="slides_closeResize"><a href="#" onclick="return CloseSlideshow();">';
		outHTML += '<img src="' + SSi_close + '" style="height:' + SSy_close + 'px;width:' + SSx_close + 'px;" alt="Close Image" /></a></p>';
		// Movie Code
		outHTML += '<div id="slides_mov">';
		outHTML += '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="';
		outHTML += movHeight + '" width="' + movWidth + '">';
		outHTML += '<param name="src" value="' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href ) + '" />';
		outHTML += '<param name="controller" value="false" />';
		outHTML += '<param name="autoplay" value="true" />';
		outHTML += '<param name="scale" value="tofit" />';
		outHTML += '<object type="video/quicktime" data="' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href );
		outHTML += '" width="' + movWidth + '" height="' + movHeight + '">';
		outHTML += '<param name="src" value="' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href ) + '" />';
		outHTML += '<param name="autoplay" value="true" />';
		outHTML += '<param name="controller" value="false" />';
		outHTML += '<param name="scale" value="tofit" />';
		outHTML += '<p id="slides_downloadFile"><a href="' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href ) + '">';
		outHTML += 'Click here to download this file</a></p>';
		outHTML += '</object></object></div>';
		break;
		
	// for all else
	default:
		// add code for close button
		outHTML += '<p id="slides_closeResize"><a href="#" onclick="return CloseSlideshow();">';
		outHTML += '<img src="' + SSi_close + '" style="height:' + SSy_close + 'px;width:' + SSx_close + 'px;" alt="Close Image" /></a></p>';
		// add code for downloading file
		outHTML += '<p id="slides_downloadFile"><a href="' + GetImageURLByGal( slides_imageLink[ slides_currentImage ].href ) + '">';
		outHTML += 'Click here to download this file</a></p>';
		break;
	}
	checkPosition = Math.floor( ( document.getElementById( slides_masterDIV ).clientHeight - 25 ) / 2 );
	// if image is not the first image
	if( slides_currentImage > 1 ) {
		// add code for back buttons
		outHTML += '<p id="slides_firstback" style="top:' + checkPosition + 'px;"><a href="#" onclick="return ImageFirst();">';
		outHTML += '<img src="' + SSi_first + '" style="height:' + SSy_first + 'px;width:' + SSx_first + 'px;" alt="First Image" /></a>';
		outHTML += '<a href="#" onclick="return ImageBack();">';
		outHTML += '<img src="' + SSi_back + '" style="height:' + SSy_back + 'px;width:' + SSx_back + 'px;" alt="Previous Image" /></a></p>';
	}
	// if image is not the last image
	if( slides_currentImage < slides_numberOfImages ) {
		// add code for forward buttons
		outHTML += '<p id="slides_nextlast" style="top:' + checkPosition + 'px;"><a href="#" onclick="return ImageNext();">';
		outHTML += '<img src="' + SSi_next + '" style="height:' + SSy_next + 'px;width:' + SSx_next + 'px;" alt="Next Image" /></a>';
		outHTML += '<a href="#" onclick="return ImageLast();">';
		outHTML += '<img src="' + SSi_last + '" style="height:' + SSy_last + 'px;width:' + SSx_last + 'px;" alt="Last Image" /></a></p>';
	}
	outHTML += '<p id="slides_pagebuttons">';
	// for each of the 'page' buttons, add code if active
	var outshift = Math.floor( ( document.getElementById( slides_masterDIV ).clientWidth - ( SSx_page[ 0 ] + SSx_page[ 1 ] + SSx_page[ 2 ] + SSx_page[ 3 ] ) ) / 2 );
	for(var i=0;i<4;i++) {
		if( slides_pageActive[ i ] ) {
			outHTML += '<a id="slides_p' + i + '" href="#" onclick="return Page' + i + '();">';
			outHTML += '<img src="' + SSi_page[ i ] + '" style="height:' + SSy_page[ i ] + 'px;width:' + SSx_page[ i ] + 'px;left:' + outshift + 'px" alt="';
			switch(i){
			case 0:
				outHTML += 'first';
				break;
			case 1:
				outHTML += 'previous';
				break;
			case 2:
				outHTML += 'next';
				break;
			case 3:
				outHTML += 'last';
				break;
			}
			outHTML += ' page" /></a>';
		}
		outshift += SSx_page[ i ];
	}
	outHTML += '</p>';
	// add code for the description, if there is one
	textDescription = slides_imageDesc[ slides_currentImage ];
	if( textDescription.length > 0 ) {
		outHTML += '<p id="slides_description' + ( slides_descOpen ? 'Open' + ( slides_descLock ? 'Locked' : 'Unlock' ) : 'Close' );
		outHTML += '" style="left:' + Math.floor( ( document.getElementById( slides_masterDIV ).clientWidth - DESCRIPTION_WIDTH ) / 2 ) + 'px;">';
		if( textDescription.length > DESCRIPTION_CHARS ) {
			outHTML += '<span id="description_short">';
			outHTML += '<a href="#" id="slides_openIcon" onclick="return OpenDescription();">';
			outHTML += '<img src="' + SSi_descOpen + '" alt="Open Description" style="height:' + SSy_descOpen + ';width:' + SSx_descOpen + ';" /></a>';
			lastLocation = textDescription.lastIndexOf(' ', DESCRIPTION_CHARS ); 
			if( lastLocation < 1 ) lastLocation = DESCRIPTION_CHARS;
			outHTML += textDescription.slice( 0, lastLocation ) + '...</span>';
			outHTML += '<span id="description_long">';
			outHTML += '<a href="#" id="slides_closeIcon" onclick="return CloseDescription();">';
			outHTML += '<img src="' + SSi_descClose + '" class="descIcon" alt="Close Description" style="height:' + SSy_descClose + ';width:' + SSx_descClose + ';" /></a>';
			outHTML += '<img src="' + SSi_descLock + '" id="slides_lockIcon" class="descIcon" alt="Description Locked"';
			outHTML += ' style="height:' + SSy_descLock + ';width:' + SSx_descLock + ';" />';
			outHTML += '<a href="#" id="slides_unlockIcon" onclick="return LockDescription();">';
			outHTML += '<img src="' + SSi_descUnlock + '" class="descIcon" alt="Lock Description" style="height:' + SSy_descUnlock + ';width:' + SSx_descUnlock + ';" /></a>';
			outHTML += textDescription + '</span>';
		}
		else {
			outHTML += '<span>' + textDescription + '</span>';
		}
		outHTML += '</p>';
	}
	// add code to div
	document.getElementById( slides_masterDIV ).innerHTML = outHTML;
	// if marked for imageshift, run image shift
	if( backShift ) {
		ImageShift();
	}
}

// LoadImage function
// Purpose: begins the loading of a new image
// Attributes: new image to load
// Returns: none
function LoadImage( imageNum ) {
	// set the current image number
	slides_currentImage = imageNum;
	// reset zoom level if set to be reset on each image
	if( RESET_ZOOM ) slides_imageFullSize = false;
	// close the description box, unless it has been locked open
	if( !( slides_descLock ) ) slides_descOpen = false;

	// code specific to images
	if( slides_imageType[ imageNum ] == 'image' ) {
		if( slides_imageChkHeight[ slides_currentImage ] > 0 && slides_imageChkWidth[ slides_currentImage ] > 0 ) {
			slides_imageHeight = slides_imageChkHeight[ slides_currentImage ];
			slides_imageWidth = slides_imageChkWidth[ slides_currentImage ];
			slides_imageLoaded = true;
		}
		else {
			// set the current image as not loaded
			slides_imageLoaded = false;
			// set the image as a new image
			slides_imagePreload = new Image();
			// set the onload function
			slides_imagePreload.onload = LoadCompleteImage;
			// start loading the image
			slides_imagePreload.src = GetImageURLByGal( slides_imageLink[ imageNum ].href );
		}
	}
	// code specific to flash
	if( slides_imageType[ imageNum ] == 'flash' ) {
		if( slides_imageChkHeight[ slides_currentImage ] > 0 && slides_imageChkWidth[ slides_currentImage ] > 0 ) {
			slides_imageHeight = slides_imageChkHeight[ slides_currentImage ];
			slides_imageWidth = slides_imageChkWidth[ slides_currentImage ];
		}
		else {
			slides_imageHeight = slides_maxHeight;
			slides_imageWidth = slides_maxWidth;
		}
	}
	// code specific to avi movies
	if( slides_imageType[ imageNum ] == 'movie_mov' ) {
		if( slides_imageChkHeight[ slides_currentImage ] > 0 && slides_imageChkWidth[ slides_currentImage ] > 0 ) {
			slides_imageHeight = slides_imageChkHeight[ slides_currentImage ];
			slides_imageWidth = slides_imageChkWidth[ slides_currentImage ];
		}
		else {
			slides_imageHeight = slides_maxHeight;
			slides_imageWidth = slides_maxWidth;
		}
	}

	// load the HTML
	LoadHTML();
	/* This code will determine flash image height and width, if it will work right
	if( slides_imageType[ imageNum ] == 'flash' ) {
		flashOBJ = document.getElementById( 'slides_flash' );
		LoadStartFlash();
	}
	*/
}

// LoadStartFlash function ** This function is not working right **
// Purpose: this function runs once enough flash is loaded to get an image size
// Attributes: none
// Returns: none
function LoadStartFlash() {
	flashOBJ = document.getElementById( 'slides_flash' );
		testHeight = flashOBJ.height;
		testWidth = flashOBJ.width;
		if( slides_imageHeight != testHeight || slides_imageWidth != slides_imageWidth ) {
			slides_imageHeight = testHeight;
			slides_imageWidth = testWidth;
			loadHTML;
		}
}

// LoadCompleteImage function
// Purpose: this function runs when the image has finished loading, setting image sizes
// Attributes: none
// Returns: none
function LoadCompleteImage() {
	slides_imageLoaded = true;
	// if height and width > 0
	if( slides_imagePreload.width > 0 && slides_imagePreload.height > 0 ) {
		// set image height and width
		slides_imageHeight = slides_imagePreload.height;
		slides_imageWidth = slides_imagePreload.width;
		// set the height and width in a variable so it isn't requested again
		slides_imageChkHeight[ slides_currentImage ] = slides_imageHeight;
		slides_imageChkWidth[ slides_currentImage ] = slides_imageWidth;
	}
	// otherwise
	else {
		// change type to unknown
		slides_imageType[ slides_currentImage ] = 'unknown';
	}
	// load html
	LoadHTML();
}

// SetResizeBrowser function
// Purpose: sets the new browser height and width after a resize and reloads the information
// Attributes: none
// Returns: none
function SetResizeBrowser() {
	if( slides_size > 0 ) {
	// Set max height
	slides_maxHeight = Math.floor( document.getElementById( slides_masterDIV ).clientHeight * 0.85 );
	// set max width
	slides_maxWidth = Math.floor( document.getElementById( slides_masterDIV ).clientWidth * 0.9 );
	// reload the html
	LoadHTML();
	}
}

// ImageShift function
// Purpose: sets the location of large full size images
// Attributes: none
// Returns: none
function ImageShift() {
	// set x and y at 0
	var xshift = 0;
	var yshift = 0;
	var shiftRatio = 0.0;
	// if width > max width
	if( slides_imageWidth > slides_maxWidth ) {
		// find shift ratio
		shiftRatio = ( slides_mouseWidth - ( document.getElementById( slides_masterDIV ).clientWidth * 0.2 ) ) / ( document.getElementById( slides_masterDIV ).clientWidth * 0.6 );
		if( shiftRatio > 1 ) shiftRatio = 1;
		if( shiftRatio < 0 ) shiftRatio = 0;
		// calculate shift
		xshift = Math.floor( ( slides_imageWidth - slides_maxWidth ) * shiftRatio );
	}
	// if height > max height
	if( slides_imageHeight > slides_maxHeight ) {
		// find shift ratio
		shiftRatio = ( slides_mouseHeight - ( document.getElementById( slides_masterDIV ).clientHeight * 0.2 ) ) / ( document.getElementById( slides_masterDIV ).clientHeight * 0.6 );
		if( shiftRatio > 1 ) shiftRatio = 1;
		if( shiftRatio < 0 ) shiftRatio = 0;
		// calculate shift
		yshift = Math.floor( ( slides_imageHeight - slides_maxHeight ) * shiftRatio );
	}
	// apply shift
	document.getElementById( 'slides_largeImage' ).style.backgroundPosition = '-' + xshift + 'px -' + yshift + 'px';
}

// MouseMoveLoc function
// Purpose: sets the mouse position when the mouse is moved
// Attributes: mouse event
// Returns: none
function MouseMoveLoc( evnt ) {
	var ev = evnt || window.event; // Needed for IE to work right
	// set mouse positions
	slides_mouseWidth = ev.clientX;
	slides_mouseHeight = ev.clientY;
	// if the proper image exists, call image shift function
	if( document.getElementById( 'slides_largeImage' ) != null ) {
		ImageShift();
	}
}

// GetFileTypeByExtension function
// Purpose: gets known file types
// Attributes: file name
// Returns: file type
function GetFileTypeByExtension( fileName ) {
	var ext = fileName.substr(fileName.lastIndexOf('.') + 1);
	if( ext == 'gif' || ext == 'jpg' || ext == 'jpeg' || ext == 'png' ) {
		return 'image';
	}
	if( ext == 'swf' ) {
		return 'flash';
	}
	if( ext == 'avi' ) {
		return 'movie_avi'; // currently ignored
	}
	if( ext == 'mpg' || ext == 'mpeg' ) {
		return 'movie_mpg'; // currently ignored
	}
	if( ext == 'mov' ) {
		return 'movie_mov';
	}
	return 'unknown';
}

function GetFileTypeByType( type ) {
	if( type == 'image/gif' || type == 'image/jpeg' || type == 'image/png' ) {
		return 'image';
	}
	if( type == 'application/x-shockwave-flash' ) {
		return 'flash';
	}
	return 'unknown';
}

// SwitchZoom function
// Purpose: Changes between fit-to-screen and full-size mode
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading)
function SwitchZoom() {
	slides_imageFullSize = !( slides_imageFullSize );
	LoadHTML();
	return false;
}

// OpenDescription function
// Purpose: Opens the description box
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading)
function OpenDescription() {
	document.getElementById( 'slides_descriptionClose' ).id = 'slides_descriptionOpenUnlock';
	slides_descOpen = true;
	return false;
}

// LockDescription function
// Purpose: Locks the description box open
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading
function LockDescription() {
	document.getElementById( 'slides_descriptionOpenUnlock' ).id = 'slides_descriptionOpenLocked';
	slides_descLock = true;
	return false;
}

// CloseDescription function
// Purpose: Closes the description box, and unlocks it if it was locked
// Attributes: none
// Returns: false (always returns false to keep the link from actually loading
function CloseDescription() {
	document.getElementById( 'slides_descriptionOpen' + ( slides_descLock ? 'Locked' : 'Unlock' ) ).id = 'slides_descriptionClose';
	slides_descLock = false;
	slides_descOpen = false;
	return false;
}

function GetImageURLByGal( checkURL ) {
	qpos = checkURL.lastIndexOf("?");
	spos = checkURL.lastIndexOf("/");
	if( qpos < 0 ) {
		return checkURL;
	}
	else {
		return ( spos < 0 ? '' : checkURL.slice( 0, spos + 1 ) ) + 'images.php' + checkURL.slice( qpos );
	}
}

// Include the cookies javascript file
document.write('<script type="text/javascript" src="' + SSi_cookies + '"></scr' + 'ipt>');
document.write('<link rel="stylesheet" media="screen" href="' + SSi_screencss + '" type="text/css" />');
