

  	function preloadImages()
	{
		if (document.images)
		{
			document.imgs = new Array();
		    document.imgsThumb = new Array();
			for(i=0; i<images.length; i++)
			{
				document.imgs[i] = new Image;
				document.imgs[i].src = images[i]['path'];
				document.imgsThumb[i] = new Image;
				document.imgsThumb[i].src = images[i]['paththumb'];
			}
		}
	}
	
    
	function initFotoboek()
    {
      
      setTimeout('preloadImages()', 1);

	  curFoto = 0;
	  slideActive = true;
	  showEffect = true;

	  if(photoCount<5)
	  	thumbCount = photoCount;
	  else
	 	thumbCount = 5;

      nameBox = document.getElementById('name');
	  startBtn = document.getElementById('btnStart');
	  effectBtn = document.getElementById('btnEffect');
	  speedMenu = document.getElementById('speed');
	  thisPhotoBox = document.images.thisPhoto;

	  thumbPhotoBox1 = document.images.thumbPhoto1;
	  thumbPhotoBox2 = document.images.thumbPhoto2;
	  thumbPhotoBox3 = document.images.thumbPhoto3;
	  thumbPhotoBox4 = document.images.thumbPhoto4;
	  thumbPhotoBox5 = document.images.thumbPhoto5;
	  prevBtn = document.images.btnPrev;
	  nextBtn = document.images.btnNext;

	  timeoutFadeOut = null;
      timeoutNextPhoto = null;

	  showNext(true);
	}
	
	function setEffect()
	{
      	if(showEffect)
	   	{
		   	showEffect = false;
			effectBtn.value = 'Effect aan';
		}
		else
		{
			showEffect = true;
			effectBtn.value = 'Effect uit';
		}
	}
	

	function showNext(fadeIN)
	{
		if(curFoto>=photoCount)
			return;



		if(fadeIN==false && showEffect)
		{
		//	if(!slideActive)
		//		return;
		
			if(curFoto>=photoCount)
				return;

			opacity('2', 100, 0, 2000);
			timeoutFadeOut = setTimeout('showNext(true)', 200);
  		}else{
			
			if(showEffect)
			{
				thisPhotoBox.style.visibility = 'hidden';
				thisPhotoBox.src = images[curFoto]['path'];
				thisPhotoBox.style.visibility = 'visible';
				opacity('2', 0, 100, 2000);
   			}
   			else
   			{
            	thisPhotoBox.src = images[curFoto]['path'];
			}
			thisPhotoBox.style.height = images[curFoto]['height'];
			thisPhotoBox.style.width = images[curFoto]['width'];

			nameBox.innerHTML = images[curFoto]['name'];
			updateThumbs();
			curFoto++;

            timeoutNextPhoto = setTimeout('showNext(false)', speedMenu.value);
		}
	}

	function updateThumbs()
	{
	    thumb = curFoto -2;

		if(thumb+5>photoCount)
        	thumb = photoCount-5;

        if(thumb<0)
             thumb = 0;


	  	for(i=1;i<thumbCount+1;i++)
	  	{
		 	box = "thumbPhotoBox"+i;

				eval(box).src = images[thumb++]['paththumb'];
				if(curFoto==(thumb-1))
				{
					eval(box).className = 'fotoboek_thumb_selected';
				}else{
	                eval(box).className = 'fotoboek_thumb';
				}

	}

		//disable/enable next and prev btns
		if(curFoto==0)
			prevBtn.src = 'image/fotolinksuit.jpg';
		else
			prevBtn.src = 'image/fotolinks.jpg';

        if(curFoto==(photoCount-1))
        {
			slideShowStartStop();
			nextBtn.src = 'image/fotorechtsuit.jpg';
		}
		else
			nextBtn.src = 'image/fotorechts.jpg';
	}

	function opacity(id, opacStart, opacEnd, millisec) {
		var speed = Math.round(millisec / 100);
    	var timer = 0;

	    if(opacStart > opacEnd) {
	        for(i = opacStart; i >= opacEnd; i=i-10) {
			    setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
	            timer++;
	        }
	    } else if(opacStart < opacEnd) {
	        for(i = opacStart; i <= opacEnd; i=i+10)
	            {
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
	            timer++;
	        }
	    }
	}

	function changeOpac(opacity, id) {
	    thisPhotoBox.style.opacity = (opacity / 100);
	    thisPhotoBox.style.MozOpacity = (opacity / 100);
	    thisPhotoBox.style.KhtmlOpacity = (opacity / 100);
	    thisPhotoBox.style.filter = "alpha(opacity=" + opacity + ")";
	}




	function slideShowStartStop()
	{
	   	
		if(timeoutFadeOut!=null)
		 	clearTimeout(timeoutFadeOut);
		 if(timeoutNextPhoto!=null)
		 	clearTimeout(timeoutNextPhoto);

		if(slideActive)
	   	{
		   	slideActive = false;
			clearTimeout(timeoutNextPhoto);
			startBtn.value = 'Start slideshow';
		}
		else
		{
			slideActive = true;
			startBtn.value = 'Stop slideshow';
            showNext(false);
		}
	}


	function slideShowNavigate(id)
	{
		 if(timeoutFadeOut!=null)
		 	clearTimeout(timeoutFadeOut);
		 if(timeoutNextPhoto!=null)
		 	clearTimeout(timeoutNextPhoto);
		 
		 curFoto--;

		 if(curFoto<2)
		     curFoto += (2-curFoto)+id;
		 else if(curFoto>(photoCount-3))
			 curFoto += (id-(2-((photoCount-1)-curFoto)));
		 else
		 	curFoto += id;

		 showNext(true);

	}
	
	function slideShowNavigateNextPrev(id)
	{
		curFoto--;

		if(timeoutFadeOut!=null)
		 	clearTimeout(timeoutFadeOut);
		 if(timeoutNextPhoto!=null)
		 	clearTimeout(timeoutNextPhoto);

		curFoto += id;
		showNext(true);
	}
