WAFPhotoGallery = {
	
	galleryElemID: 'photogallery',
	galleryElem: null,
	
	displayFrameID: 'imagedisplay',
	displayFrameElem: null,
	
	photos: null,
	photoSelectedClassName: 'selected',
	
	imageNameAppended: '-tn',
		
	init: function() {
		var galleryElem = document.getElementById(WAFPhotoGallery.galleryElemID);
		var frameElem = document.getElementById(WAFPhotoGallery.displayFrameID);
		
		if (galleryElem != null && frameElem != null) {
			WAFPhotoGallery.galleryElem = galleryElem;
			WAFPhotoGallery.displayFrameElem = frameElem;
			
			var photos = galleryElem.getElementsByTagName('img');
			WAFPhotoGallery.photos = photos;
			var firstPhoto = photos[0];
			for (var i=0; i < photos.length; i++) {
				photos[i].onclick = function() { WAFPhotoGallery.showPhoto(this); }
			};
			WAFPhotoGallery.showPhoto(firstPhoto);
		}
	},
	
	showPhoto: function(elem) {
		WAFPhotoGallery.highlightThumb(elem);
		var frame = WAFPhotoGallery.displayFrameElem;
		var srcImg = elem.src.replace(WAFPhotoGallery.imageNameAppended, '');
		frame.style.backgroundImage = 'url(' + srcImg + ')';
	},
	
	highlightThumb: function(elem) {
		// clear current highlight
		var photos = WAFPhotoGallery.photos;
		for (var i=0; i < photos.length; i++) {
			photos[i].className = photos[i].className.replace(WAFPhotoGallery.photoSelectedClassName, '');
		};
		
		elem.className += ' ' + WAFPhotoGallery.photoSelectedClassName;	
	}
	
}
addLoadEvent(WAFPhotoGallery.init);