$(document).ready(function() {
    TA.init();
});

// TA: Tiger Advertising

var TA = function () {

    // private

    var i = 0;
    var timerId;
    var duration = 1000; // animation duration
    var delay = 7000; // delay between slides

    var slides = [
        { image: "images/xerox.png", banner: "images/banner-1.png" },
        { image: "images/fujifilm.png", banner: "images/banner-2.png" }
    ];

    function onColorboxClosed() {
        timerId = setTimeout(nextSlide, delay);
    }

    function onColorboxOpen() {
        clearTimeout(timerId);
    }

    function nextSlide() {
        if (slides.length > 0) {
            i = ++i % slides.length;
            clearTimeout(timerId);
            var slide = slides[i];
            $("#header").fadeOut(duration, function() {
                $("#header").css("background-image", "url(" + slide["image"] + ")");
                $("#banner").attr("src", slide["banner"]);
            });
            $("#header").fadeIn(duration, function() {
                timerId = setTimeout(nextSlide, delay);
            });
        }
    }

    // public

    return {
        init: function () {
            timerId = setTimeout(nextSlide, delay);
            $("a[rel='slide-pictures'], a[rel='slide-graphics']").colorbox({
                onClosed: onColorboxClosed,
                onOpen: onColorboxOpen,
                scrolling: false,
                speed: 1000
            });
        }
    };
}();

