function BannerR(id, data) {
    this.id = id;    
    if (data[data.length - 1] == undefined)
        data.pop();
    this.data = data;
    this.posCurrent = 0;
    this.posLast = -1;
    this.rotation = false;
    this.fadeSpeed = "normal";
    this.delay = 5000;
    this.obj = $("#b" + id);
    this.elements = null;
	this.imgpath = SetPath() + "images/layout/";
}

BannerR.prototype = {
    toggleRotation: function(state) {
        if (state != undefined)
            this.rotation = !state;

        if (this.rotation == false) {
            var self = this;
            this.iVal = setInterval(function() { self.rotateBanner(); }, this.delay);
            this.obj.find("img.toggle").attr('src', this.imgpath + 'ban_stop.png');
            this.rotation = true;
        }
        else if (this.rotation == true) {
            clearInterval(this.iVal);
            this.iVal = null;
            this.obj.find("img.toggle").attr('src', this.imgpath + 'ban_play.png');
            this.rotation = false;
        }
        return this;
    },
    setBanner: function(pos) {
        var path = this.imgpath;
        if (pos != undefined && pos >= 0 && pos < this.data.length) {
            this.posLast = this.posLast > -1 ? this.posCurrent : -1;
            this.posCurrent = pos;
            this.toggleRotation(false);
        }
        if (this.posLast > -1) {
            if (this.posLast != this.posCurrent) {
                var pL = $(this.elements[this.posLast]);
                var pC = $(this.elements[this.posCurrent]);
                if (pL.is(":animated"))
                    pL.stop(true, true).show();
                pL.css("z-index", "50");
                pC.css("z-index", "100").fadeIn(this.fadeSpeed, function() { $(pL).hide(); });
            }
        } else {
            $(this.elements[this.posCurrent]).show();
            this.obj.css("height", $(this.elements[this.posCurrent]).height() + "px")
            this.posLast = this.posCurrent;
        }

        this.obj.find("div.bControl img.toggle").attr('src', path + (this.rotation ? "ban_stop.png" : "ban_play.png"));

        if ($.browser.msie && parseInt(jQuery.browser.version) < 7) {
            $(this.elements[this.posCurrent]).find(".bControl").pngFix();
        }

        return this;
    },
    rotateBanner: function() {
        this.posLast = this.posCurrent;
        this.posCurrent++;
        if (this.posCurrent >= this.data.length)
            this.posCurrent = 0;
        return this.setBanner();
    },
    initRotator: function(options) {
        if (!options.rotation) {
            if (options.fix >= 0)
                this.obj.html(this.data[options.fix]);
            else
                this.obj.html(this.data[Math.floor(Math.random() * this.data.length)]);
            return this;
        }

        var data = this.data;        
        if (data.length > 5)
            data.length = 5;
        var path = this.imgpath;
        $.each(data, function(index, value) {
            var cHtml = "";
            if (options.controls) {
                for (var i = 0; i < data.length; i++)
                    if (i == index) {
                    cHtml += "<img src=\"" + path + "ban_rbtn2.png\" onclick=\"$(this).parents('.bContainer')[0].bannerR.setBanner(" + i + ")\" class=\"ban active\" alt=\"Banner " + (i + 1) + "\" />";
                }
                else
                    cHtml += "<img src=\"" + path + "ban_rbtn1.png\" onclick=\"$(this).parents('.bContainer')[0].bannerR.setBanner(" + i + ")\" class=\"ban\" alt=\"Banner " + (i + 1) + "\" />";
                cHtml += "<img src=\"" + path + "ban_stop.png\" onclick=\"$(this).parents('.bContainer')[0].bannerR.toggleRotation()\" class=\"toggle\" alt=\"Play\/Pause Rotation\" />";
                cHtml = value.replace("<div class=\"bControl\"><\/div>", "<div class=\"bControl\">" + cHtml + "</div>");
            }
            data[index] = '<div style="position: absolute; display: none;">' + (cHtml == "" ? value : cHtml) + '</div>';
        });
        this.data = data;
        this.obj
            .html(data.join(""))
            .find('div.bControl img.ban:not(.active)').hover(
                function() { $(this).attr('src', path + 'ban_rbtn2.png'); },
                function() { $(this).attr('src', path + 'ban_rbtn1.png'); });
        this.elements = this.obj.children();

        if ($.browser.msie && parseInt(jQuery.browser.version) < 7) {
            $(".bInfoBoard").css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../images/layout/ban_ibbg.png', sizingMethod='scale');").css("background", "none").css("position", "relative");
        }

        if (options.fix >= 0)
            this.setBanner(options.fix);
        else
            this.setBanner(Math.floor(Math.random() * this.data.length));

        this.delay = options.delay;
        this.fadeSpeed = options.fade != "" ? options.fade : "normal";
        this.toggleRotation(options.rotation);

        return this;
    }
}