﻿var pic = "";
var t;
var delay = 4000;
var noDoubles = 0;//avoid having two timeouts running
//set the highest and lowest gallery picture numbers below
var highNum = 22;
var lowNum = 11;
var a = lowNum - 1;
var whichFolder = "image2/winterLand/img";

var whNum = (Math.floor(Math.random() * (highNum - 10)) + 11); var whLtr = whNum.toString();
var randomPic = '<img style="max-width:800px;" src="' + whichFolder + whLtr + '.jpg"' + ' \/>';
t1 = setTimeout("document.getElementById('pictureHolder').innerHTML = randomPic", 3000);
var origPic = '<img src="images/ws-lake-crop.jpg" \/>';
t3 = setTimeout("document.getElementById('pictureHolder').innerHTML = origPic", 6000);

window.onload = function() {
    document.getElementById('ButtonDown').onclick = stepDown;
    document.getElementById('ButtonUp').onclick = stepUp;
    document.getElementById('ButtonPlay').onclick = showPic;
    document.getElementById('ButtonSlow').onclick = slower;
    document.getElementById('ButtonFast').onclick = faster;
}
function showPic() {
    if (document.getElementById("ButtonPlay").value == "Play") {
        window.scroll(0, 195);
    }
    if (noDoubles == 0) {
        //make sure no timers are running
        clearTimeout(t);
        clearTimeout(t1);
        clearTimeout(t3);
        noDoubles = 1;
        document.getElementById("ButtonPlay").value = "Pause";
        stepPic();
    }
    else {
        stopShow();
    }
}
function faster() {
    delay = delay / 2;
    if (delay <= 500) {
        delay = 500;
    }
}
function slower() {
    delay = delay * 2;
}

function stepPic() {
    a++;
    if (a > highNum) {
        a = lowNum;
    }
    putPic();
    t = setTimeout("stepPic()", delay);
}

function stepUp() {
    stopShow();
    a++;
    if (a > highNum) {
        a = lowNum;
    }
    putPic();
}
function stepDown() {
    stopShow();
    a--;
    if (a < lowNum) {
        a = highNum;
    }
    putPic();
}
function stopShow() {
    //make sure no timers are running
    clearTimeout(t);
    clearTimeout(t1);
    clearTimeout(t3);
    noDoubles = 0;
    document.getElementById("ButtonPlay").value = "Play";
}
function putPic() {
    pic = '<img style="max-width:800px;" src="' + whichFolder + a.toString() + '.jpg"' + ' \/>';
    document.getElementById("pictureHolder").innerHTML = pic;
}

