var bmone2n = {
    positions: new Object(),
    adRepository: new Object(),
    oldErrHandler: null,
    blockErrors: function() {
        if (typeof _bbdebug == "undefined") {
            if (!this.oldErrHandler) {
                this.oldErrHandler = window.onerror
            }
            window.onerror = this.failGracefully
        }
    },
    unblockErrors: function() {
        if (typeof _bbdebug == "undefined") {
            window.onerror = this.oldErrHandler
        }
    },
    failGracefully: function() {
        return true
    },
    getRefTo: function(b, a) {
        var c = null;
        if (!a) {
            a = document
        }
        if (a.getElementById && a.getElementById(b) != null) {
            c = a.getElementById(b)
        } else {
            if (a.layers && a.layers[b] != null) {
                c = a.layers[b]
            } else {
                if (a.all) {
                    c = a.all[b]
                }
            }
        }
        return c
    },
    addPosition: function(a, c, b, f, e, g, h) {
        this.blockErrors();
        var d = this.getRefTo("bmone2n-" + a);
        if (d && (d.style.visibility.toUpperCase() != "HIDDEN") && (d.style.display.toUpperCase() != "NONE")) {
            this.positions[a] = new Object();
            this.positions[a]["codeParams"] = typeof(c) != "string" ? "": c;
            this.positions[a]["objIDsS"] = b == "this" || b == "" ? "bmone2n-" + a: b;
            this.positions[a]["objStylesS"] = f;
            this.positions[a]["objIDsF"] = e == "this" || e == "" ? "bmone2n-" + a: e;
            this.positions[a]["objStylesF"] = g;
            this.positions[a]["callback"] = h
        }
        this.unblockErrors()
    },
    addAd: function(b, c, a) {
        this.blockErrors();
        this.adRepository[b] = new Object();
        this.adRepository[b]["adCode"] = c;
        this.adRepository[b]["beacon"] = a ? true: false;
        this.unblockErrors()
    },
    makeAd: function(a) {
        this.blockErrors();
        var g, f, e = "";
        var b = true;
        var d = this;
        var f;
        if (this.adRepository[a] && this.adRepository[a]["adCode"]) {
            if (this.adRepository[a]["beacon"]) {
                e = "BBMEDIA ONE2MANY WARNING: INVISIBLE BEACON CODE TO BE PLACED HERE. IF YOU SEE THIS MESSAGE IT IS WRONG!"
            }
            var c = this.adRepository[a]["adCode"].toUpperCase();
            g = this.getRefTo("bmone2n-" + a);
            if (c.indexOf("<SC") != -1 || c.indexOf("SCRIPT") != -1) {
                f = this.getRefTo("bmone2t-" + a);
                document.write(this.adRepository[a]["adCode"] + e);
                if (b) {
                    this.adRepository[a]["tomove"] = true
                }
                if (this.browser.msie || this.browser.opera) {
                    setTimeout(function() {
                        d.waitForScripts(f, a)
                    },
                    0)
                } else {
                    this.move1Ad(a)
                }
            } else {
                g = this.getRefTo("bmone2n-" + a);
                if (g) {
                    setTimeout(function() {
                    g.innerHTML = this.adRepository[a]["adCode"] + e;
                    }.bind(this),                    0)
                    this.callCallback(a, true)
                }
            }
        } else {
            this.callCallback(a, false)
        }
        this.unblockErrors()
    },
    totalScripts: {},
    unreadyScripts: {},
    waitForScripts: function(d, b) {
        var e = this;
        var a = d.getElementsByTagName("SCRIPT");
        this.unreadyScripts[b] = this.totalScripts[b] = a.length;
        if (a[0] && !a[0].readyState) {
            this.move1Ad(b, true)
        }
        for (var c = 0; c < a.length; c++) {
            if (a[c].readyState != "complete") {
                a[c].onreadystatechange = function() {
                    if (this.readyState == "complete") {
                        e.checkReadiness(b, d)
                    }
                }
            } else {
                this.checkReadiness(b, d)
            }
        }
    },
    checkReadiness: function(a, b) {
        var c = this;
        this.unreadyScripts[a]--;
        if (this.unreadyScripts[a] < 1) {
            if (b.getElementsByTagName("SCRIPT").length == this.totalScripts[a]) {
                this.runWhenContentLoaded(function() {
                    c.move1Ad(a)
                })
            } else {
                this.waitForScripts(b, a)
            }
        }
    },
    callCallback: function(a, b) {
        if (this.positions[a]) {
            if (typeof this.positions[a]["callback"] != "function") {
                this.changeStyles(a, b)
            } else {
                this.positions[a]["callback"](a, b)
            }
        }
    },
    move1Ad: function(j, g) {
        var c;
        var b = null;
        var h = null;
        if (this.adRepository[j]["tomove"]) {
            var f = this.getRefTo("bmone2n-" + j);
            if (f) {
                var a = this.getRefTo("bmone2t-" + j);
                if (a) {
                    a.style.display = "block";
                    if (this.browser.msie) {
                        var d = a.getElementsByTagName("SCRIPT");
                        for (var e = 0; e < d.length; e++) {
                            if (d[e].src != "") {
                                d[e].src = ""
                            }
                        }
                    }
                    f.insertBefore(a, null);
                    this.callCallback(j, true)
                }
            }
            this.adRepository[j]["tomove"] = false
        }
    },
    moveAd: function() {
        this.blockErrors();
        var b = this;
        if (!this.contentLoaded) {
            this.runWhenContentLoaded(function() {
                b.moveAd()
            });
            return
        }
        for (var a in this.adRepository) {
            this.move1Ad(a)
        }
        this.unblockErrors()
    },
    getMoveAdCall: function(a) {
        that = this;
        return function() {
            that.move1Ad(a)
        }
    },
    getAd: function(e, g, f, b) {
        this.blockErrors();
        var h = this;
        if (m(e)) {
            return
        }
        var d = 0;
        var l = "";
        var i = (location.protocol.substring(0, 2) != "ht") ? "http:": location.protocol;
        if (i != "https:") {
            e = this.correctDomain(e)
        }
        for (var n in this.positions) {
            d++;
            l += "&one2n" + d + "=/" + n.replace(/\./g, "/") + "/;" + n + ";" + escape(this.positions[n]["codeParams"])
        }
        if (d > 0) {
            l += "&one2n=" + d;
            var a = screen,
            c = navigator,
            j;
            j = "&ubl=" + c.browserLanguage + "&ucc=" + c.cpuClass + "&ucd=" + a.colorDepth + "&uce=" + c.cookieEnabled + "&udx=" + a.deviceXDPI + "&udy=" + a.deviceYDPI + "&usl=" + c.systemLanguage + "&uje=" + c.javaEnabled() + "&uah=" + a.availHeight + "&uaw=" + a.availWidth + "&ubd=" + a.bufferDepth + "&uhe=" + a.height + "&ulx=" + a.logicalXDPI + "&uly=" + a.logicalYDPI + "&use=" + a.fontSmoothingEnabled + "&uto=" + (new Date()).getTimezoneOffset() + "&uti=" + (new Date()).getTime() + "&uui=" + a.updateInterval + "&uul=" + c.userLanguage + "&uwi=" + a.width;
            j = l + j;
            if (typeof g == "string" && g != "") {
                j += "&keywords=" + escape(g)
            }
            if (typeof f == "string" && f != "") {
                j += f
            }
            if (typeof b != "string") {
                b = "windows-1250"
            }
            document.write("<script type='text/javascript' charset='" + b + "' src='" + i + "//" + e + "/please/showit/0/0/0/1/?typkodu=js" + j + "&alttext=0&border=0&bust=" + Math.random() + "&target=_top'><\/script>")
        }
        function m(s) {
            var p = 0;
            var r = "ad2.ip.ro";
            var q = "5478";
            if (typeof bb_dropDomain == "string") {
                r = bb_dropDomain
            }
            if (typeof bb_dropForServerId == "string") {
                q = bb_dropForServerId
            }
            if (s != r) {
                return false
            }
            for (var o in h.positions) {
                serverId = o.split(".")[p];
                if (serverId == q) {
                    return k()
                }
            }
            return false
        }
        function k() {
            var o = 10;
            if (typeof bb_dropRate == "number") {
                o = parseInt(bb_dropRate)
            }
            return Math.random() * 100 < o
        }
        this.unblockErrors()
    },
    correctDomain: function(b) {
        var a = {};
        a["adarbo2.bbmedia.cz"] = "go.arbo.bbelements.com";
        a["adidnes2.bbmedia.cz"] = "go.idnes.bbelements.com";
        a["ad2.pl.mediainter.net"] = "go.arbopl.bbelements.com";
        a["ad2.bbmedia.cz"] = "go.cz.bbelements.com";
        if (a[b]) {
            return a[b]
        } else {
            return b
        }
    },
    changeStyles: function(k, j) {
        this.blockErrors();
        finalL = j ? "S": "F";
        var a = "",
        h, l, m, g;
        if (typeof(this.positions[k]) != "undefined" && this.positions[k]["objIDs" + finalL]) {
            var d = (this.positions[k]["objIDs" + finalL]).split(",");
            var f = (this.positions[k]["objStyles" + finalL]).split(",");
            for (var e in d) {
                if (!f[e]) {
                    if (a) {
                        f[e] = a
                    } else {
                        return
                    }
                }
                var b = f[e];
                a = b;
                var c = this.getRefTo(d[e]);
                if (c) {
                    if (b.indexOf("class=") == 0) {
                        c.className = b.substr(6)
                    } else {
                        while (b) {
                            h = b.indexOf(":");
                            if (h == -1) {
                                return
                            }
                            l = b.indexOf(";");
                            if (l == -1) {
                                l = b.length
                            }
                            g = b.substr(0, h);
                            m = b.substr(h + 1, l - h - 1);
                            c.style[g] = m;
                            b = b.substr(l + 1)
                        }
                    }
                }
            }
        }
        this.unblockErrors()
    },
    rotateAd: function(c) {
        if (typeof bb_rotation == "function") {
            bb_rotation(c)
        } else {
            for (var b = 0; b < c.length; b++) {
                if (c[b].gId != 0 && c[b].poss.length > 1) {
                    for (var a = 0; a < c[b].poss.length - 1; a++) {
                        sourceIdx = Math.floor(Math.random() * c[b].poss.length);
                        destIdx = Math.floor(Math.random() * c[b].poss.length);
                        if (sourceIdx != destIdx) {
                            source = document.getElementById("bmone2n-" + c[b].poss[sourceIdx]);
                            dest = document.getElementById("bmone2n-" + c[b].poss[destIdx]);
                            placeHolder = document.createElement("SPAN");
                            if (source && dest) {
                                sourcePar = source.parentNode;
                                destPar = dest.parentNode;
                                source = sourcePar.replaceChild(placeHolder, source);
                                dest = destPar.replaceChild(source, dest);
                                sourcePar.replaceChild(dest, placeHolder)
                            }
                        }
                    }
                }
            }
        }
    },
    iniDivRotation: function(c) {
        var a = new Object();
        var d = [];
        var e = c.split(";");
        for (var b = 0; b < e.length; b++) {
            groupInfo = e[b].split("#");
            groupId = "grp" + groupInfo[1];
            if (typeof a[groupId] != "undefined") {
                a[groupId].push(groupInfo[0])
            } else {
                a[groupId] = [groupInfo[0]]
            }
        }
        for (group in a) {
            gid = group.substr(3);
            d.push({
                gId: gid,
                poss: a[group]
            })
        }
        this.rotateAd(d)
    },
    contentLoadedFunctions: [],
    contentLoaded: false,
    runContentLoadedFunctions: function() {
        this.contentLoaded = true;
        for (var a = 0; a < this.contentLoadedFunctions.length; a++) {
            this.contentLoadedFunctions[a]()
        }
    },
    initContentLoaded: function() {
        that = this;
        if (document.addEventListener && !window.opera) {
            document.addEventListener("DOMContentLoaded", function() {
                that.runContentLoadedFunctions()
            },
            false);
            return
        }
        if (this.browser.msie && window == top) { (function() {
                if (this.contentLoaded) {
                    return
                }
                try {
                    document.documentElement.doScroll("left")
                } catch(b) {
                    setTimeout(arguments.callee, 0);
                    return
                }
                that.runContentLoadedFunctions();
                return
            })();
            return
        }
        if (this.browser.opera) {
            document.addEventListener("DOMContentLoaded", function() {
                if (this.contentLoaded) {
                    return
                }
                for (var b = 0; b < document.styleSheets.length; b++) {
                    if (document.styleSheets[b].disabled) {
                        setTimeout(arguments.callee, 10);
                        return
                    }
                }
                this.runContentLoadedFunctions();
                return
            },
            false)
        }
        if (this.browser.safari) {
            var a;
            (function() {
                if (this.contentLoaded) {
                    return
                }
                if (document.readyState != "loaded" && document.readyState != "complete") {
                    setTimeout(arguments.callee, 0);
                    return
                }
                that.runContentLoadedFunctions();
                return
            })()
        }
        oldOnload = window.onload;
        window.onload = function() {
            that.runContentLoadedFunctions();
            if (oldOnload) {
                oldOnload()
            }
        }
    },
    runWhenContentLoaded: function(a) {
        if (this.contentLoaded) {
            a()
        } else {
            this.contentLoadedFunctions.push(a)
        }
    },
    browser: {},
    detectBrowser: function() {
        var a = navigator.userAgent.toLowerCase();
        this.browser = {
            version: (a.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
            safari: /webkit/.test(a),
            opera: /opera/.test(a),
            msie: /msie/.test(a) && !/opera/.test(a),
            mozilla: /mozilla/.test(a) && !/(compatible|webkit)/.test(a)
        }
    },
    init: function() {
        this.detectBrowser();
        this.initContentLoaded()
    }
};
bmone2n.init();