function HomePageBanners() {
}

HomePageBanners.prototype = {
    "ctrl": {
        "bigImage": null,
        "link": null
    },
    "banners": [],
    // bannerText, imageUrl, displayTime, tab, tabLink, tabText, link
    "bannersOrder": [],
    "currentBannerIndex": 0,
    "timeout": null,

    "initialize": function() {
        for (i = 0; i < this.banners.length; i++) {
            var preload = new Image(25, 25);
            preload.src = this.banners[i].imageUrl;
            this.banners[i].tabLink.innerHTML = this.banners[i].tabText;
            this.banners[this.bannersOrder[i]].tabLink.index = i;
            $addHandlers(this.banners[i].tabLink, { "click": this.buttonclick }, this);
        }
        this.setBanner();

    },
    "buttonclick": function(eventArgs) {
        if (this.timeout != null) {
            clearTimeout(this.timeout);
        }
        if (eventArgs.target.index != this.currentBannerIndex) {
            this.currentBannerIndex = eventArgs.target.index;
            this.setBanner();
        }
        else {
            location.href = this.banners[this.bannersOrder[eventArgs.target.index]].link;
        }
    },
    "nextBanner": function() {
        this.currentBannerIndex = (this.currentBannerIndex + 1) % this.banners.length;
        this.setBanner();
    },
    "setBanner": function() {
        var currentBanner = this.banners[this.bannersOrder[this.currentBannerIndex]];

        this.ctrl.link.href = currentBanner.link;
        this.ctrl.bigImage.src = currentBanner.imageUrl;
        this.ctrl.bigImage.alt = currentBanner.bannerText;
        this.ctrl.bigImage.title = currentBanner.bannerText;
        $(".tabs li").each(function() {
            $(this).removeClass("selected");
        });
        $(currentBanner.tab).addClass("selected");

        this.timeout = setTimeout(Function.createDelegate(this, this.nextBanner), currentBanner.displayTime);

    }
};
