/*********************
Author: Timothy Grindall
Copyright: Timothy Grindall, 2008

Liscense: GNU Public Liscense. Note: if you don't know what the GNU public liscense is, you can probably find out by searching in Wikipedia at "http://www.wikipedia.org". A GNU Public Liscense basically means that you can use this code in any way you like as long as you don't sell the whole or any part of it in the original javascript or in a translated and/or compiled form.

Credits: This script is based on a slideshow script from the book "Javascript for the World Wide Web, Fifth Edition, Visual Quickstart Guide" by Tom Negrino and Dori Smith (ISBN 0-321-19439-X), but with magor enhancements allowing the gallery to autoplay.

Captions are as follows:

    Photo #1 “Light the paper edge”
    
    Photo #2 “Place under full sized logs”
    
    Photo #3 “4-6 min.- the logs have ignited”
    
    Photo #4 “8-11 min.- the logs are fully engaged”
    
    Photo #5 “15 Min.- you can still see the fire starter hard at work”
    
    Photo #6 “Grizzly Firestarters will continue to burn for <span style="text-decoration: underline;">over 20 minutes!</span>"

*********************/

myPix = new Array("graphics/gallery/image0.jpg", "graphics/gallery/image1.jpg","graphics/gallery/image2.jpg","graphics/gallery/image3.jpg","graphics/gallery/image4.jpg","graphics/gallery/image5.jpg", "graphics/gallery/endof.gif");
myCaption = new Array("Light the paper edge", "Place under full sized logs", "4-6 min.- the logs have ignited", "8-11 min.- the logs are fully engaged", "15 Min.- you can still see the fire starter hard at work", "Grizzly Firestarters will continue to burn for <span style=\"text-decoration: underline;\">over 20 minutes!</span>", "... end of gallery");
thisPic = 0
imgCt = myPix.length - 1
active = true;  // variable for storing the state of the gallery, on or off
end = false;    // variable for remembering if we are at the end of the gallery or not, whether we restart next time or not
pushed = false; // variable for remembering if a button has been pushed recently, whether to allow autoplay next time or not
verbose = false;// variable for turning reporting text on or off...

function processPrevious() {
    if (document.images && thisPic > 0) {
        thisPic--
        document.GalleryCenter.src=myPix[thisPic];
        document.getElementById("caption").innerHTML = myCaption[thisPic];
        
        if (thisPic == 0) document.GalleryLeft.src=myPix[(myPix.length-1)];
        else document.GalleryLeft.src=myPix[(thisPic-1)];
        document.GalleryRight.src=myPix[(thisPic+1)];
        pushed = true;
        check();
    }
}

function processNext() {
    if (document.images && thisPic < imgCt) {
        thisPic++
        if (thisPic == myPix.length-1) {
            thisPic--
        }
        else {
            document.GalleryCenter.src=myPix[thisPic];
            document.GalleryLeft.src=myPix[(thisPic-1)];
            document.GalleryRight.src=myPix[(thisPic+1)];
            document.getElementById("caption").innerHTML = myCaption[thisPic];
        }
        pushed = true;
        check();
    }
}

function restart() {
    if (document.images) {
        thisPic = 0
        document.GalleryCenter.src=myPix[thisPic];
        document.GalleryLeft.src=myPix[(myPix.length-1)];
        document.GalleryRight.src=myPix[(thisPic+1)];
        document.getElementById("caption").innerHTML = myCaption[thisPic];
        pushed = true;
        check();
    }
}

function autoplay() {
    if (document.images) {
        if (pushed == false) {
            /* alert("autoplay()"); */
            if (end == true) restart(); // if we are at the end, restart
            else processNext();         // else, continue
            if (thisPic == myPix.length-2) end = true;   // if we are at the end, set the restart state to true so we restart next time
            else end = false;                             // else, set it to false (otherwise it'll stay set true from last time we restarted
            pause();
        }
        if (pushed == true) pushed = false;
        check();
        setTimeout("autoplay()", 5 * 1000) // every five second(s)
    }
}

function pause() {
    if (verbose == true) {
        if (document.getElementById("debug")) document.getElementById("debug").innerHTML = "inactive " + thisPic + "<br />" + myPix.length + "<br />end: " + end + "<br />pushed: " + pushed;    // set debug text
        else alert("debug not found");
    }
    active = false;
    /* alert("pause() set:" + active); */
    setTimeout("unpause()", 0.25 * 1000) // wait half a second before activating again
}

function unpause() {
    if (verbose == true) {
        if (document.getElementById("debug")) document.getElementById("debug").innerHTML = "active.. " + thisPic + "<br />" + myPix.length + "<br />end: " + end + "<br />pushed: " + pushed;    // set debug text
        else alert("debug not found");
    }
    active = true;
    /* alert("unpause() set:" + active); */
}

function check() {
    if (verbose == true) {
        if (document.getElementById("debug")) document.getElementById("debug").innerHTML = "active.. " + thisPic + "<br />" + myPix.length + "<br />end: " + end + "<br />pushed: " + pushed + "<br />check";    // set debug text
        else alert("debug not found");
    }
}

/* function init() {
    // initialize caption
    document.getElementById("caption").innerHTML = myCaption[thisPic];
    alert("done");
} */