var index = 0;
var photos = new Array();

function photo(image, caption) {
    this.image = path + "thumb" + image;
    this.url = path + image;
    this.caption = caption;
}

function shuffle(array) {
    var i = array.length;

    if (i == 0) return false;

    while (--i) {
        var j = Math.floor(Math.random() * (i + 1));
        var tempi = array[i];
        var tempj = array[j];
        array[i] = tempj;
        array[j] = tempi;
    }
}

var preloadedimages = new Array();

for (i = 0; i < photos.length; i++) {
    preloadedimages[i] = new Image();
    preloadedimages[i].src = photos[i].image;
}

function backward() {
    if (index <= 0) {
        index = photos.length;
    }

    if (index > 0) {
        index--;
        document.images.slider.src = photos[index].image;
        document.getElementById("imagecaption").innerHTML = photos[index].caption;
        document.getElementById('a_slider').href = photos[index].url
        document.getElementById('a_slider').rel = "lightbox";
        document.getElementById('a_slider').title = photos[index].caption;
    }
}

function forward() {
    if (index >= photos.length - 1) {
        index = -1;
    }

    if (index < photos.length - 1) {
        index++;
        document.images.slider.src = photos[index].image;
        document.getElementById("imagecaption").innerHTML = photos[index].caption;
        document.getElementById('a_slider').href = photos[index].url
        document.getElementById('a_slider').rel = "lightbox";
        document.getElementById('a_slider').title = photos[index].caption;
        document.getElementById('a_slider').className = "imgborder";
    }
}
