﻿var Banners = new Class({
    initialize: function(container) {
        this.container = container;
        this.banners = [];
        this.index = 0;
        this.interval = 38000;
    },
    add: function(img, url, newWindow) {
        var b = {};
        b.img = img;
        b.url = url;
        b.newWindow = newWindow;
        this.banners[this.banners.length] = b;
    },
    start: function() {
        var rotate = function() {
            this.index++;
            if (this.index >= this.banners.length) this.index = 0;
            this.container.empty();
            
            var b = this.banners[this.index];
            new Element('img', { 'src': b.img, 'styles': { 'border': 'none' }}).inject(
                new Element('a', { 'href': b.url, 'target': b.newWindow ? '_blank' : '_self' }).inject(this.container));
        }.bind(this);
        rotate.periodical(this.interval, rotate);
    }
});
