﻿var currentIndex = -1;

var timer;
var status = "play";
var fadeInterval = 6000;

if (document.images) {
    var i = 0;
    for (i = 0; i < leftimagearray.length; i++) {
        var Limg = new Image(500, 500);
        var Rimg = new Image(500, 500);
        Limg.src = leftimagearray[i];
        Rimg.src = rightimagearray[i];
    }
}

NextImage();

function NextImage() {
    clearTimeout(timer);
    $("#oldLeftImage").attr("src", $("#newLeftImage").attr("src"));
    $("#oldRightImage").attr("src", $("#newRightImage").attr("src"));
    $("#newLeftImage, #newRightImage").hide();

    if ((currentIndex + 1) == leftimagearray.length) {
        currentIndex = 0;
    } else {
        currentIndex++;
    }

    SetSlide();
    timer = setTimeout(NextImage, fadeInterval);
}

function PrevImage() {
    clearTimeout(timer);
    $("#oldLeftImage").attr("src", $("#newLeftImage").attr("src"));
    $("#oldRightImage").attr("src", $("#newRightImage").attr("src"));

    $("#newLeftImage, #newRightImage").hide();

    if (currentIndex == 0) {
        currentIndex = leftimagearray.length - 1;
    } else {
        currentIndex--;
    }
    SetSlide();
    timer = setTimeout(NextImage, fadeInterval);
   
}

function SetSlide() {
    $("#newLeftImage").attr("src", leftimagearray[currentIndex]);
    $("#newRightImage").attr("src", rightimagearray[currentIndex]);
    $("#newLeftImage, #newRightImage").fadeIn(1000);
    $("#leftLink").attr("href", leftlinkarray[currentIndex]);
    $("#rightTopLink").attr("href", righttoplinkarray[currentIndex]);
    $("#rightBottomLink").attr("href", rightbottomlinkarray[currentIndex]);
    $("#slideshowTitle").html(titlearray[currentIndex]);
}

function PlayPause() {
    if (status == "play") {
        status = "pause";
        clearTimeout(timer);
        $("#playpause span").html("Play");
    } else {
        status = "play";
        timer = setTimeout(NextImage, fadeInterval);
        $("#playpause span").html("Pause");
    }
    $("#playpause img").attr("src","/images/slideshow_" + status + ".gif");
}
