﻿$(document).ready(function() {
    // Setup the fontpage slideshow by using the Cycle Lite plugin    
    SetupFronpageSlideshow();
});

var once = onlyShowOnce;
var syncsetting = 0;
var pausesetting = 0;
var speedsetting = speed;

function SetupFronpageSlideshow() {

    // If the first image in the slideshow should only be showed once, we need to run the slideshow once, remove the image and start a new slideshow
    if (once == 1) {        
        $("#CaseSlideshow").cycle({
            timeout: generalDelay,
            speed: speedsetting,
            delay: startDelay,
            pause: pausesetting,
            sync: syncsetting,
            nowrap: 1,
            end: function() {
                $("#CaseSlideshow").children("a").each(function() {
                    if ($(this).hasClass("ShowOnce"))
                        $(this).remove();
                });
                $("#CaseSlideshow").children("a:last").fadeOut((speedsetting - 500));
                setTimeout("StartSecondSlideshow();", (speedsetting-500));
            }
        });
    }
    else {        
        $("#CaseSlideshow").cycle({
            timeout: generalDelay,
            speed: speedsetting,
            delay: startDelay,
            pause: pausesetting,
            sync: syncsetting
        });
    }        
}

function StartSecondSlideshow() {    
    $("#CaseSlideshow").children("a:first").css("opacity", "");
    $("#CaseSlideshow").children("a:first").fadeIn((speedsetting-500));
    $("#CaseSlideshow").cycle({
        timeout: generalDelay,
        speed: speedsetting,
        delay: 0,
        pause: pausesetting,
        sync: syncsetting
    });       
}