	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, June 2006
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	

	
	
	
	var opacitySpeed = 2;	// Speed of opacity - switching between large images - Lower = faster
	var opacitySteps = 10; 	// Also speed of opacity - Higher = faster
	var slideSpeed = 5;	// Speed of thumbnail slide - Lower = faster
	var slideSteps = 8;	// Also speed of thumbnail slide - Higher = faster
	var columnsOfThumbnails = 7;	// Hardcoded number of thumbnail columns, use false if you want the script to figure it out dynamically.
	
	/* Don't change anything below here */
	var slideshow_largeImage = false;
	var slideshow_imageToShow = false;
	var slideshow_currentOpacity = 100;
	var slideshow_slideWidth = false;
	var slideshow_thumbTotalWidth = false;
	var slideshow_viewableWidth = false;
	
	var currentUnqiueOpacityId = false;
	var slideshow_currentActiveImage = false;
	var slideshow_thumbDiv = false;
	var slideshow_thumbSlideInProgress = false;
	
	var browserIsOpera = navigator.userAgent.indexOf('Opera')>=0?true:false;
	var leftArrowObj;
	var rightArrowObj;
	var thumbsColIndex = 1;
	var thumbsLeftPos = false;
	
	function initGalleryScript()
	{
		slideshow_largeImage = document.getElementById('slideshow_largeImage').getElementsByTagName('IMG')[0];
		var innerDiv = document.getElementById('slideshow_thumbs_inner');
		slideshow_thumbDiv = document.getElementById('slideshow_thumbs_inner');
		slideshow_viewableWidth = document.getElementById('slideshow_thumbs').offsetWidth;
	}
	
	function moveThumbnails()
	{
		if(slideshow_thumbSlideInProgress)return;
		slideshow_thumbSlideInProgress = true;
		if(this.id=='slideshow_leftArrow'){
			thumbsColIndex--;
			rightArrowObj.style.visibility='visible';
			if(slideshow_thumbDiv.style.left.replace('px','')/1>=0){
				leftArrowObj.style.visibility='hidden';
				slideshow_thumbSlideInProgress = false;
				return;
			}
			
			slideThumbs(slideSteps,0);
			
		}else{
			thumbsColIndex++;
			leftArrowObj.style.visibility='visible';
			var left = slideshow_thumbDiv.style.left.replace('px','')/1;	
			var showArrow = true;
			if(slideshow_thumbTotalWidth + left - slideshow_slideWidth <= slideshow_viewableWidth)showArrow = false;
			if(columnsOfThumbnails)showArrow = true;
				
			if(!showArrow)	
			{
				rightArrowObj.style.visibility='hidden';
				slideshow_thumbSlideInProgress = false;
				return;
			}	
			
			slideThumbs((slideSteps*-1),0);
		}	
		
	}
	
	function slideThumbs(speed,currentPos)
	{
		var leftPos;
		if(thumbsLeftPos){
			leftPos= thumbsLeftPos;
		}else{
			var leftPos = slideshow_thumbDiv.style.left.replace('px','')/1;
			thumbsLeftPos = leftPos;
		}
		currentPos = currentPos + Math.abs(speed);		
		var tmpLeftPos = leftPos;
		leftPos = leftPos + speed;
		thumbsLeftPos = leftPos;
		slideshow_thumbDiv.style.left = leftPos + 'px';
		if(currentPos<slideshow_slideWidth)setTimeout('slideThumbs(' + speed + ',' + currentPos + ')',slideSpeed);else{
			if(tmpLeftPos>=0 || (columnsOfThumbnails && thumbsColIndex==1)){
				document.getElementById('slideshow_leftArrow').style.visibility='hidden';
			}	
			var left = tmpLeftPos;		
			var showArrow = true;
			if(slideshow_thumbTotalWidth + left - slideshow_slideWidth <= slideshow_viewableWidth)showArrow=false;
			if(columnsOfThumbnails){
				if((thumbsColIndex+1)<columnsOfThumbnails)showArrow=true; else showArrow = false;				
			}			
			if(!showArrow){
				document.getElementById('slideshow_rightArrow').style.visibility='hidden';
			}					
			slideshow_thumbSlideInProgress = false;
		}
	
	}
	
	function showPreview(imagePath,inputObj)
	{		
		if(slideshow_currentActiveImage){
			if(slideshow_currentActiveImage==inputObj.getElementsByTagName('IMG')[0])return;
			slideshow_currentActiveImage.className='';
		}
		slideshow_currentActiveImage = inputObj.getElementsByTagName('IMG')[0];
		slideshow_currentActiveImage.className='activeImage';
		
		slideshow_imageToShow = imagePath;
		var tmpImage = new Image();
		tmpImage.src = imagePath;
		currentUnqiueOpacityId = Math.random();
		moveOpacity(opacitySteps*-1,currentUnqiueOpacityId);
	}
	
	function setOpacity()
	{
		if(document.all)
		{
			slideshow_largeImage.style.filter = 'alpha(opacity=' + slideshow_currentOpacity + ')';
		}else{
			slideshow_largeImage.style.opacity = slideshow_currentOpacity/100;
		}		
	}
	function moveOpacity(speed,uniqueId)
	{
		
		if(browserIsOpera){
			slideshow_largeImage.src = slideshow_imageToShow;
			return;
		}
		
		slideshow_currentOpacity = slideshow_currentOpacity + speed;
		if(slideshow_currentOpacity<=5 && speed<0){
		
			var tmpParent = slideshow_largeImage.parentNode; 
			slideshow_largeImage.parentNode.removeChild(slideshow_largeImage);
			slideshow_largeImage = document.createElement('IMG');
			tmpParent.appendChild(slideshow_largeImage);
			setOpacity();
			slideshow_largeImage.src = slideshow_imageToShow;
		
			speed=opacitySteps;
		}
		if(slideshow_currentOpacity>=99 && speed>0)slideshow_currentOpacity=99;		
		setOpacity();	
		if(slideshow_currentOpacity>=99 && speed>0)return;		
		if(uniqueId==currentUnqiueOpacityId)setTimeout('moveOpacity(' + speed + ',' + uniqueId + ')',opacitySpeed);		
	}