﻿function slideshow() {
    //Set the opacity of all images to 0
    $('#gallery div').css("display", "none");

    //Get the first image and display it (set it to full opacity)
    $('#gallery div:first').css("display", "block");

    //Set the opacity of all images to 0
    $('#galleryText div').css("display", "none");

    //Get the first image and display it (set it to full opacity)
    $('#galleryText div:first').css("display", "block");
		
}

function rotateGallery(direction) {
    gallery('#gallery', direction);
    gallery('#galleryText', direction);
}

rotateSwitch = function(){
    play = setInterval(function(){ 
	gallery('#gallery', 'next');
	}, 10000); //Timer speed in milliseconds (5 seconds)
};


function gallery(id, direction) {
    //if no IMGs have the show class, grab the first image
    var next = $(id + ' div:first');
    var current = ($(id + ' div.show') ? $(id + ' div.show') : $(id + ' div:first'));

    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    if (direction == "prev") {
        next = (current.prev().length ? current.prev() : $(id + ' div:last'));
    } else {
        next = (current.next().length ? current.next() : $(id + ' div:first'));
    }

    //remove current
    current.animate({ opacity: 0.0 }, 700, "linear", function () {
        hideCurrent(current);
        showNext(next);
    });

//    current.css("display", "none");
//    current.removeClass('show');

//    //show next
//    next.css({ opacity: 0.0 })
//    next.css("display", "block");
//    next.addClass('show');
//    next.animate({ opacity: 1.0 }, 2000);

}

function hideCurrent(id) {
    var current = id;
    current.css("display", "none");
    current.removeClass('show');
}

function showNext(id){
    var next = id;
    next.css({ opacity: 0.0 })
    next.css("display", "block");
    next.addClass('show');
    next.animate({ opacity: 1.0 }, 1000);
}


function galleryText(id, direction) {
    //if no IMGs have the show class, grab the first image
    var next = $(id + ' div:first');
    var current = ($(id + ' div.show') ? $(id + ' div.show') : $(id + ' div:first'));

    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    if (direction == "prev") {
        next = (current.prev().length ? current.prev() : $(id + ' div:last'));
    } else {
        next = (current.next().length ? current.next() : $(id + ' div:first'));
    }

    //remove current
    current.css("display", "none");
    current.removeClass('show');

    //show next
    next.css({ opacity: 0.0 })
    next.css("display", "block");
    next.addClass('show');
    next.animate({ opacity: 1.0 }, 0);

}


rotateSwitch(); //Run function on launch



