
function bannerRotator(strIdContainer, strTagName, strClassName, intVisibleItems, intDelay) {

    var rotator = this;//Needed for closures below
    this.banners = new Array();
    this.visibleBanners = new Array(); //currently visible banners
    this.intVisibleItems = intVisibleItems; //number of visible banners
    this.pause = false;//when mouseovered the banner switching should be paused to avoid a click on 'next' banner

    //initiliaze banners
    var container = document.getElementById(strIdContainer);
    if(!container) return;
    var colBanners = container.getElementsByTagName(strTagName);


    var l = colBanners.length;
    for (var i = 0; i < l; i++) {

        if (ClassName.contains(colBanners[i], strClassName)) {

            colBanners[i].style.display = "none";

            addEventHandler(colBanners[i], "mouseover", function () {
                rotator.pause = true;
            });
            addEventHandler(colBanners[i], "mouseout", function () {
                rotator.pause = false;
            });
            this.banners.push(colBanners[i]);
        }
    }
    this.length = this.banners.length;
    if(this.length < 1)
    {
       return;
    }
    else if (this.length == 1)
    {
       // set display is true without rotating
       this.banners[0].style.display = "block";
       return;
    }
    var self = this;
    this.index = Math.floor(Math.random() * this.length);
    this.rotate();
    this.auto = setInterval(function() {self.rotate()}, intDelay);
}
bannerRotator.prototype.rotate = function () {
    if (!this.pause) {
        var l = this.visibleBanners.length;
        for (var i = 0; i < l; i++) {
            this.visibleBanners[i].style.display = "none";
        }
        this.visibleBanners = new Array();
        for (var i = 1; i <= this.intVisibleItems; i++) {
            this.index++;
            if (this.index >= this.length) {
                this.index = 0;
            }
            this.banners[this.index].style.display = "block";
            this.visibleBanners.push(this.banners[this.index]);
        }
    }
};

if (onloadHandler) onloadHandler.add(function() {
    new bannerRotator("tools", "div", "banner", 3, 10000);
});


