﻿//uncomment these values if no preloading action and only 2 images
//var totalSlideCount = 2;
//var currentImageNum = 2;

//var Picture = new Array(); // don't change this
//uncomment these if preloading more than 2 images
//Picture[1] = '/filer/bilder/image01.jpg';
//Picture[2] = '/filer/bilder/image02.jpg';
//Picture[3] = '/filer/bilder/image03.jpg';
//Picture[4] = '/filer/bilder/image04.jpg';
//Picture[5] = '/filer/bilder/image05.jpg';
//Picture[6] = '/filer/bilder/image06.jpg';

//Least number to use is 4 slides
//var totalSlideCount = 6;
//Let this value be static 3
//var currentImageNum = 3;

$(document).ready(function() {
    // start slideshow
    $('#slideshow').cycle({
        fx: 'fade',
        timeout: 6000,
        before: onBefore       
    });
    
    function onBefore(curr, next, opts) {
        //Check if there are more than 2 images presented
        if (totalSlideCount > 2) {
            // on the first pass, addSlide is undefined (plugin hasn't yet created the fn);
            // when we're finshed adding slides we'll null it out again
            if (!opts.addSlide)
                return;

            // on Before arguments: 
            //  curr == DOM element for the slide that is currently being displayed 
            //  next == DOM element for the slide that is about to be displayed 
            //  opts == slideshow options

            //var currentImageNum = parseInt(next.src.match(/image0(\d)/)[1]);
            if (currentImageNum == totalSlideCount) {
                // final slide in our slide slideshow is about to be displayed 
                // so there are no more to fetch
                opts.addSlide = null;
                currentImageNum = 1
                return;
            }
            // add our next slide
            currentImageNum = currentImageNum + 1     
            opts.addSlide(Slide[currentImageNum]);
                         
           
        }
    };
});




