var speed = 0;
var imageTexts = new Array();
var initialized = false;

function showImage(imageSrc, index) {
	var image = document.getElementById('selected_image');
	var imageText = document.getElementById('image_text');
	image.src = imageSrc;
	imageText.innerHTML = imageTexts[index];
}

function fadeThumbNail() {
		this.style.opacity = 0.8;
		this.style.filter = 'alpha(opacity=80)';
}

function restoreThumbNail() {
		this.style.opacity = 1;
		this.style.filter = 'alpha(opacity=100)';
}

function moveUp() {	
	speed=9;
}
 
function moveDown(event) {
	speed=-9;
}

function stop() {		
	speed = 0;
}
	
function moveThumbNails() {
	var endThumbnails = document.getElementById('end_thumbnails');
	var thumbnailParent = document.getElementById('thumbnail_container');
	var thumbnailContainer = document.getElementById('thumbnails');

	if(speed!=0){
		var topPos = thumbnailContainer.style.top.replace(/[^\-0-9]/g,'')/1;	
			
		//Stop moving down when end is reached
		if(speed < 0 && endThumbnails.offsetTop <= (thumbnailParent.offsetHeight - topPos)){
			speed=0;			
		}

		//Adjust down speed as we near the end
		if ((thumbnailParent.offsetHeight - topPos - speed) > endThumbnails.offsetTop) {
			var speedAdjustment = endThumbnails.offsetTop - (thumbnailParent.offsetHeight - topPos - speed);
			speed = speed - speedAdjustment;
		}
		
		//Adjust the up speed as we near the top
		if (topPos + speed > 0) {
			speed = speed + topPos;
		}			
		
		//Stop moving up when the top is reached
		if (speed > 0 && topPos >= 0) {
			speed=0;
		}

		topPos = topPos + speed;
		thumbnailContainer.style.top = topPos + 'px';
	}	
	setTimeout("moveThumbNails()",30);	
}
	
function initSlideShow() {
	var thumbnailContainer = document.getElementById('thumbnails');
	var thumbNails = thumbnailContainer.getElementsByTagName('img');
	var imgTexts = thumbnailContainer.getElementsByTagName('div');
	
	for (var i=0; i < thumbNails.length; i++) {
		thumbNails[i].onmouseover = restoreThumbNail;
		thumbNails[i].onmouseout = fadeThumbNail;
	}
	
	for (var i=0; i < imgTexts.length; i++) {
		imageTexts[i] = imgTexts[i].innerHTML;
	}
		
	moveThumbNails();
}	

function checkInitialized() {
	if (!initialized) {
		initSlideShow();
		initialized = true;
	}	
}