var g_currentIssue = 0;
var g_timeout = 0;
var g_delaySeconds = 7;
var g_wrapper1 = 0;
var g_wrapper2 = 0;
var g_active = 1;
var g_indexForeground = 100;
var g_indexBackground = 50;


function startSlideshow()
{
    g_wrapper1 = document.getElementById("slideshowWrapper1");
    g_wrapper2 = document.getElementById("slideshowWrapper2");

    g_timeout = setTimeout("runSlideshow()", g_delaySeconds * 1000);
}

function runSlideshow()
{
    g_currentIssue++;

    if (g_currentIssue >= covers.length) {
        resetSlideshow();
    }
    else {
        swapDisplay();
        setInactiveTo(g_currentIssue + 1);
    }

    g_timeout = setTimeout("runSlideshow()", g_delaySeconds * 1000);
}

function resetSlideshow()
{
    g_currentIssue = 0;
    g_active = 1;
    g_wrapper1.innerHTML = covers[g_currentIssue];
    g_wrapper2.innerHTML = covers[g_currentIssue + 1];
    g_wrapper1.style.zIndex = g_indexForeground;
    g_wrapper2.style.zIndex = g_indexBackground;
}

function setInactiveTo(n)
{
    if (g_active == 1) {
        g_wrapper2.innerHTML = covers[n];
    }
    else {
        g_wrapper1.innerHTML = covers[n];
    }
}

function swapDisplay()
{
    if (g_active == 1) {
        g_wrapper1.style.zIndex = g_indexBackground;
        g_wrapper2.style.zIndex = g_indexForeground;
        g_active = 2;
    }
    else {
        g_wrapper1.style.zIndex = g_indexForeground;
        g_wrapper2.style.zIndex = g_indexBackground;
        g_active = 1;
    }
}
