﻿var OfferMessageController = Class.create({
    initialize: function(count) {
        this.index = 0;
        this.count = count;
    },

    getHideShowIndex: function() {
        var hideIndex = this.index;
        this.index++;
        if (this.index >= this.count) {
            this.index = 0;
        }
        return { "hide": hideIndex, "show": this.index };
    },

    start: function() {
        var _self = this;
        setInterval(function() { _self.loadNextMessage() }, (10 * 1000));
    },

    loadNextMessage: function() {
        var index = this.getHideShowIndex();
        this.fadeOut(index.hide);
        this.fadeIn(index.show);
    },

    fadeOut: function(hide) {
        Effect.Fade($('OfferMessage' + hide), { duration: 1, from: 1.0, to: 0.0, queue: 'end' });
    },

    fadeIn: function(show) {
        Effect.Appear($('OfferMessage' + show), { duration: 1, from: 0.0, to: 1.0, queue: 'end' });
    }
});
