//<script>


		//hash management
		var validHashes = [];
			
		function findHash(el) {
			forEachTagBelow(el, 'A', recordHash);
		}
		function recordHash(el) {
			var hash;
			if (el.href) {
				hash = extractHash(el.href);
				if (hash) {
					validHashes.push({
							'hash': hash,
							'li': el.parentNode
							});
				}
			}
		}
		function extractHash(href) {
			var h = href.lastIndexOf('#');
			if (h>=0) {
				return href.substr(h);
			}
			return '';
		}
			
		//imagelist selection
			
		function syncImageWithHash() {
			var hash = window.location.hash;
			if (!hash && validHashes.length) {
				hash = validHashes[0].hash;
			}
			selectImage(hash);
		}
			
		function imageListClick(e) {
			e = e || window.event;
			var hash;
				
			if (e) {
				var el = e.srcElement || e.target;
				if (el && el.href) {
					hash = extractHash(el.href);
					if (hash) {
						selectImage(hash);
						if (ss) {
							ss.delayNextSlide();
						}
						return true;
					}
				}
			}
			return true;
		}
		

		
		function selectNextImage(onceonly) {
			for (var i=0; i<validHashes.length; i++) {
				if (hasClassName(validHashes[i].li, 'current')>=0) {
					removeClassName(validHashes[i].li, 'current');
					if (i === validHashes.length-1) {
						if (!onceonly) {
							window.location.replace(window.location.pathname + validHashes[0].hash);
							return false;
						}
						return true;
					} else {
						window.location.replace(window.location.pathname + validHashes[i+1].hash);
						return false;
					}
				}
			}
		}
		function selectPrevImage(onceonly) {
			for (var i=0; i<validHashes.length; i++) {
				if (hasClassName(validHashes[i].li, 'current')>=0) {
					removeClassName(validHashes[i].li, 'current');
					if (i === 0) {
						if (!onceonly) {
							window.location.replace(window.location.pathname + validHashes[validHashes.length-1].hash);
							return false;
						}
						return true;
					} else {
						window.location.replace(window.location.pathname + validHashes[i-1].hash);
						return false;
					}
				}
			}
		}
		
		function selectImage(hash) {
			var foundHash, isThisHash;
			foundHash = false;
			for (var i=0; i<validHashes.length; i++) {
				isThisHash = (validHashes[i].hash === hash);
				foundHash = foundHash || isThisHash;
				toggleClassName(validHashes[i].li, 'current', isThisHash);
			}
			if (!foundHash && validHashes.length) {
				toggleClassName(validHashes[0].li, 'current', true);
			}
		}
		
		//link credits to search engine
		
		function getSearchLink(searchType, searchTitle, searchText, displayText) {
			return '<a href="http://project.millerhare.com/public/search.asp?t=' + searchType + 
							'&amp;s=' + escape(searchText) + 
							'" title = "' + searchTitle.replace(/"/, "'") + 
							'">' + displayText + '</a>';
		}
		
		function copyDTdetailsToDD(el) {
			var c, elText;
			var searchType = 'o';
			var searchTitle = 'find more images linked to ';
			
			if (el && el.hasChildNodes) {
				c = el.childNodes;
				for (var i=0; i<c.length; i++) {
					elText = c[i].innerHTML;
					if (elText) {
						switch(c[i].tagName) {
							case 'DT':
								switch(elText.replace(/\s+/, '').toLowerCase()) {
									case 'architect':
									case 'architects':
									case 'designer':
										searchType = 'a';
										searchTitle = 'find more buildings by ';
										break;
										
									case 'client':
										searchType = 'c';
										searchTitle = 'find more images for ';
										break;
										
										
									default:
										searchType = 'o';
										searchTitle = 'find more images linked to ';
								}
								break;
							case 'DD':
								if (searchType && hasClassName(c[i], 'dontlink')<0) {
									c[i].innerHTML = getSearchLink(searchType, searchTitle + elText, elText, elText);
								}
								break;
						}
					}
				}
			}
		}
		
		function linkJob(el) {
			var elText, jobcode;
			if (el && hasClassName(el, 'dontlink')<0) {
				elText = el.innerHTML;
				jobcode = el.getAttribute('name');
				if (jobcode && parseInt(jobcode, 10)) {
					el.innerHTML = getSearchLink('j', 'more images from this project', jobcode, elText);
				}
			}
		}
		
		//menu handlers
		
		var mhl_menu = {
			el: null,
			timer: null	
		};
	
		function resetMenuTimer() {
			if (mhl_menu.timer) {
				window.clearTimeout(mhl_menu.timer);
				mhl_menu.timer = null;
			}
		}
		
		function showMenu(el) {
			hideMenu();
			
			addClassName(el, 'menushown');
			mhl_menu.timer = window.setTimeout(hideMenu, 4000);
			
			mhl_menu.el = el;
		}
		
		function delayedHideMenu(el) {
			if (mhl_menu.el) {
				resetMenuTimer();
				mhl_menu.timer = window.setTimeout(hideMenu, 300);
			}
		}
		
		function hideMenu() {
			resetMenuTimer();
			if (mhl_menu.el) {
				removeClassName(mhl_menu.el, 'menushown');			
			}
			mhl_menu.el = null;
		}
		
		
		//insert event handlers
			
		function alterImageDisplay() {
			var el, li;
				
			el = myGetElementById('imagelist');
			if (el) {
				el.onclick = imageListClick;
				forEachTagBelow(el, 'LI', findHash);
			}
			el = myGetElementById('exampleimages');
			if (el) {
				if (!validHashes.length || !window.opera) {
					//opera cannot scroll a div with overflow: hidden;
					addClassName(el, 'noscroll');
				}
				el.onscroll = syncImageWithHash;
			}
			syncImageWithHash();
			//window.onfocus=syncImageWithHash;
		}
		
		function linkCredits(el) {
			if (el) {
				switch (el.tagName) {
					case 'DIV':
						forEachTagBelow(el, 'H4', linkJob);
						forEachTagBelow(el, 'DL', linkCredits);
						break;
						
					case 'DL':
						copyDTdetailsToDD(el);
						break;
				}
			} else {
				el = myGetElementById('exampleimages');
				if (el) {
					forEachTagBelow(el, 'DIV', linkCredits);
				}
			}
		}
		
		function enhanceMenus(el) {
			
			if (el) {
				switch (el.tagName) {
					case 'UL':
						forEachTagBelow(el, 'LI', enhanceMenus);
						break;
						
					case 'LI':
						el.onmouseover = function() {
							showMenu(el);
						};
						el.onmouseout = function() {
							delayedHideMenu(el);
						}
						
						break;
				}
			} else {
				el = myGetElementById('navigation');
				if (el) {
					forEachTagBelow(el, 'UL', enhanceMenus);
				}
			}
		}
