﻿function theRotator() {
    //Set the opacity of all images to 0
    $('div#header-slide-container ul li').css({ opacity: 0.0 });

    //Get the first image and display it (gets set to full opacity)
    $('div#header-slide-container ul li:first').css({ opacity: 1.0 });

    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds

    intervalID = setInterval('goRight()', 5000);

}
function goRight() {
    //Get the first image
    var current = ($('div#header-slide-container ul li.show') ? $('div#header-slide-container ul li.show') : $('div#header-slide-container ul li:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#header-slide-container ul li:first') : current.next()) : $('div#header-slide-container ul li:first'));

    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({ opacity: 0.0 })
	        .addClass('show')
	        .animate({ opacity: 1.0 }, 1300);

    //Hide the current image
    current.animate({ opacity: 0.0 }, 700)
	        .removeClass('show');
};
function goLeft() {
    //Get the first image
    var current = ($('div#header-slide-container ul li.show') ? $('div#header-slide-container ul li.show') : $('div#header-slide-container ul li:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var prev = ((current.prev().length) ? ((current.prev().hasClass('show')) ? $('div#header-slide-container ul li:first') : current.prev()) : $('div#header-slide-container ul li:last'));

    //Set the fade in effect for the next image, the show class has higher z-index
    prev.css({ opacity: 0.0 })
	        .addClass('show')
	        .animate({ opacity: 1.0 }, 1300);

    //Hide the current image
    current.animate({ opacity: 0.0 }, 700)
	        .removeClass('show');
};

$(document).ready(function () {
    //Load the slideshow
    $(".jFlowNext").click(function () {
        clearInterval(intervalID);
        goRight();
    });
    $(".jFlowPrev").click(function () {
        clearInterval(intervalID);
        goLeft();
    });
});
