	// -----------------------------------------------------------------------------------
	// 
	// This page coded by Scott Upton
	// http://www.uptonic.com | http://www.couloir.org
	//
	// This work is licensed under a Creative Commons License
	// Attribution-ShareAlike 2.0
	// http://creativecommons.org/licenses/by-sa/2.0/
	//
	// Associated API copyright 2002, Travis Beckham (www.squidfingers.com)
	//
	// -----------------------------------------------------------------------------------
	// --- version date: 02/25/05 ------------------------------------------------------
	
	var borderSize = 2;			// = 2x CSS border size
		
	// Create access to 'Detect' object and a place to put instances of 'HTMLobj'
	API = new Detect();
	photoDir = "";
	
	// CREATE INSTANCES & LOAD
	loadAPI = function(){
		// Instantiate HTMLobj
		API.Container		= new HTMLobj('Container');
		API.Photo			= new HTMLobj('Photo');
		//API.LinkContainer	= new HTMLobj('LinkContainer');
		//API.PrevLink		= new HTMLobj('PrevLink');
		//API.NextLink		= new HTMLobj('NextLink');
		//API.PrevTextLink	= new HTMLobj('PrevTextLink');

		//API.NextTextLink	= new HTMLobj('NextTextLink');
		//API.Caption		= new HTMLobj('Caption');
		//API.Counter			= new HTMLobj('Counter');
		
		// Show initial photo
		selectImg(0);
	}
	onload = loadAPI;
	
	// Fade in photo when it is loaded from the server
	initFade = function(){
		// Be certain the tween is complete before fading, too
		var fade_timer = setInterval('startFade()', 1000);
						
		// Fade photo in when ready and clear listener
		startFade = function(){
			if(API.Container._tweenRunning == false){
				clearInterval(fade_timer);
				
				// Be certain fade is done running before allowing next/previous links to work
				// This avoids rapid fade-in when users click next/previous links in quick succession
				var adv_timer = setInterval('permitNextPrev()', 500);
				
				// Permit next/previous links to function normally when fade is completed
				permitNextPrev = function(){
					if(API.Photo._fadeRunning == false){
						clearInterval(adv_timer);
						//API.LinkContainer.displayShow();
						//document.getElementById('NextLink').onclick = nextPhoto;
						//document.getElementById('PrevLink').onclick = prevPhoto;
						//document.getElementById('NextTextLink').onclick = nextPhoto;
						//document.getElementById('PrevTextLink').onclick = prevPhoto;
					} else {
						return;
					}
				}
				
				// Fade photo in
				API.Photo.fadeIn(0,15,33);
			} else {
				return;
			}
		}
	}
	
	// Prevent next/previous
	nullify = function(){
		return false;
	}
	
	// Go to next photo
	nextPhoto = function(){
		// Go to next photo
		if(photoId == (photoArray.length - 1)){
			photoId = 0;
		} else {
			photoId++;
		}
		cyclePhoto(photoId);
	}
	
	// Go to previous photo
	prevPhoto = function(){
		// If at start, go back to end
		if(photoId == 0){
			photoId = photoArray.length - 1;
		} else {
			photoId--;
		}
		cyclePhoto(photoId);
	}
	
	// Function to load subsequent photos in gallery
	cyclePhoto = function(photoId){
		// Hide link container temporarily
		//API.LinkContainer.displayHide();
		
		// Hide photo container temporarily
		API.Photo.hide();
		API.Photo.setOpacity(0);
		
		// Get dimensions of photo
		var wNew = photoArray[photoId][1];
		var hNew = photoArray[photoId][2];
		
		// Start tween on a delay
		var wCur = API.Container.getWidth() - borderSize;
		var hCur = API.Container.getHeight() - borderSize;
		
		// Begin tweening on a short timer
		setTimeout('API.Container.tweenTo(easeInQuad, ['+wCur+', '+hCur+'], ['+wNew+','+hNew+'], 7)',500);
		//setTimeout('API.LinkContainer.tweenTo(easeInQuad, ['+wCur+', '+hCur+'], ['+wNew+','+hNew+'], 7)',500);
		//setTimeout('API.PrevLink.tweenTo(easeInQuad, ['+wCur/2+', '+hCur+'], ['+wNew/2.05+','+hNew+'], 7)',500);
		//setTimeout('API.NextLink.tweenTo(easeInQuad, ['+wCur/2+', '+hCur+'], ['+wNew/2.05+','+hNew+'], 7)',500);
		
		// Get new photo source
		var newPhoto = photoDir + photoArray[photoId][0];
		
		// Set source, width, and height of new photo
		API.Photo.setSrc(newPhoto);		
		API.Photo.sizeTo(wNew,hNew);
		
		// Set caption and photo counter
		//API.Caption.setInnerHtml(photoArray[photoId][3]);
		//API.Counter.setInnerHtml((photoId+1)+' of '+photoNum);
		
		// Set links to new targets based on photoId
		//API.NextLink.setHref("#" + (photoId+1));
		//API.PrevLink.setHref("#" + (photoId+1));
		//API.NextTextLink.setHref("#" + (photoId+1));
		//API.PrevTextLink.setHref("#" + (photoId+1));
		
		// Event listeners for onload and onclick events
		document.getElementById('Photo').onload = initFade;
		//document.getElementById('NextLink').onclick = nullify;
		//document.getElementById('PrevLink').onclick = nullify;
		//document.getElementById('NextTextLink').onclick = nullify;
		//document.getElementById('PrevTextLink').onclick = nullify;
	}

