   	/***********************************************************************************************
	
	Copyright (c) 2005 - Alf Magne Kalleland post@dhtmlgoodies.com
	
	UPDATE LOG:
	
	March, 10th, 2006 : Added support for a message while large image is loading
	
	Get this and other scripts at www.dhtmlgoodies.com
	
	You can use this script freely as long as this copyright message is kept intact.
	
	***********************************************************************************************/ 
   	
	var displayWaitMessage = new Array();//num =true;	// Display a please wait message while images are loading?
  	
	var activeImage = new Array();//num  = false;
	var imageGalleryLeftPos = new Array();//num  = false;
	var imageGalleryWidth = new Array();//num  = false;
	var imageGalleryObj = new Array();//num false;
	var maxGalleryXPos = new Array();//num  = false;
	var minGalleryXPos = new Array();//num  = false;
	var slideSpeed = new Array();//num  = 0;
	var imageGalleryCaptions = new Array();//num  = new Array();
	
	function startSlide(e)
	{
		var num = parseInt(this.up('div.dhtmlgoodies_slideshow').id.replace(/dhtmlgoodies_slideshow_/,''));
		if(document.all)e = event;
		var id = this.id;
		this.getElementsByTagName('IMG')[0].src = '/js/slideshow/' + this.id + '_over.gif';	
		if(this.id=='arrow_right'){
			slideSpeedMultiply = Math.floor((e.clientX - this.offsetLeft) / 5);
			slideSpeed[num] = -1*slideSpeedMultiply;
			slideSpeed[num] = Math.max(-10,slideSpeed[num]);
		}else{			
			slideSpeedMultiply = 10 - Math.floor((e.clientX - this.offsetLeft) / 5);
			slideSpeed[num] = 1*slideSpeedMultiply;
			slideSpeed[num] = Math.min(10,slideSpeed[num]);
			if(slideSpeed[num]<0)slideSpeed[num]=10;
		}
	}
	
	function releaseSlide()
	{
		var num = parseInt(this.up('div.dhtmlgoodies_slideshow').id.replace(/dhtmlgoodies_slideshow_/,''));
		var id = this.id;
		this.getElementsByTagName('IMG')[0].src = '/js/slideshow/' + this.id + '.gif';
		slideSpeed[num]=0;
	}
		
	function gallerySlide()
	{	
		for (var i=1; i<imageGalleryObj.length;i++)
		if ((imageGalleryObj[i]) && (slideSpeed[i]!=0)) {
			var leftPos = imageGalleryObj[i].offsetLeft;
			leftPos = leftPos/1 + slideSpeed[i];
			if(leftPos>maxGalleryXPos[i]){
				leftPos = maxGalleryXPos[i];
				slideSpeed[i] = 0;
				
				}
			if(leftPos<minGalleryXPos[i]){
				leftPos = minGalleryXPos[i];
				slideSpeed[i]=0;
				}
			imageGalleryObj[i].style.left = leftPos + 'px';
			}
		setTimeout(gallerySlide,45);
		
	}
	
	function showImage() //num
	{
		var num = parseInt(this.up('div.dhtmlgoodies_slideshow').id.replace(/dhtmlgoodies_slideshow_/,''));
		if(activeImage[num]){
			activeImage[num].style.filter = 'alpha(opacity=50)';	
			activeImage[num].style.opacity = 0.5;
		}	
		this.style.filter = 'alpha(opacity=100)';
		this.style.opacity = 1;	
		activeImage[num] = this;	
	}
	
	function initSlideShow(num) //num
	{

		if (!$('dhtmlgoodies_slideshow_' + num).down('#theImages')) return;
		$('dhtmlgoodies_slideshow_' + num).down('#arrow_left').onmousemove = startSlide;
		$('dhtmlgoodies_slideshow_' + num).down('#arrow_left').onmouseout = releaseSlide;
		$('dhtmlgoodies_slideshow_' + num).down('#arrow_right').onmousemove = startSlide;
		$('dhtmlgoodies_slideshow_' + num).down('#arrow_right').onmouseout = releaseSlide;
		
		imageGalleryObj[num]=$('dhtmlgoodies_slideshow_' + num).down('#theImages');
		slideSpeed[num] = 0;
		imageGalleryLeftPos[num] = imageGalleryObj[num].offsetLeft;
		imageGalleryWidth[num] = $('dhtmlgoodies_slideshow_' + num).down('#galleryContainer').offsetWidth - 80;
		maxGalleryXPos[num] = imageGalleryObj[num].offsetLeft; 
		minGalleryXPos[num] = imageGalleryWidth[num] - $('dhtmlgoodies_slideshow_' + num).down('#slideEnd').offsetLeft;
		var slideshowImages = imageGalleryObj[num].getElementsByTagName('IMG');
		for(var no=0;no<slideshowImages.length;no++){
			slideshowImages[no].onmouseover = showImage;
		}
		
		var divs = imageGalleryObj[num].getElementsByTagName('DIV');
		imageGalleryCaptions[num] = new Array();
		for(var no=0;no<divs.length;no++){
			if(divs[no].className=='imageCaption') imageGalleryCaptions[num].push(divs[no].innerHTML);
		}
		gallerySlide();
	}
	
	function showPreview(num,imagePath,imageIndex){
		var subImages = $('dhtmlgoodies_slideshow_' + num).down('#previewPane').getElementsByTagName('IMG');
		if(subImages.length==0){
			var img = document.createElement('IMG');
			$('dhtmlgoodies_slideshow_' + num).down('#previewPane').appendChild(img);
		}else img = subImages[0];
		
		if(displayWaitMessage){
			$('dhtmlgoodies_slideshow_' + num).down('#waitMessage').style.display='inline';
		}
		$('dhtmlgoodies_slideshow_' + num).down('#largeImageCaption').style.display='none';
		img.onload = function() { hideWaitMessageAndShowCaption(num,imageIndex-1); };
		img.src = imagePath;
		
	}
	function hideWaitMessageAndShowCaption(num,imageIndex)
	{
		$('dhtmlgoodies_slideshow_' + num).down('#waitMessage').style.display='none';	
		$('dhtmlgoodies_slideshow_' + num).down('#largeImageCaption').innerHTML = imageGalleryCaptions[num][imageIndex];
		$('dhtmlgoodies_slideshow_' + num).down('#largeImageCaption').style.display='block';
		
	}
	