

function gallery(path, supersizePath, fileExt) {
	this.galleryPhotos = [];
	this.currentPosition = 1;
	this.path = path;
	this.supersizePath = supersizePath;
	this.fileExt = fileExt;
	this.galleryPhoto = GAL_galleryPhoto;
	this.addPhoto = GAL_addPhoto;
	this.showPhoto = GAL_showPhoto;
	this.showPreviousPhoto = GAL_showPreviousPhoto;
	this.showNextPhoto = GAL_showNextPhoto;
}

function GAL_galleryPhoto(photoID, photoWidth, photoHeight, photoCaption) {
    this.photoID = photoID;
    this.photoWidth = photoWidth;
    this.photoHeight = photoHeight;
    this.photoCaption = photoCaption
}

function GAL_addPhoto(photoID, photoWidth, photoHeight, photoCaption) {
    this.galleryPhotos.push(new this.galleryPhoto(photoID, photoWidth, photoHeight, photoCaption))
}

function GAL_showPhoto(photoPosition) {
    this.currentPosition = photoPosition;
    if (photo = document.getElementById('mainPhoto')) {
		if(largerLink = document.getElementById('supersizeLink')){
        gPhoto = this.galleryPhotos[photoPosition - 1];
        photo.src = this.path + gPhoto.photoID + this.fileExt;
        photo.width = gPhoto.photoWidth;
        photo.height = gPhoto.photoHeight;
		larger = this.supersizePath + gPhoto.photoID + this.fileExt; 
		largerLink.href = larger;
        if (photoCaptionTag = document.getElementById('caption')) {
               photoCaptionTag.firstChild.nodeValue = gPhoto.photoCaption;
		}
		if(supersizeCaptionLink = document.getElementById('supersizeLinkCaption')){
				supersizeCaptionLink.href = larger;
		}
        if (photoPositionTag = document.getElementById('photoPosition')) {
            photoPositionTag.firstChild.nodeValue = photoPosition
        }
        if (photoTop = document.getElementById('largePhoto')) {
            photoTop.focus()
        }
        return false
    } else {
        return true
    }
	}
}
function GAL_showNextPhoto() {
    var newPosition;
    if (this.currentPosition == this.galleryPhotos.length) {
        newPosition = 1
    } else {
        newPosition = this.currentPosition + 1
    }
    return showPhoto(newPosition)
}
function GAL_showPreviousPhoto() {
    var newPosition;
    if (this.currentPosition == 1) {
        newPosition = this.galleryPhotos.length
    } else {
        newPosition = this.currentPosition - 1
    }
    return showPhoto(newPosition)
}
