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

function show(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.offsetLeft;

	while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;

	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.clientX + Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) - getTopPosition(this);
	
	if(this.src.indexOf('right')>=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.left.replace(/[^\-0-9]/g,'')/1;	
		if(scrollSpeed<0 && totalImgWidth<(thumbGallery.offsetWidth - topPos)){
			scrollSpeed=0;
		}
		topPos = topPos + scrollSpeed;

		if(topPos>0)topPos=0;

	 	thumbImages.style.left = topPos + 'px';

	}
	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.left = '0px';
	galleryContainer  = document.getElementById('slideshow');
	images = thumbImages.getElementsByTagName('IMG');

	totalImgWidth = 0;
	// removed overwriting the onMouseOver on the actual image
	for(var no=0;no<images.length;no++){ 
		totalImgWidth += images[no].offsetWidth + 4;
		//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;
