function photoSlideshow(varName, maxWidth, maxHeight, photoElemId, photoLinkId, imageArray, titleId, subTitleId) {

this.photoSlideshowVarName = varName;
this.PHOTO_MAX_WIDTH = maxWidth;
this.PHOTO_MAX_HEIGHT = maxHeight;
this.photoElemId = photoElemId;
this.photoLinkId = photoLinkId;
this.photoTitleId = titleId;
this.photoSubTitleId = subTitleId;
this.imageArray = imageArray;


// TODO: Do we need to pass in the variable name that instantiates this
//		object so that we can call it in setTimeout????

this.curImageIndex = 0;
this.lastImageIndex = -1;
this.slideShowId = -1;

// Maybe I should define all the various panel name vars here 
//	and then I can override if necessary? 

this.opacity = function(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout(this.photoSlideshowVarName + ".changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout(this.photoSlideshowVarName + ".changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
};

// change the opacity for different browsers 
this.changeOpac = function(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";

//	 If we're at full opacity, just remove filter 
//	 since it can cause ugly outline of text in IE.

	if (opacity == 100) {
		object.filter = '';
	}
}; 

this.switchImage = function(imgIndex) {
	this.lastImageIndex = this.curImageIndex;
	this.curImageIndex = imgIndex;

	var photoId = this.imageArray[imgIndex][0];
	var photoTitle = this.imageArray[imgIndex][1];
	var photoLoc = this.imageArray[imgIndex][2];
	var photoThumbLoc = this.imageArray[imgIndex][3];
	var photoLinkUrl = this.imageArray[imgIndex][4];
	var photoCredits = this.imageArray[imgIndex][5];
	var width = this.imageArray[imgIndex][6];	
	var height = this.imageArray[imgIndex][7];
	var thumbWidth = this.imageArray[imgIndex][8];	
	var thumbHeight = this.imageArray[imgIndex][9];
	var numVotes = this.imageArray[imgIndex][10];
	var domain = this.imageArray[imgIndex][11];
	var hasVoted = this.imageArray[imgIndex][12];
	var subTitle = this.imageArray[imgIndex][13];

	if (width > this.PHOTO_MAX_WIDTH) {
		height = height * (this.PHOTO_MAX_WIDTH / width);
		width = this.PHOTO_MAX_WIDTH;
	}

	if (height > this.PHOTO_MAX_HEIGHT) {
		width = width * (this.PHOTO_MAX_HEIGHT / height);
		height = this.PHOTO_MAX_HEIGHT;

	}
	
	width = this.PHOTO_MAX_WIDTH;
	height = this.PHOTO_MAX_HEIGHT;

	width = Math.floor(width);
	height = Math.floor(height);
    var imgElem = document.getElementById(this.photoElemId);
	if ((imgElem) && (imgElem.src)) {
		imgElem.src = photoLoc;
		imgElem.style.width = width + 'px';
		imgElem.style.height = height + 'px';
	}

	if (this.photoLinkId) {
	    var linkElem = document.getElementById(this.photoLinkId);
		if ((linkElem) && (linkElem.href)) {
			linkElem.href = photoLinkUrl;
		}
	}

	if (this.photoTitleId) {
	    var elem = document.getElementById(this.photoTitleId);
		if (elem) {
			elem.innerHTML = photoTitle;
		}
	}

	if (this.photoSubTitleId) {
	    var elem = document.getElementById(this.photoSubTitleId);
		if (elem) {
			elem.innerHTML = subTitle;
		}
	}

    setTimeout(this.photoSlideshowVarName + ".opacity('" + photoElemId +  "',0, 100, 500)", 100); 
};

this.switchImageFade = function(imgIndex, stop) {
	this.stopSlideShow();
	this.opacity(this.photoElemId, 100, 0, 500);
	setTimeout(this.photoSlideshowVarName + ".switchImage(" + imgIndex + ")", 600);
	if (!stop) {
		this.startSlideShow();
	}
};

this.nextImage = function(stop) {
	var tempIndex = this.curImageIndex+1;
	if (tempIndex >= this.imageArray.length) {
		tempIndex = 0;
	}
	this.switchImageFade(tempIndex, stop);
};

this.prevImage = function(stop) {
	var tempIndex = this.curImageIndex-1;
	if (tempIndex < 0) {
		tempIndex =  this.imageArray.length - 1;
	}
	this.switchImageFade(tempIndex, stop);
};

this.startSlideShow = function() {
	this.slideShowId = setInterval(this.photoSlideshowVarName + ".nextImage(false);", 7000);
	
// TODO: We should toggle play/pause button	
//		var playElem = document.getElementById('play_link');
//		playElem.style.display = 'none';
//		var pauseElem = document.getElementById('pause_link');
//		pauseElem.style.display = 'inline';
};

this.stopSlideShow = function() {
	clearInterval(this.slideShowId);
	this.slideShowId = -1;
// TODO: We should toggle play/pause button	
//		var playElem = document.getElementById('play_link');
//		playElem.style.display = 'inline';
//		var pauseElem = document.getElementById('pause_link');
//		pauseElem.style.display = 'none';
};

}
