﻿document.observe("dom:loaded", function() {

    new PeriodicalExecuter(function(pe) {
        var currentAward = $$('#awards div.current')[0];
        if (currentAward != null) {
            var nextAward = currentAward.next();
            if (nextAward == null) {
                nextAward = $$('#awards div.award')[0];
            }
            currentAward.removeClassName('current');
            nextAward.addClassName('current');
            Effect.Fade(currentAward, { duration: 1.5, from: 1, to: 0, queue: 'front' });
            Effect.Appear(nextAward, { duration: 1.5, from: 0, to: 1, queue: 'end' });
        }
    }, 5);

    var spots = $$('div.spot');

    $$('a.prev', 'a.next').each(function(el) {
        el.observe('click', function(ev) {
            ev.stop();
            var currentSpot = el.up('.spot');
            var nextSpot;
            if (el.hasClassName('prev')) {
                nextSpot = currentSpot.previous('.spot');
                if (nextSpot == null) {
                    nextSpot = spots[spots.length - 1];
                }
            } else {
                nextSpot = currentSpot.next('.spot');
                if (nextSpot == null) {
                    nextSpot = spots[0];
                }
            }

            if (nextSpot != null) {
                currentSpot.hide();
                nextSpot.show();
            }
        });
    });
});