﻿var fadeStep=2; 
var fadeInterval=50;
var readingTime=3000;
var maxTrans=100;
var imagepersetcount = 4;


var images=new Array(); 
for(i = 0; i<setCount; i++){ 
    images[i] = new Array();
    for(j = 0; j < imagepersetcount; j++){          
        images[i][j] = "slideshowImages/" + "s" + i + "i"+ j +".gif";   
    }
}
for(i = 0; i<setCount; i++){ 
    images[i].sort(function() {return 0.5 - Math.random();});
}
images.sort(function() {return 0.5 - Math.random();});
var currTransp=maxTrans; 
var currDir=0; 
var currNum=0;
function nextSlide() 
{   
    currNum++; 
    if(currNum == images.length) 
    { 
        currNum=0; 
    } 
    for(j = 0; j < imagepersetcount; j++){
        document.getElementById("disp-slide"+j).src=images[currNum][j];     
    }
}
function prevSlide() 
{ 
    currNum--; 
    if(currNum == -1) 
    { 
        currNum=images.length-1; 
    } 
    for(j = 0; j < imagepersetcount; j++){
        document.getElementById("disp-slide"+j).src=images[currNum][j]; 
    }
} 
var john;
function fadeSlide() 
{    
    window.clearTimeout(john); 
    if(currTransp <= 0) 
    { 
        currTransp = 0; 
    } 
    if(currTransp >= maxTrans) 
    { 
        currTransp=maxTrans; 
    } 
    if(currDir==0 && currTransp > 0) 
    { 
        currTransp=currTransp-fadeStep;   
        for(j = 0; j < imagepersetcount; j++){
           setSlideTransparency(j,currTransp);
        }
    }
    else if(currDir==1 && currTransp < maxTrans) 
    { 
        currTransp=currTransp+fadeStep; 
        for(j = 0; j < imagepersetcount; j++){
            setSlideTransparency(j,currTransp);
       }
    } 
    else if(currDir==0 && currTransp <= 0) 
    { 
        currDir=1; 
        nextSlide(); 
    }  
    john = window.setTimeout("fadeSlide()", fadeInterval);
    if(currDir==1 && currTransp >= maxTrans) {
        currDir=0; 
        window.clearTimeout(john);
        john = window.setTimeout("fadeSlide()", readingTime);
    }    
} 
function setSlideTransparency(sideid, trans)
{
    var crossobj = document.getElementById("disp-slide" + sideid);
    if (crossobj.filters&&crossobj.filters[0]){
        if (typeof crossobj.filters[0].opacity=="number") //if IE6+
            crossobj.filters(0).opacity=trans
        else //else if IE5.5-
            crossobj.style.filter="alpha(opacity="+trans+")"    
    }
    else if (crossobj.style.MozOpacity)
        crossobj.style.MozOpacity=trans/101
    else if (crossobj.style.KhtmlOpacity)
        crossobj.style.KhtmlOpacity=trans/100
    else if (crossobj.style.opacity&&!crossobj.filters)
        crossobj.style.opacity=trans/101
}
function commenceFade() 
{ 
    currDir=0; 
    fadeSlide();
    window.clearTimeout( startup );
} 
for(i = 0; i < imagepersetcount; i++){
    document.getElementById("disp-slide"+i).src=images[0][i]; 
    setSlideTransparency(i,maxTrans);
}
 var totalImages = setCount * imagepersetcount;
 var startup;
 var startupsecs = 0;
function startSlideshow(){
    if(loadedImageCount >= totalImages){
        startup = window.setInterval("commenceFade()", readingTime ); 
    }else {
        if(startupsecs >= 20)
        {
            startupsecs++;
            window.setTimeout('startSlideshow()', 1000);
        } else {
            startup = window.setInterval("commenceFade()", readingTime ); 
        }
    }
}
startSlideshow();

