var slideshow;
var currentIndex; 
dojo.addOnLoad(function() {
    slideshow = new atemi.widget.Slideshow('eventPosters', {
        duration: 5000,
        transitionInterval: 300,
        transitionMode: 'down'
    });

    dojo.connect(slideshow, "focusWillChange", function(focusIndex) {
        dojo.query("#eventThumbs a").forEach(function(element) {
            dojo.removeClass(element,"current");
        });
    });
    var thumbs = dojo.query("#eventThumbs a");
    dojo.connect(slideshow, "focusDidChange", function(focusIndex) {
        currentIndex = focusIndex;
        // The thumbs in this case are backwards, index from the back.
        thumbs.slice(thumbs.length-focusIndex-1, thumbs.length-focusIndex).addClass("current");
    });

    thumbs.forEach(function(node, index) {
        dojo.connect(node, "onclick", function(event) {
            dojo.stopEvent(event);
            slideshow.setFocusIndex(thumbs.length - index - 1, true);
        });
    });

    if (thumbs.length > 1) {
        // slideshow.setNavigator('slideshow_nav');
        slideshow.play();
        dojo.query("#eventSwitcher").connect("onmouseenter", function(event) {
            dojo.animateProperty({
                node: "eventThumbs",
                properties: { bottom: 5 }
            }).play();

        });
        dojo.query("#eventSwitcher").connect("onmouseleave", function(event) {
            dojo.animateProperty({
                node: "eventThumbs",
                properties: { bottom: -45 }
            }).play();
        });
    }
});

