	/************************************************************************************************************
	(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
	
	************************************************************************************************************/	

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function showLargeImageInit(img){
     
      if(img){
		  var url = img.src;
		  url = url.replace("_preview.jpg",".jpg");
		  mywindow = window.open(url, "_blank");
	  
		  // Pop the window to the front
		  if (mywindow && mywindow.focus) mywindow.focus();	
	  }
}

function showLargeImage(){
     
      if(this){
		  var url = this.src;
		  url = url.replace("_preview.jpg",".jpg");
		  mywindow = window.open(url, "_blank");
	  
		  // Pop the window to the front
		  if (mywindow && mywindow.focus) mywindow.focus();	
	  }
}
	
function SlideShow(objectName,refNumber){
	
	this.opacitySpeed = 2;	// Speed of opacity - switching between large images - Lower = faster
	this.opacitySteps = 10; 	// Also speed of opacity - Higher = faster
	this.slideSpeed = 5;	// Speed of thumbnail slide - Lower = faster
	this.slideSteps = 8;	// Also speed of thumbnail slide - Higher = faster
	
	/* Don't change anything below here */
	this.DHTMLgoodies_largeImage = false;
	this.DHTMLgoodies_imageToShow = false;
	this.DHTMLgoodies_currentOpacity = 100;
	this.DHTMLgoodies_slideWidth = false;
	this.DHTMLgoodies_thumbTotalWidth = false;
	this.DHTMLgoodies_viewableWidth = false;
	
	this.currentUnqiueOpacityId = false;
	this.DHTMLgoodies_currentActiveImage = false;
	this.DHTMLgoodies_thumbDiv = false;
	this.DHTMLgoodies_thumbSlideInProgress = false;
	
	this.browserIsOpera = navigator.userAgent.indexOf('Opera')>=0?true:false;
	this.leftArrowObj;
	this.rightArrowObj;
	this.thumbsColIndex = 1;
	this.thumbsLeftPos = false;
	
	this.ObjectName = objectName;
	this.refNumber = refNumber
	
	this.initGalleryScript = function()
	{
		this.leftArrowObj = document.getElementById('DHTMLgoodies_leftArrow_'+this.refNumber);		
		this.leftArrowObj.style.visibility='hidden';
		this.rightArrowObj = document.getElementById('DHTMLgoodies_rightArrow_'+this.refNumber);	
		this.leftArrowObj.style.cursor = 'pointer';	
		this.rightArrowObj.style.cursor = 'pointer';
		this.rightArrowObj.style.visibility='visible';
		//this.leftArrowObj.onclick = this.moveThumbnails;
		//this.rightArrowObj.onclick = this.moveThumbnails;
		this.DHTMLgoodies_largeImage = document.getElementById('DHTMLgoodies_largeImage_'+this.refNumber).getElementsByTagName('IMG')[0];
		var innerDiv = document.getElementById('DHTMLgoodies_thumbs_inner_'+this.refNumber);
		this.DHTMLgoodies_slideWidth = innerDiv.getElementsByTagName('DIV')[0].offsetWidth;
		this.DHTMLgoodies_thumbDiv = document.getElementById('DHTMLgoodies_thumbs_inner_'+this.refNumber);
		this.DHTMLgoodies_thumbDiv.style.left = '0px';
		
		var subDivs = this.DHTMLgoodies_thumbDiv.getElementsByTagName('DIV');
		this.DHTMLgoodies_thumbTotalWidth = 0;
		var tmpLeft = 0;
		for(var no=0;no<subDivs.length;no++){
			if(subDivs[no].className=='strip_of_thumbnails'){
				this.DHTMLgoodies_thumbTotalWidth = this.DHTMLgoodies_thumbTotalWidth + this.DHTMLgoodies_slideWidth;
				subDivs[no].style.left = tmpLeft + 'px';
				subDivs[no].style.top = '0px';
				tmpLeft = tmpLeft + subDivs[no].offsetWidth;
			}
		}

		this.DHTMLgoodies_viewableWidth = document.getElementById('DHTMLgoodies_thumbs_'+this.refNumber).offsetWidth;
		
		
		this.DHTMLgoodies_currentActiveImage = this.DHTMLgoodies_thumbDiv.getElementsByTagName('A')[0].getElementsByTagName('IMG')[0];
		this.DHTMLgoodies_currentActiveImage.className='activeImage';
	}
	
	this.moveThumbnails = function(pSender)
	{
		if(this.DHTMLgoodies_thumbSlideInProgress)return;
		this.DHTMLgoodies_thumbSlideInProgress = true;
		if(pSender.id=='DHTMLgoodies_leftArrow_'+this.refNumber){
			this.thumbsColIndex--;
			this.rightArrowObj.style.visibility='visible';
			if(this.DHTMLgoodies_thumbDiv.style.left.replace('px','')/1>=0){
				this.leftArrowObj.style.visibility='hidden';
				this.DHTMLgoodies_thumbSlideInProgress = false;
				return;
			}
			
			this.slideThumbs(this.slideSteps,0);
			
		}else{
			this.thumbsColIndex++;
			this.leftArrowObj.style.visibility='visible';
			var left = this.DHTMLgoodies_thumbDiv.style.left.replace('px','')/1;	
			var showArrow = true;
			if((parseInt(this.DHTMLgoodies_thumbTotalWidth) + parseInt(left)) - parseInt(this.DHTMLgoodies_slideWidth) <= parseInt(this.DHTMLgoodies_viewableWidth)){
				showArrow = false;
			}
				
			if(!showArrow)	
			{
				this.rightArrowObj.style.visibility='hidden';
				this.DHTMLgoodies_thumbSlideInProgress = false;
				return;
			}	
			
			this.slideThumbs((this.slideSteps*-1),0);
		}	
		
	}
	
	this.slideThumbs = function(speed,currentPos)
	{
		var leftPos;
		if(this.thumbsLeftPos){
			leftPos= this.thumbsLeftPos;
		}else{
			var leftPos = this.DHTMLgoodies_thumbDiv.style.left.replace('px','')/1;
			this.thumbsLeftPos = leftPos;
		}
		currentPos = currentPos + Math.abs(speed);		
		var tmpLeftPos = leftPos;
		leftPos = leftPos + speed;
		this.thumbsLeftPos = leftPos;
		this.DHTMLgoodies_thumbDiv.style.left = leftPos + 'px';
		
		
		if(currentPos<this.DHTMLgoodies_slideWidth){
			setTimeout(this.ObjectName+'.slideThumbs(' + speed + ',' + currentPos + ')',this.slideSpeed);
		}else{
			
			if(tmpLeftPos>=0 || this.thumbsColIndex==1){
				document.getElementById('DHTMLgoodies_leftArrow_'+this.refNumber).style.visibility='hidden';
			}	
			var left = tmpLeftPos;		
			var showArrow = true;
			if((this.DHTMLgoodies_thumbTotalWidth + (left - this.DHTMLgoodies_slideWidth) <= this.DHTMLgoodies_viewableWidth)&&speed<0){
				showArrow=false;
			}
			
			if(!showArrow){
				document.getElementById('DHTMLgoodies_rightArrow_'+this.refNumber).style.visibility='hidden';
			}					
			this.DHTMLgoodies_thumbSlideInProgress = false;
		}
	
	}
	
	this.showPreview = function(imagePath,inputObj)
	{		
		if(this.DHTMLgoodies_currentActiveImage){
			if(this.DHTMLgoodies_currentActiveImage==inputObj.getElementsByTagName('IMG')[0])return;
			this.DHTMLgoodies_currentActiveImage.className='';
		}
		this.DHTMLgoodies_currentActiveImage = inputObj.getElementsByTagName('IMG')[0];
		this.DHTMLgoodies_currentActiveImage.className='activeImage';
		
		this.DHTMLgoodies_imageToShow = imagePath;
		var tmpImage = new Image();
		tmpImage.src = imagePath;
		this.currentUnqiueOpacityId = Math.random();
		this.moveOpacity(this.opacitySteps*-1,this.currentUnqiueOpacityId);
	}
	
	this.setOpacity = function()
	{
		if(document.all)
		{
			this.DHTMLgoodies_largeImage.style.filter = 'alpha(opacity=' + this.DHTMLgoodies_currentOpacity + ')';
		}else{
			this.DHTMLgoodies_largeImage.style.opacity = this.DHTMLgoodies_currentOpacity/100;
		}		
	}
	this.moveOpacity = function(speed,uniqueId)
	{
		
		if(this.browserIsOpera){
			this.DHTMLgoodies_largeImage.src = this.DHTMLgoodies_imageToShow;
			return;
		}
		
		this.DHTMLgoodies_currentOpacity = this.DHTMLgoodies_currentOpacity + speed;
		if(this.DHTMLgoodies_currentOpacity<=5 && speed<0){
		
			var tmpParent = this.DHTMLgoodies_largeImage.parentNode; 
			this.DHTMLgoodies_largeImage.parentNode.removeChild(this.DHTMLgoodies_largeImage);
			this.DHTMLgoodies_largeImage = document.createElement('IMG');
			tmpParent.appendChild(this.DHTMLgoodies_largeImage);
			this.setOpacity();
			this.DHTMLgoodies_largeImage.src = this.DHTMLgoodies_imageToShow;
		
			speed=this.opacitySteps;
		}
		if(this.DHTMLgoodies_currentOpacity>=99 && speed>0){
			this.DHTMLgoodies_currentOpacity=99;
		}
		this.setOpacity();	
		if(this.DHTMLgoodies_currentOpacity>=99 && speed>0){
			this.DHTMLgoodies_largeImage.onclick = showLargeImage;
			this.DHTMLgoodies_largeImage.title = "Click to see larger image";
			return;
		}
		if(uniqueId==this.currentUnqiueOpacityId)setTimeout(this.ObjectName+'.moveOpacity(' + speed + ',' + uniqueId + ')',this.opacitySpeed);		
	}
	
}