
//-----------------------General function for all galleries. 

function generalReplacePicts (iDirection, aPhoto, aCapt, aCred, sPhotoID, sCaptID, sSeqID, sCredID) {
	
	var iMaxPicIndex = (aPhoto.length - 2);	//  For readability. Max index of pictures.
	var iCurrPhoto = aPhoto[(iMaxPicIndex + 1)]; // For readability. 
								//Index of variable for current photo to be displayed.
	
	
	iCurrPhoto += iDirection;	// iDirection == 1 if forward button is clicked.
								// iDirection == -1 if backward button is clicked.
								
	if (iCurrPhoto == (aPhoto.length - 1)) 		// More than the max array value so cycle back to zero.
		iCurrPhoto = 0;
		
	if (iCurrPhoto < 0) 			// Less than the minimum value, cycle around to the end.
		iCurrPhoto = iMaxPicIndex;
		
	 							// Now iCurrPhoto contains the correct value for the photo array.
	 							
	aPhoto[(aPhoto.length)-1] = iCurrPhoto;	// Places proper value in array.
	
	var photoElem = document.getElementById(sPhotoID.toString()); // Get picture element
	photoElem.src = aPhoto[iCurrPhoto];							// Replace picture
		
	var captElem = document.getElementById(sCaptID.toString()); // Get caption element
	captElem.firstChild.nodeValue = aCapt[iCurrPhoto];	// Replace caption
	
	var seqElem = document.getElementById(sSeqID.toString()); // Get sequence number element
	var seqText = (iCurrPhoto+1).toString() + ' of ' + (iMaxPicIndex+1).toString();	// Make text string
	seqElem.firstChild.nodeValue = seqText;	// Replace sequence text
	
	var credElem = document.getElementById(sCredID.toString()); // Get photo credit element
	credElem.firstChild.nodeValue = aCred[iCurrPhoto];	// Replace photo credit
	
}
