	if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}

// setHighlight -- set thumbnail border to yellow (selected) or white (not selected)
function setHighlight(thumbnail,status) {	
	if ( status == "out" ) {
		document.getElementById(thumbnail).className = 'thumb gal noborder';
		}
	if ( status == "on" ) {
		document.getElementById(thumbnail).className = 'thumb highlight';
	} 
	if ( status == "off" ) {
		document.getElementById(thumbnail).className = 'thumb border';
	}
}

// setFileName -- gets filename based on images array
function setFileName(index) {
		if ( index <0 ) {
				imgName = navDir + "/start.png";
					} 
		else if (index >= images.length ) {
				imgName = navDir + "/end.png";
				if(index==images.length+1) {imgName = navDir + "/blank.gif";}
		} else if ((index >0) || (index <= images.length) ) {
			//document.getElementById('control-output').alt=index+1;
				imgName = thumbDir+"/"+images[index]+'.jpg';
		}
	return imgName;
}

// updateThumbnails -- update thumbnails based on user selection
function updateThumbnails(centerImage) {
	for ( count = 1; count <= numOfThumbs; count++ ) {
		thumbIndex = centerImage + count - center;
		imgName = setFileName(thumbIndex);
		document.getElementById(count).src = imgName;
		if (centerImage==0) {
		setHighlight(1,"out");
		} 
		else if (centerImage==1&&thumbIndex==2) {setHighlight(1,"off");}
		if ((centerImage==images.length-1)) {
			setHighlight(3,"out");
		} 
		else {
			if (thumbIndex == currentImage) {
			setHighlight(count,"on");
			} else {
			setHighlight(count,"off");
			}	
		}
		if (centerImage==images.length-1) {
			setHighlight(1,"off");
			setHighlight(2,"on");
			setHighlight(3,"out");
			setHighlight(4,"out");
			}
		if (centerImage==images.length-2) {
			setHighlight(4,"out");
		}
	}
}


// updateMainImg -- update main image
function updateMainImg(index) {
	if ( imageDir != "" && imageDir.charAt(imageDir.length - 1) != "/" ) { imageDir = imageDir + "/" }
	document.getElementById("main").src=imageDir + images[index] + '.jpg';
	return current=images[index];
}
		
// focusImg -- changes featured (main) image based on selected thumbnail
function focusImg(source) {
	var imageInArray = false;
	var mainImage = document.getElementById(source).src;
	for ( count = 0; count < images.length; count++ ) {
		if(images[count]==mainImage.slice(mainImage.lastIndexOf('/')+1,mainImage.lastIndexOf('.'))) {
			currentImage = count;
			updateMainImg(currentImage);
			imageInArray = true;
		}
	}
	if ( imageInArray == true) {
		updateThumbnails(currentImage);
	}
}

// moveImg -- advances thumbnails by [n] units
// Used by viewer.html
function moveImg(amount) {
	//The center thumbnail image should always be part of the images array
	var string = document.getElementById(center).src;
	for ( count = 0; count < images.length; count++ ) {
		if(images[count]==string.slice(string.lastIndexOf('/')+1,string.lastIndexOf('.'))) {
			middleThumb = count;
			break;
		}
	}
	//What if I hit rewind (e.g. -5) and I'm on item 2?
	if ( middleThumb + amount < 0 ) {
		amount = 0 - middleThumb
	}
	if ( middleThumb + amount >= images.length ) {
		amount = (images.length - 1) - middleThumb
	}
	if ( middleThumb + amount >= 0 && middleThumb + amount < images.length ) {
		updateThumbnails(middleThumb + amount);
	}
	var str=document.getElementById(4).src;
	if(str.slice(str.lastIndexOf('/')+1,str.lastIndexOf('.'))=='blank') {
		setHighlight(4,"out");
	}
}


// initViewer -- displays navigation thumbnails
// Used by viewer.html
function initViewer() {
	updateMainImg(currentImage);
	updateThumbnails(currentImage);
}

xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
	if(!e){e='';}
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function Gallery(type,ID,photos,current) {
	document.getElementById('gallery').style.top=yMousePos+'px';
	document.getElementById('gallery').style.display='block';
	currentImage=images.indexOf(current);
	initViewer();
}

function closeGallery() {
	document.getElementById('gallery').style.display='none';
}

function keyPressHandler(ev) {
ev=ev||event;

if(document.getElementById('gallery'))

{
if(ev.keyCode==27){
closeGallery();
return false
}
}

}
document.onkeypress=keyPressHandler
