﻿//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] = '//images/image01.jpg';
//Picture[2] = '//images/image02.jpg';
//Picture[3] = '//images/image03.jpg';
//Picture[4] = '//images/image04.jpg';
//Picture[5] = '//images/image05.jpg';
//Picture[6] = '//images/image06.jpg';

//Least number to use is 4 slides
//var totalSlideCount = 6;
//Let this value be static 3
//var currentImageNum = 3;

var Picture = new Array(); // don't change this;
//var Caption = new Array();
var totalSlideCount = 7;
var currentImageNum = 3;
Picture[1] = '/images/home1.jpg';
Picture[2] = '/images/home2.jpg';
Picture[3] = '/images/home3.jpg';
//Caption[1] = '<div class="topleft"><h1>"Vi har över 15 års erfarenhet av att jobba med Miljöbud.se och det fungerar perfekt i alla situationer" </h1><p>Lars Rydberg, Electrolux Hemprodukter </p></div><div class="bottomright"></div>';
Picture[4] = '/images/home4.jpg';
//Caption[2] = '<div class="topleft">asdasasdsdasd</div><div class="bottomright">Annars kan man ha vanlig i nedre högra hörnet som här</div>';
Picture[5] = '/images/home5.jpg';
Picture[6] = '/images/home6.jpg';
//Caption[3] = '<div class="topleft"></div><div class="bottomright"></div>';


$(document).ready(function() {
    // start slideshow
	$('#imageReel').cycle({
        fx: 'fade',
        timeout: 1000,
        before: onBefore,
        speed: 2000
});


    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
            //opts.addSlide('<img src="//images/image0' + (currentImageNum + 1) + '.jpg" />');
            opts.addSlide('<div><img src="' + Picture[currentImageNum] + '" height="400" width="900" /></div>');
            //opts.addSlide('<div>' + Caption[currentImageNum] + '</div>');
            currentImageNum = currentImageNum + 1
        }
    };
   });

