/*
Script by FPMC at http://jsarchive.8m.com
Submitted to JavaScript Kit (http://javascriptkit.com)
For this and 400+ free scripts, visit http://javascriptkit.com
*/

//set image paths
var src = [
    ];

//set corresponding urls
var url = [
];
      

//set duration for each image
var duration = 5;

// counter
var ct=0;

// store the id of the timeout so we can stop the slideshow
var timeoutId=0;

// play the slideshow by default
var playShow = 1;

// don't repeat the show by default
// set to a negative number to repeat forever
// set to a positive number to repeat the show that many times
var repeatShow = 0;

function fadeImage() {
    var n=(ct+1)%src.length;
    crossfade(document.getElementById('showimg'), src[n], '2', 'next');

    if (n == 0) {
        if (repeatShow == 0) {
            playShow = 0;
        }
        --repeatShow;
    }

    if (playShow) {
        timeoutId = setTimeout("fadeImage()",duration*1000);
    }
    ct += 1;
}

// start a new slideshow
function startShow() {
    ct=0;
    src = [];
    for (i=1 ; i<= 51 ; i++) {
        var output = '';
        if (i < 10) {
            output = '0';
        }
        output += i;
        src[i] = "http://dagnall.net/images/slideshow/ss_" + output + '.jpg';
    }
    fadeImage();
}

// stop the slideshow, clearning any existing timeout
function stopShow() {
    clearTimeout(timeoutId);
    playShow = 0;
    repeatShow = 0;
}

// Load a new collection of images, restart the slideshow
function setImages(newImages) {
    src = newImages;
    startShow();
}

