//---------------------------------------------------
//All for the image slideshow
//---------------------------------------------------
	
	var iStep = 5;  //the % of fading for each step
    var iSpeed = 100; //the iSpeed in ms
    var iPause = 5000; //how long should the current image stay without fading
	var nOpac = 0; //start opacity
	var opacity = 0;
	var images = new Array();
	var currentImg = 1;
	var prevImg = 0;
	
	var bRandom = 0
	
	var currentTimeout = 0;
	
	var imgbot;
	var imgtop;

	function startShow(_iStep, _iSpeed, _iPause, _bRandom){
		//Set the fade patameters
		bRandom = _bRandom;
		iStep = _iStep;
		iSpeed = _iSpeed;
		iPause = _iPause;
		
		//test for new browsers
		if(document.getElementById){
			loadImages();
			if (images.length > 0){
				initShow();	
				loadFirstImgs();
				setTimeout('iPauseFadeImg()',iPause);
			}
		}
	}

	function loadFirstImgs(){
			imgbot = document.getElementById('imgbot');
			imgtop = document.getElementById('imgtop');
			//Set to random image
			if (bRandom == 1){
			var ran_unrounded = Math.random() * images.length;
			currentImg = Math.floor(ran_unrounded);
			nextImage();
			}
			//Set the top image to this random image		
			imgtop.src = images[prevImg];	
			//calculate what the nex image will be
			nextImage(); 		
	}
    
    function initShow(){
    		nOpac = 100;
			opacity = nOpac;
    }
    	
    function iPauseFadeImg()	{
        //Set lower image to new image
        imgbot.src = images[currentImg];
    	setTimeout('FadeImg()',iSpeed);
    }
    	
    function resetTopImg(){
    //Reset the opacity for top image to 100%
        initShow();
        setOpacity (imgtop); 
    }
    	
    function FadeImg(){
    	
        //lower opacity
        opacity = nOpac-iStep;
        nOpac = opacity;
        
        //Set the timer to change the opacity
        currentTimeout = setTimeout('FadeImg()',iSpeed);         

        if(opacity < 1){
        	clearTimeout(currentTimeout);
        	//The top image has opacity 0 now so; Set top image to lower image
        	//Both images are the same now
            nextImage();        	
            imgtop.src = images[prevImg];
            setTimeout('resetTopImg()',iPause/2); 
            setTimeout('iPauseFadeImg()',iPause);   
        }
		//Lower opacity of top image
      	setOpacity (imgtop)
    }
       

    function nextImage(){
    	prevImg = currentImg;
    	currentImg = currentImg + 1;
    	if (currentImg > images.length -1){
    		currentImg = 0;
    	}
    	
    }

    function setOpacity (obj){
        obj.style.opacity = opacity / 100;
        obj.style.MozOpacity = opacity / 100;
        obj.style.filter = "alpha(opacity=" + opacity + ")"; 
    }
