	var photoDir = "images/brutalism/";	// Location of photos for gallery
	var borderSize = 2;			// = 2x CSS border size
	
	// get current photo id from URL
	var thisURL = document.location.href;
	var splitURL = thisURL.split("#");
	var photoId = splitURL[1] - 1;
	
	// if no id in query string then set i=1
	photoId = (!photoId)? 0:photoId;
		
	// Define each photo's name, height, width, and caption
	var photoArray = new Array(
		// Source, Width, Height, Caption
		new Array("AltonWestEstate.jpg", "500", "400", '<span id="title">Alton West Estate</span><br />Roehampton, Greater London<br />LCC Architects Department, 1954-58'),
		new Array("barbican.jpg", "320", "400", '<span id="title">Barbican</span><br />City, London<br />Chamberlin, Powell &amp; Bon, 1963'),
		new Array("GatesheadCarPark01.jpg", "500", "400", '<span id="title">Multi Storey Car Park</span><br />Trinity Square, Gateshead<br />Owen Luder, 1964-69'),
		new Array("GatesheadCarPark02.jpg", "320", "400", '<span id="title">Multi Storey Car Park</span><br />Trinity Square, Gateshead<br />Owen Luder, 1964-69'),
		new Array("GatesheadCarPark03.jpg", "500", "400", '<span id="title">Multi Storey Car Park</span><br />Trinity Square, Gateshead<br />Owen Luder, 1964-69'),
		new Array("HaywardGallery01.jpg", "320", "400", '<span id="title">Hayward Gallery</span><br />South Bank, London<br />Department of Architecture &amp; Civic Design, GLC, 1968'),	
		new Array("HaywardGallery02.jpg", "320", "400", '<span id="title">Hayward Gallery</span><br />South Bank, London<br />Department of Architecture &amp; Civic Design, GLC, 1968'),
		new Array("RobinHoodEstate.jpg", "500", "400", '<span id="title">Robin Hood Gardens</span><br />Poplar, London<br />Alison &amp; Peter Smithson, 1966-72'),		
		new Array("smithdonSchool01.jpg", "500", "400", '<span id="title">Smithdon School</span><br />Hunstanton, Norfolk<br />Alison &amp; Peter Smithson, 1954'),	
		new Array("smithdonSchool02.jpg", "320", "400", '<span id="title">Smithdon School</span><br />Hunstanton, Norfolk<br />Alison &amp; Peter Smithson, 1954'),	
		new Array("trellickTower.jpg", "320", "400", '<span id="title">Trellick Tower</span><br />Westbourne Grove, London<br />Erno Goldfinger, 1968-72'),
		new Array("Tricorn01.jpg", "320", "400", '<span id="title">The Tricorn Centre</span><br />Portsmouth, Hants<br />Owen Luder, 1966'),
		new Array("Tricorn02.jpg", "500", "400", '<span id="title">The Tricorn Centre</span><br />Portsmouth, Hants<br />Owen Luder, 1966'),
		new Array("Tricorn03.jpg", "320", "400", '<span id="title">The Tricorn Centre</span><br />Portsmouth, Hants<br />Owen Luder, 1966'),
		new Array("Tricorn04.jpg", "500", "400", '<span id="title">The Tricorn Centre</span><br />Portsmouth, Hants<br />Owen Luder, 1966')
		
		);
	
	// Number of photos in this gallery
	var photoNum = photoArray.length;
	
	// Create access to 'Detect' object and a place to put instances of 'HTMLobj'
	API = new Detect();
	
	// 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
		cyclePhoto(photoId);
	}
	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;
	}
