﻿

var slideShowClass = {
    // properties
    // time to wait between slides
    autoTransitionWait: 5,
    // element that holds the slideshow
    container: '',
    // list of contents
    contents: '',
    // element that holds the current content
    currentContentContainer: '',
    // index of the active content
    currentContentIndex: 0,
    // element that holds the next content
    nextContentContainer: '',
    // functions
    // used to initialize contents into their containers
    // called once at the beginning
    InitializeTransition: function() { },
    // used to get the index of the next content
    NextContentIndex: function(slideshow) {
        var temp = slideshow.currentContentIndex + 1;
        if (temp >= slideshow.contents.length)
            temp = 0;
        return temp;
    },
    // used to move between the current div and the next
    PerformTransition: function() { },
    // used to run the slide show
    StartSlideShow: function(slideshow, slideShowVarName) {
        slideshow.InitializeTransition();
        if (window[slideShowVarName].contents.length > 0)
            setInterval('onTimerEvent(function() {'
                + slideShowVarName + '.currentContentIndex = '
                    + slideShowVarName + '.NextContentIndex(' + slideShowVarName + ');'
                + slideShowVarName + '.PerformTransition();'
                + '})', slideshow.autoTransitionWait * 1000);
    }
};

function onTimerEvent(callback) {
    if (!this.isExecuting) {
      try {
        this.isExecuting = true;
        callback();
      } finally {
        this.isExecuting = false;
      }
    }
}
