﻿// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 5000;
var SlideShowSpeed_Wait = 60000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration_Default = 1;
var CrossFadeDuration = 1;
var CrossFadeDuration_Quick = .2;

var tss;
var jss = 0;
var pss;

var preLoad = new Array();

function loadNextImage() {
    var i=jss+1; if (i > pss) i=0;
    if (!preLoad[i]) {
        preLoad[i] = new Image();
        preLoad[i].src = Picture[i];
    }
    tss = setTimeout('SlideShowGoForNext()', SlideShowSpeed);
}

function runSlideShow(){
    //ShowPicture();
    pss = Picture.length-1;
    //tss = setTimeout('SlideShowGoForNext()', SlideShowSpeed);
    loadNextImage();
}

var opacValue=0;
var fadeTimer=null;
function fadeOutPicture(reset) {
    if (reset) opacValue=10;
    if (--opacValue<=0) {
        fadeInPicture(true);
    } else {
        document.getElementById(PictureBoxId).style.filter='alpha(opacity='+(opacValue*10)+')';
        document.getElementById(PictureBoxId).style.opacity='0.'+opacValue;
        fadeTimer = setTimeout('fadeOutPicture()', CrossFadeDuration*50);
    }
}
function fadeInPicture(reset) {
    ShowPicture();
    if (reset) opacValue=0;
    if (++opacValue>=10) {
        document.getElementById(PictureBoxId).style.filter='alpha(opacity=100)';
        document.getElementById(PictureBoxId).style.opacity=1;
        //tss = setTimeout('SlideShowGoForNext()', SlideShowSpeed);
        loadNextImage();
    } else {
        document.getElementById(PictureBoxId).style.filter='alpha(opacity='+(opacValue*10)+')';
        document.getElementById(PictureBoxId).style.opacity=(opacValue/10);
        fadeTimer = setTimeout('fadeInPicture()', CrossFadeDuration*50);
    }
}

function SlideShowGoForNext(){
    if (++jss > pss) jss=0;
    if (!document.all || preLoad[jss].readyState=='complete' || preLoad[jss].readyState=='loaded') {
        fadeOutPicture(true);
    } else {
        //tss = setTimeout('SlideShowGoForNext()', SlideShowSpeed);
        loadNextImage();
    }
}

function ShowPicture(){
    var picItem=document.getElementById('SlideListItem_'+jss);
    var lastpicItem=document.getElementById('SlideListItem_'+lastpicNumber);
    if (lastpicItem) lastpicItem.className="SlideListBoxItem";
    picItem.className="SlideListBoxItem SlideListBoxItemShown";
    lastpicNumber=jss;
    var pic=document.getElementById(PictureBoxId);
    pic.src = preLoad[jss].src;
    pic.title=Pic_Title[jss];
    document.getElementById(divPhotoTitleId).innerHTML= Pic_Title[jss];
    document.getElementById(divPhotoDescId).innerHTML= Pic_Desc[jss];
}

function SlideShowGoForThis(itemNumber) {
    clearTimeout(tss);
    clearTimeout(fadeTimer);
    jss=itemNumber;
    if (!preLoad[jss]) {
        preLoad[jss] = new Image();
        preLoad[jss].src = Picture[jss];
    }
    fadeOutPicture();
}

AddEventTo(window,'load',runSlideShow);
