	/************************************************************************************************************
	(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 = 8; 	// Also speed of opacity - Higher = faster
	var slideSpeed = 3;	// Speed of thumbnail slide - Lower = faster
	
	/* Don't change anything below here */
	var dd_gallery_slideshow_largeImage = false;
	var dd_gallery_slideshow_imageToShow = false;
	var dd_gallery_slideshow_currentOpacity = 100;
	var dd_gallery_slideshow_slideWidth = false;
	var dd_gallery_slideshow_thumbTotalWidth = false;
	var dd_gallery_slideshow_viewableWidth = false;
	
	var currentUnqiueOpacityId = false;
	var dd_gallery_slideshow_currentActiveImage = false;
	var dd_gallery_slideshow_thumbDiv = false;
	var dd_gallery_slideshow_thumbSlideInProgress = false;
	//new
	var dd_gallery_slideshow_imageURL = false;
	
	var browserIsOpera = navigator.userAgent.indexOf('Opera')>=0?true:false;
	var leftArrowObj;
	var rightArrowObj;
	
	function initGalleryScript()
	{
		leftArrowObj = document.getElementById('dd_gallery_slideshow_leftArrow');		
		leftArrowObj.style.visibility='hidden';
		rightArrowObj = document.getElementById('dd_gallery_slideshow_rightArrow');	
		leftArrowObj.style.cursor = 'pointer';	
		rightArrowObj.style.cursor = 'pointer';	
		leftArrowObj.onclick = moveThumbnails;
		rightArrowObj.onclick = moveThumbnails;
		dd_gallery_slideshow_largeImage = document.getElementById('dd_gallery_slideshow_largeImage').getElementsByTagName('IMG')[0];
		var innerDiv = document.getElementById('dd_gallery_slideshow_thumbs_inner');
		//dd_gallery_slideshow_slideWidth = innerDiv.getElementsByTagName('DIV')[0].offsetWidth;
		dd_gallery_slideshow_slideWidth = 132;
		dd_gallery_slideshow_thumbDiv = document.getElementById('dd_gallery_slideshow_thumbs_inner');
		dd_gallery_slideshow_thumbDiv.style.left = '0px';
		
		
		var subDivs = dd_gallery_slideshow_thumbDiv.getElementsByTagName('DIV');
		dd_gallery_slideshow_thumbTotalWidth = 0;
		for(var no=0;no<subDivs.length;no++){
			if(subDivs[no].className=='strip_of_thumbnails')dd_gallery_slideshow_thumbTotalWidth = dd_gallery_slideshow_thumbTotalWidth + dd_gallery_slideshow_slideWidth;
		}

		dd_gallery_slideshow_viewableWidth = document.getElementById('dd_gallery_slideshow_thumbs').offsetWidth;
		
		
		dd_gallery_slideshow_currentActiveImage = dd_gallery_slideshow_thumbDiv.getElementsByTagName('A')[0].getElementsByTagName('IMG')[0];
		dd_gallery_slideshow_currentActiveImage.className='activeImage';
		
		//new
		dd_gallery_slideshow_imageURL = document.getElementById('dd_gallery_slideshow_largeImageURL');
	}
	
	function moveThumbnails()
	{
		if(dd_gallery_slideshow_thumbSlideInProgress)return;
		dd_gallery_slideshow_thumbSlideInProgress = true;
		if(this.id=='dd_gallery_slideshow_leftArrow'){
			rightArrowObj.style.visibility='visible';
			if(dd_gallery_slideshow_thumbDiv.style.left.replace('px','')/1>=0){
				leftArrowObj.style.visibility='hidden';
				dd_gallery_slideshow_thumbSlideInProgress = false;
				return;
			}
			slideThumbs(4,0);
			
		}else{
			leftArrowObj.style.visibility='visible';
			var left = dd_gallery_slideshow_thumbDiv.style.left.replace('px','')/1;			
			if(dd_gallery_slideshow_thumbTotalWidth + left - dd_gallery_slideshow_slideWidth <= dd_gallery_slideshow_viewableWidth){
				rightArrowObj.style.visibility='hidden';
				dd_gallery_slideshow_thumbSlideInProgress = false;
				return;
			}	
			slideThumbs(-4,0);
		}	
		
	}
	
	function slideThumbs(speed,currentPos)
	{
		var leftPos = dd_gallery_slideshow_thumbDiv.style.left.replace('px','')/1;
		currentPos = currentPos + Math.abs(speed);		
		leftPos = leftPos + speed;
		dd_gallery_slideshow_thumbDiv.style.left = leftPos + 'px';
		if(currentPos<dd_gallery_slideshow_slideWidth)setTimeout('slideThumbs(' + speed + ',' + currentPos + ')',slideSpeed);else{
			if(dd_gallery_slideshow_thumbDiv.style.left.replace('px','')/1>=0){
				document.getElementById('dd_gallery_slideshow_leftArrow').style.visibility='hidden';
			}	
			var left = dd_gallery_slideshow_thumbDiv.style.left.replace('px','')/1;		
			if(dd_gallery_slideshow_thumbTotalWidth + left - dd_gallery_slideshow_slideWidth <= dd_gallery_slideshow_viewableWidth){
				document.getElementById('dd_gallery_slideshow_rightArrow').style.visibility='hidden';
			}					
			dd_gallery_slideshow_thumbSlideInProgress = false;
		}
	
	}
	
	function showPreview(imagePath,imageViewUrl,inputObj)
	{		
		if(dd_gallery_slideshow_currentActiveImage){
			if(dd_gallery_slideshow_currentActiveImage==inputObj.getElementsByTagName('IMG')[0])return;
			dd_gallery_slideshow_currentActiveImage.className='';
		}
		dd_gallery_slideshow_currentActiveImage = inputObj.getElementsByTagName('IMG')[0];
		dd_gallery_slideshow_currentActiveImage.className='activeImage';
		
		dd_gallery_slideshow_imageToShow = imagePath;
		var tmpImage = new Image();
		tmpImage.src = imagePath;
		currentUnqiueOpacityId = Math.random();
		moveOpacity(opacitySteps*-1,currentUnqiueOpacityId);
		
		//new
		dd_gallery_slideshow_imageURL.href = imageViewUrl;
		dd_gallery_slideshow_imageURL.setAttribute('abox',imagePath);
	}
	
	function setOpacity()
	{
		if(document.all)
		{
			dd_gallery_slideshow_largeImage.style.filter = 'alpha(opacity=' + dd_gallery_slideshow_currentOpacity + ')';
		}else{
			dd_gallery_slideshow_largeImage.style.opacity = dd_gallery_slideshow_currentOpacity/100;
		}		
	}
	function moveOpacity(speed,uniqueId)
	{
		
		if(browserIsOpera){
			dd_gallery_slideshow_largeImage.src = dd_gallery_slideshow_imageToShow;
			return;
		}
		
		dd_gallery_slideshow_currentOpacity = dd_gallery_slideshow_currentOpacity + speed;
		if(dd_gallery_slideshow_currentOpacity<=5 && speed<0){
		
			var tmpParent = dd_gallery_slideshow_largeImage.parentNode; 
			dd_gallery_slideshow_largeImage.parentNode.removeChild(dd_gallery_slideshow_largeImage);
			dd_gallery_slideshow_largeImage = document.createElement('IMG');
			tmpParent.appendChild(dd_gallery_slideshow_largeImage);
			setOpacity();
			dd_gallery_slideshow_largeImage.src = dd_gallery_slideshow_imageToShow;
			//new
			dd_gallery_slideshow_largeImage.title = '';
			dd_gallery_slideshow_largeImage.alt = '';
		
			speed=opacitySteps;
		}
		if(dd_gallery_slideshow_currentOpacity>=99 && speed>0)dd_gallery_slideshow_currentOpacity=99;		
		setOpacity();	
		if(dd_gallery_slideshow_currentOpacity>=99 && speed>0)return;		
		if(uniqueId==currentUnqiueOpacityId)setTimeout('moveOpacity(' + speed + ',' + uniqueId + ')',opacitySpeed);		
	}
