function changeGalleryImage(imagesrc,filename,width,height,number){
	document.getElementById('displayImage').src = imagesrc;
	document.getElementById('thumbnailViewer').style.height = height+'px';
	pieces = imagesrc.split('/');
	document.getElementById('currentPhotoName').innerHTML = document.getElementById('display'+number).innerHTML;
	document.getElementById('pageUrl').innerHTML = escape(siteBaseUrl+'news.php?newsid='+newsid+'&pn='+number);
}
function changePicture(direction,count){
	filename = document.getElementById('displayImage').src;
	while ( filename.indexOf("/") != -1 ) {
		filename = filename.substring(1,filename.length);
	}
	// Locate this photo in the array
	for (var i = 1; i <= count; i++) {
		pieces = document.getElementById('photoLink'+i).href.split("'");

		if ( pieces[3] == filename ) {
			// Found the image
			if ( direction == -1 ) {
				if ( i == 1 ) {
					piecesNew = document.getElementById('photoLink'+(count)).href.split("'");
				}else{
					piecesNew = document.getElementById('photoLink'+(i-1)).href.split("'");
				}
			} else if ( direction == 0 ) {
				piecesNew = document.getElementById('photoLink'+i).href.split("'");
			}else{
				if ( i == count ) {
					piecesNew = document.getElementById('photoLink1').href.split("'");
				}else{
					piecesNew = document.getElementById('photoLink'+(i+1)).href.split("'");
				}
			}
			changeGalleryImage(piecesNew[1],piecesNew[3],piecesNew[5],piecesNew[7],piecesNew[9],piecesNew[11],piecesNew[13],piecesNew[15]);
			break;
		}
	}
}
//
// These four functions below are a lot of just to ensure that the page loads
// with a full photo description on startup
//
function displayFirst() {
	schedule('currentPhotoName', 'displaySecond()');
}
function displaySecond() {
	schedule('display1', 'displayThird()');
}
function displayThird() {
	document.getElementById('currentPhotoName').innerHTML = 
		document.getElementById('display1').innerHTML;
}
function schedule(objectID, functionCall)
{
	if (document.getElementById(objectID))
	{
		eval(functionCall);
	}
	else
	{
		setTimeout("schedule('" + objectID + "', '" + functionCall + "')", 1);
	}
	
	return true;
}
document.onload = displayFirst();

