﻿var TextSwapper = new Class({
    Implements: [Options],
    options: {
        element: null,
        selector: 'div'
    },
    currentIndex: 0,

    initialize: function(options) {
        this.setOptions(options);
        this.setup();
    },

    next: function() {
        this.currentIndex++;
        if (this.currentIndex > this.divs.length - 1) {
            this.currentIndex = 0;
        }
        this.display();

    },

    previous: function() {
        this.currentIndex--;
        if (this.currentIndex < 0) {
            this.currentIndex = this.divs.length - 1;
        }
        this.display();

    },

    display: function() {
        if (this.divs.length == 0) {
            return;
        }
        this.divs.each(function(_e) {
            _e.setStyle('display', 'none');

        });
        this.divs[this.currentIndex].setStyle('display', 'block');
    },

    setup: function() {
        this.divs = [];
        this.options.element.getElements(this.options.selector).each(function(_e) {
            this.divs.push(_e);
        }, this);

        this.display();

    }



});

var ImageSwapperTimer = new Class({
    Implements: [Options],
    options: {
        swappers: [],
        timeout: 5000

    },



    initialize: function(options) {
        this.setOptions(options);
    },

    start: function() {
        this.next.periodical(this.options.timeout, this);
    },

    next: function() {
        this.options.swappers.forEach(function(_swapper, _index) {
            _swapper.next();
        });
    }



});
