var Slideshow = {
    stopped: false,
    // setup class and bind events
    init: function() {
        Slideshow.$active = $("#headerSlideshow IMG.active");
        if (Slideshow.$active.length == 0 ) {
            Slideshow.$active = $("#headerSlideshow IMG:last");
        }
        // attack event to "back"-button (stops autoplay and selects previous image)
        $("#slideshowBack").click(function(event){
            event.preventDefault();
            $("#headerSlideshow img").stop(false, true);
            Slideshow.stopped = true;
            Slideshow.showPrevious();
        });
        // attack event to "forth"-button (stops autoplay and selects next image)
        $("#slideshowForth").click(function(event){
            event.preventDefault();
            $("#headerSlideshow img").stop(false, true);
            Slideshow.stopped = true;
            Slideshow.showNext();
        });
    },
    // go to next image
    showNext: function() {
        Slideshow.$next =  Slideshow.$active.next("img").length ? Slideshow.$active.next("img") : $("#headerSlideshow IMG:first");
        Slideshow.$active.addClass("last-active");
        Slideshow.$next.css({opacity: 0.0})
            .addClass("active")
            .animate({opacity: 1.0}, 1000, function() {
                Slideshow.$active.removeClass("active last-active");
                Slideshow.$active = Slideshow.$next;
            });
        if (!Slideshow.stopped) {
            window.setTimeout(function(){
                Slideshow.showNext();
            }, 5000);
        }
    },
    // go to previous image
    showPrevious: function() {
        Slideshow.$previous =  Slideshow.$active.prev("img").length ? Slideshow.$active.prev("img") : $("#headerSlideshow IMG:last");
        Slideshow.$active.addClass("last-active");
        Slideshow.$previous.css({opacity: 0.0})
            .addClass("active")
            .animate({opacity: 1.0}, 1000, function() {
                Slideshow.$active.removeClass("active last-active");
                Slideshow.$active = Slideshow.$previous;
            });
    },
    // start autoplay
    autoplay: function() {
        Slideshow.init();
        window.setTimeout(function(){
            Slideshow.showNext();
        }, 5000);
    }
}

var BrandsTicker = {
    xValue: 0,
    init: function() {
        BrandsTicker.go();
    },
    go: function() {
        window.setTimeout(function(){
            BrandsTicker.xValue+=1;
            $("#brandsTicker").css("backgroundPosition", BrandsTicker.xValue + "px 0");
            BrandsTicker.go();
        }, 25);
    }
}

// jQuery Ready-Handler
$(function() {


});

