function showLarge(galleryIdx, imageIdx) {
	document["largeImage"].src = "mediaServer.php?fileType=image&galleryIdx=" + galleryIdx + "&itemIdx=" + imageIdx;
		
	thumbImage = document.getElementById("thumbImage" + currentDisplay);
	thumbImage.className = 'thumbunSelected';

	thumbImage = document.getElementById("thumbImage" + imageIdx);
	thumbImage.className = 'thumbSelected';
	
	//if the thumb is adult and user not logged in, then put up join button
	joverlay = document.getElementById("joinOverlay");
	if(thumbImage.src.substr(thumbImage.src.length - 7) == 'adult=1' && !loggedIn) {
		joverlay.className = 'joinOverlay';
	}
	else {
		joverlay.className = 'hidden';
	}
	
	
	currentDisplay = imageIdx;
	for (i=1;i<imageList.length;i++) {
		if (imageList[i] == imageIdx) {
			slideShowIdx = i;
			break;
		}
	}
	// scroll to next page of thumbs if picked image is off screen
	if (slideShowIdx / 3 > rowOffset + rowsPerPage) {
		nextThumbs();
	}
	//if image is first image and off screen above, scroll to beginning
	if (slideShowIdx == 1 && thumbOffset < 0) {
		prevThumbs(false);	
	}
}

function advanceOneSlide() {
	if (slideShowIdx == imageList.length - 1) {
		slideShowIdx = 0;
	}
	showLarge(galleryIdx, imageList[slideShowIdx + 1]);
	if (slideShowRunning) {
		slideShowTimer = setTimeout("advanceOneSlide()", slideShowDelay);
	}			
}

function slideShowToggle() {
	if (slideShowRunning == false) {
		//start slide show
		slideShowTimer = setTimeout("advanceOneSlide()", slideShowDelay);
		slideShowRunning = true;
		slideshowActive = false;
		document['slideshowButton'].src = 'images/gallery_slideshow_on.gif';
		
	}
	else {
		//turn it off
		clearTimeout(slideShowTimer);
		slideShowRunning = false;
		slideshowActive = true;
		document['slideshowButton'].src = 'images/gallery_slideshow_off.gif';
	}	
}

function buttonState(buttonName, buttonStatus) {
	if (eval(buttonName + 'Active')) {
		if (buttonStatus == 'over') {
			document[buttonName + 'Button'].src = 'images/gallery_' + buttonName + '_on.gif';
		}
		else if (buttonStatus == 'out') {
			document[buttonName + 'Button'].src = 'images/gallery_' + buttonName + '_off.gif';
		}
			
	}		
}

function nextThumbs() {
	if (rowOffset + rowsPerPage < totalRows) {
		thumbOffset = thumbOffset - 657;
		prevActive = true;
		document['prevButton'].src = 'images/gallery_prev_off.gif';
		rowOffset = rowOffset + rowsPerPage;
		setTimeout("animateSlide()", 100);
		if (rowOffset + rowsPerPage > totalRows) {
			nextActive = false;
			document['nextButton'].src = 'images/gallery_next_disabled.gif';
		}
	}
}

function prevThumbs(singlePage) {
	if (thumbOffset < 0) {
		nextActive = true;
		document['nextButton'].src = 'images/gallery_next_off.gif';
		if (singlePage) {
			thumbOffset = thumbOffset + 657;
			rowOffset = rowOffset - rowsPerPage;
		}
		else {
			thumbOffset = 0;
			rowOffset = 0;
		}
		setTimeout("animateSlide()", 100);
		if (thumbOffset >= 0) {
			prevActive = false;
			document['prevButton'].src = 'images/gallery_prev_disabled.gif';
		}
	}
}

function animateSlide() {
	moveStep = 75;
	smallStep = 9;
	galleryDiv = document.getElementById('galleryThumbs');

	if (thumbActual != thumbOffset) {
	 	if (Math.abs(thumbActual - thumbOffset) < moveStep) {
	 		moveStep = smallStep;	
	 	}
	 	if (Math.abs(thumbActual - thumbOffset) <= smallStep) {
	 		thumbActual = thumbOffset;	
	 	}
	 	if (thumbActual > thumbOffset) {
	 		thumbActual = thumbActual - moveStep;
	 	}
	 	else if (thumbActual < thumbOffset) {
	 		thumbActual = thumbActual + moveStep;
	 	}
	 	
		galleryDiv.style.top = thumbActual + 'px';	 			
		setTimeout("animateSlide()", 100);
	}
}


function newThumbs(originalRequest) {
	thumbsDiv = document.getElementById('galleryThumbs');
	thumbsDiv.innerHTML = originalRequest.responseText;
}
