   	/***********************************************************************************************
	
	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 SlideShowInstance;

   	function SlideShow(_name)
   	{
   	    this.name = _name;
   	       	    
	    this.displayWaitMessage=true;	// Display a please wait message while images are loading?
  	
   		
	    this.activeImage = false;
	    this.imageGalleryLeftPos = false;
	    this.imageGalleryWidth = false;
	    this.imageGalleryObj = false;
	    this.maxGalleryXPos = false;
	    this.slideSpeed = 0;
	    this.imageGalleryCaptions = new Array();
	    this.imageGalleryHeaders = new Array();
	    
	    SlideShowInstance= this;
	    //idx = idx +1;
	    this.initSlideShow();
	}
	SlideShow.prototype.startSlide = function(e)
	{
		if(document.all)e = event;
		var id = this.id;
 
		//this.getElementsByTagName('IMG')[0].src = 'images/' + this.id + '.gif';
        //alert(this.name);
        
		if(id=='arrow_right'){
			SlideShowInstance.slideSpeedMultiply = Math.floor((e.clientX - this.offsetLeft) / 5);
			SlideShowInstance.slideSpeed = -1*SlideShowInstance.slideSpeedMultiply;
			SlideShowInstance.slideSpeed = Math.max(-10,SlideShowInstance.slideSpeed);
		}else{			
			SlideShowInstance.slideSpeedMultiply = 10 - Math.floor((e.clientX - this.offsetLeft) / 5);
			SlideShowInstance.slideSpeed = 1*SlideShowInstance.slideSpeedMultiply;
			SlideShowInstance.slideSpeed = Math.min(10,SlideShowInstance.slideSpeed);
			if(SlideShowInstance.slideSpeed<0)SlideShowInstance.slideSpeed=10;
		}
	}
	
	SlideShow.prototype.releaseSlide =function()
	{
		var id = this.id;
		//this.getElementsByTagName('IMG')[0].src = 'images/' + this.id + '.gif';
		SlideShowInstance.slideSpeed=0;
	}
		
	SlideShow.prototype.gallerySlide = function gallerySlide(_name)
	{
		if(this.slideSpeed!=0){
			var leftPos = this.imageGalleryObj.offsetLeft;
			leftPos = leftPos/1 + this.slideSpeed;
			
			
			
			if(leftPos>this.maxGalleryXPos){
				leftPos = this.maxGalleryXPos;
				this.slideSpeed =0;
			}
			if(leftPos<this.minGalleryXPos){
				leftPos = this.minGalleryXPos;
				this.slideSpeed=0;
			}
			
			this.imageGalleryObj.style.left = leftPos + 'px';
		}
		setTimeout(function(){SlideShowInstance.gallerySlide(_name)},20);
		
	}
	
	SlideShow.prototype.showImage = function()
	{
	    
		if(SlideShowInstance.activeImage){
			SlideShowInstance.activeImage.style.filter = 'alpha(opacity=50)';	
			SlideShowInstance.activeImage.style.opacity = 0.5;
		}	
		this.style.filter = 'alpha(opacity=100)';
		this.style.opacity = 1;	
		SlideShowInstance.activeImage = this;	
	}
	
	SlideShow.prototype.initSlideShow = function()
	{
		document.getElementById('arrow_left').name = this.name;	
		document.getElementById('arrow_left').onmousemove = SlideShowInstance.startSlide;
		document.getElementById('arrow_left').onmouseout = SlideShowInstance.releaseSlide;
	    
		document.getElementById('arrow_right').name = this.name;	
		document.getElementById('arrow_right').onmousemove = SlideShowInstance.startSlide;
		document.getElementById('arrow_right').onmouseout = SlideShowInstance.releaseSlide;
		
		this.imageGalleryObj = document.getElementById('theImages');
		this.imageGalleryLeftPos = this.imageGalleryObj.offsetLeft;
		this.imageGalleryWidth = document.getElementById('galleryContainer').offsetWidth - 80;
		this.maxGalleryXPos = this.imageGalleryObj.offsetLeft+11; 
		this.minGalleryXPos = this.imageGalleryWidth - document.getElementById('slideEnd').offsetLeft;
		var slideshowImages = this.imageGalleryObj.getElementsByTagName('IMG');
	
		for(var no=0;no<slideshowImages.length;no++){
		    //slideshowImages[no].width = "50";
		    //ddd = slideshowImages[no].height / 45;
		    //alert(slideshowImages[no].height);
		    //slideshowImages[no].width = (slideshowImages[no].width);
		    //slideshowImages[no].width = "55";		    
		    slideshowImages[no].height = "45";
		    slideshowImages[no].width = "auto";
		    
		    slideshowImages[no].name = this.name;
			slideshowImages[no].onmouseover = SlideShowInstance.showImage;
		}
		
		var divs = this.imageGalleryObj.getElementsByTagName('DIV');
        var idx1=0,idx2=0;		
		for(var no=0;no<divs.length;no++){
			if(divs[no].className=='imageCaption')
			{
			    this.imageGalleryCaptions[idx1] = divs[no].innerHTML;
			    idx1 = idx1 + 1;
			}
			if(divs[no].className=='imageHeader')
			{
			    this.imageGalleryHeaders[idx2] = divs[no].innerHTML;			
			    idx2 = idx2+1;
			}
		}
		
		this.gallerySlide(this.name);
	}
	
	SlideShow.prototype.showPreview = function (sender,imageIndex){
		var subImages = document.getElementById('previewPane').getElementsByTagName('IMG');
		
		
		var slideshowImages = this.imageGalleryObj.getElementsByTagName('IMG');
        var slideshowlink = document.getElementById('previewPane').getElementsByTagName('A');
        
		var senderimg = slideshowImages[imageIndex];
				
		slideshowlink[0].href = sender;
		    
		if(subImages.length==0){
		
			var img = document.createElement('IMG');
			document.getElementById('previewPane').appendChild(img);
		}else img = subImages[0];
		
//		if(this.displayWaitMessage){
//			document.getElementById('waitMessage').style.display='inline';
//		}
//		document.getElementById('largeImageCaption').style.display='none';
//		document.getElementById('headerCaption').style.display='none';
		
		img.onload = function() { SlideShowInstance.hideWaitMessageAndShowCaption(imageIndex-1); };
//		img.className = 'previewPane_img';

		img.src = senderimg.src;


	   var img2 = document.createElement('IMG');
       img2.src = senderimg.src;

       var fff = img2.width / 100;
        img.width = "100";
        img.height = img2.height / fff;
       
       
       if(img.height>100)
       {
       fff = img.height / 100;
       img.width =img.width /fff;
       img.height = "100";
       
       }
	       
		
	}
	SlideShow.prototype.hideWaitMessageAndShowCaption = function(imageIndex)
	{
//		document.getElementById('waitMessage').style.display='none';	
		document.getElementById('largeImageCaption').innerHTML = this.imageGalleryCaptions[imageIndex+1];
		document.getElementById('headerCaption').innerHTML = this.imageGalleryHeaders[imageIndex+1];	
//		document.getElementById('largeImageCaption').style.display='block';
//		document.getElementById('headerCaption').style.display='block';
	}

