function CtaGallery(cta_container) {
    var ctas = [];
    var cta_index = 0;
    var container = cta_container;
    var animation_timeout = 0;
    var animation_delay = 3000;

    this.add = function(url, image) {
        var cta = {};
        cta['url'] = url;
        cta['image'] = image;
        ctas.push(cta);
    };

    this.run = function() {
        this.update();
        $(container).fadeIn();
        if (!this.hasCtas()) {
            return;
        }
        this.hide();
    };

    this.hide = function() {
        var gallery = this;
        $(container).delay(animation_delay).fadeOut('slow', function() {
                gallery.update();
                gallery.show();
            }
        );
    };

    this.update = function() {
        var cta = ctas[cta_index];
        $(container).html("<a href='" + cta.url + "'><img src='/static/uploads/" + cta.image + "'></a>");
        this.updateCtaIndex();
    };

    this.show = function() {
        var gallery = this;
        $(container).fadeIn('slow', function() {
                gallery.hide();
            });
    };

    this.hasCtas = function() {
        return ctas.length > 1;
    }; 

    this.updateCtaIndex = function() {
        cta_index++;
        if (cta_index == ctas.length) {
            cta_index = 0;
        }
    };
}

