/* Javescript Slideshow, version 1.2
 * Author: Tu Tak Tran 
 * Adapted from: http://snippets.dzone.com/posts/show/1068
 *  
 * A javascript image slideshow
 *
 * Requires: prototype.js and scriptaculous.js
/*--------------------------------------------------------------------------*/

start_slideshow(1, JSS_NUMBER_OF_SLIDES, JSS_SLIDE_DELAY * 1000);

function start_slideshow(start_frame, end_frame, delay) {
    setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
}
/*
var JSS_TRANSITION_TIME = 1; //0.85; // In seconds
function switch_slides(frame, start_frame, end_frame, delay) {
    return (function() {
        Effect.Fade('slideshow' + frame);

        if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
        setTimeout("Effect.Appear('slideshow" + frame + "');",
            JSS_TRANSITION_TIME * 1000);
        setTimeout(switch_slides(frame, start_frame, end_frame, delay),
            delay + JSS_TRANSITION_TIME * 1000);
    })
}
*/

// Can control the duration of transition, but looks more jagged

var JSS_TRANS_DURATION = 6; // Time (seconds) to fade in and then fade out
// If there is overlap, the scroll bar flickers on the screen
var JSS_OVERLAP_PERIOD = 0;//0.15; // Overlap time (seconds) between fade out and in

function switch_slides(frame, start_frame, end_frame, delay) {
    return (function() {
        var transTime = JSS_TRANS_DURATION / 2; // Transition time (seconds) for fading in or out

        Effect.Fade('slideshow' + frame, {duration: transTime});

        if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
        setTimeout("Effect.Appear('slideshow" + frame +
              "', {duration:" + transTime + "});",
              (transTime * 1000) - (JSS_OVERLAP_PERIOD * 1000));
        setTimeout(switch_slides(frame, start_frame, end_frame, delay),
            delay + (transTime * 1000) - (JSS_OVERLAP_PERIOD * 1000));
    })
}
