var scrollSpeed=0;
var triggerHeight = 20;
var thumbImages;
var images;
var previousSelected = 0;

function showImg(name,src,caption,obj) {
   if (document.images)
       document.images[name].src = src;
	document.images[name].alt = caption;

	   showSelected(obj);

	//alert(document.getElementById('caption'));
   if(document.getElementById('caption') ) 
       document.getElementById('caption').innerHTML =caption;
}


function getTopPosition(inputObj) {		
	var returnValue = inputObj.offsetTop;
	while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
	return returnValue;
}

function startScroller(e)	{
	if(document.all)e = event;

	if(this.src.indexOf('over')<0)this.src = this.src.replace('.gif','-over.gif');
		
	scrollSpeed = e.clientY + Math.max(document.body.scrollTop,document.documentElement.scrollTop) - getTopPosition(this);

	if(this.src.indexOf('down')>=0){
		scrollSpeed = (scrollSpeed)*-1;	
	}else{
		scrollSpeed = triggerHeight - scrollSpeed;
	}
	scrollSpeed = Math.round(scrollSpeed * 10 / triggerHeight);
	
}
	
function stopScroller() {		
	scrollSpeed = 0;
	this.src = this.src.replace('-over','');
}

function slidePreviewPane() {
	if(scrollSpeed!=0){
		var topPos = thumbImages.style.top.replace(/[^\-0-9]/g,'')/1;	
//alert("scroll: " +scrollSpeed+" Top: "+topPos);
//alert("end: "+ scrollEndMarker.offsetTop + ' < ' + "Gallery: " + thumbGallery.offsetHeight + ' - ' + topPos);
		
		if(scrollSpeed<0 && scrollEndMarker.offsetTop<(thumbGallery.offsetHeight - topPos)){
			scrollSpeed=0;
		}
		topPos = topPos + scrollSpeed;
//alert(scrollSpeed+" Top: "+topPos);
		if(topPos>0)topPos=0;
	 	thumbImages.style.top = topPos + 'px';
//alert(thumbImages.style.top);
	}
	setTimeout('slidePreviewPane()',30);		
}

function showHighlight(){
	if(this.className != 'highlightIV selectedImgIV'){
		this.className = 'highlightIV enabledIV';
		//this.style.border = '2px solid #008000';
	}
}

function hideHighlight(){
	if(this.className != 'highlightIV selectedImgIV'){
		this.className = 'highlightIV disabledIV';
		//this.style.border = '2px solid #666666';
	}
}

function showSelected(currObj){
	if(previousSelected != 0){
		previousSelected.className = 'highlightIV disabledIV';
	}
	currObj.className = 'highlightIV selectedImgIV';
	//currObj.onmouseout = false;
	previousSelected = currObj;
}


function initThumbGallery() {

	thumbGallery = document.getElementById('thumbimages');
	thumbImages = document.getElementById('scrollarea');
	thumbImages.style.top = '0px';
	galleryContainer  = document.getElementById('slideshow');
	images = thumbImages.getElementsByTagName('IMG');
	// removed overwriting the onMouseOver on the actual image
	//for(var no=0;no<images.length;no++){ 
		//images[no].onmouseover = showHighlight;
		//images[no].onmouseout = hideHighlight;
		//images[no].onclick = showSelected;
	//}	
	scrollEndMarker = document.getElementById('scrollstop');
		
	document.getElementById('uparrow').onmousemove = startScroller;
	document.getElementById('uparrow').onmouseout = stopScroller;
		
	document.getElementById('downarrow').onmousemove = startScroller;
	document.getElementById('downarrow').onmouseout = stopScroller;
	
	slidePreviewPane();
		
}
	
	
//window.onload = initThumbGallery;