
(function (w) {
    /*tagconfig*/
    var a = 

{"posType":"in","pauseButton":true,"maxRun":9999,"autoPlay":true,"height":0,"width":100,"templateType":"1","playerType":1,"loop":true,"maxImp":9999,"midrolldelay":0,"showPos":true,"channelId":"5f8f10f41658804a52611fd6","maxWidth":400,"customLogo":{"link":"https:\/\/cdn.snigelweb.com\/resources\/img\/logo\/logo-snigel-shell-02.png","height":23,"clickthrough":"https:\/\/snigel.com","width":23,"text":"Ads by"},"posDfp1x1":false,"startaddelay":0,"soundButton":true,"errorLimit":12,"logo":true,"hideLogoOnAd":true,"autoPlayContent":true,"scriptId":"AV5f8f134c57e2d4652b49fc8a","closeButtonStyle":{"position":"Default"},"vastRetry":5,"position":"aniplayer_AV5f8f134c57e2d4652b49fc8a","midrolltime":0,"publisherId":"5f280c598c04cd5e910ff0a1","posSelector":"body","startmidroll":10,"startdelay":0,"sticky":{"size":1,"position":"Bottom-Right","right":10,"bottom":10}}

    /*tagconfig*/
    var st = {
        unique: function() {
            if (!this.win.aniplayerPos)
                this.win.aniplayerPos = {};
            this.win.aniplayerPos[a.position] = true;
            return true;
        },
        findWin: function() {
           try {
                if ((!a.posDfp1x1 && !a.posClass && !a.posSelector && !a.posId && !a.posTag) || (w === top) || !w.frameElement) {
                    this.doc = document;
                    this.win = w;
                } else if (a.posDfp1x1 && w.frameElement) {
                    this.win = parent;
                    this.doc = parent.document;
                } else {
                    this.win = top;
                    this.doc = top.document;
                }
            } catch (f) {
                this.doc = document;
                this.win = w;
            }
        },
        postCreate: function() {
            
        },
        retry: function() {
           if (this.retryCnt++ > a.timeout)
                return;
            var that = this;
            setTimeout(function() {
                that.position();
            }, 250);
        },
        create: function(p, n) {
            var d1 = document.createElement("div");
            d1.style.width = "100%";
            d1.style.margin = "0 auto";
            d1.style.maxWidth = "" + a.maxWidth + "px";
            var d2 = document.createElement("div");
            d2.id = "aniBox";
            d2.style.height = "1px";
            var d3 = document.createElement("div");
            d3.id = "" + a.position;
            if (p === this.doc || p === this.doc.head)
                p = this.doc.body;
            if (n) {
                p.insertBefore(d1, n);
            } else {
                p.appendChild(d1);
            }
            a.refDiv = p;
            d1.appendChild(d2);
            d2.appendChild(d3);
            this.postCreate(d1);
        },
        position: function() {
            var p = this.doc;
            var isScp = false;
            if (a.posSelector) {
                p = this.doc.querySelector(a.posSelector);
                if (!p) {
                    this.retry();
                    return;
                }
            }
            if (a.posId) {
                p = this.doc.getElementById(a.posId);
                if (!p) {
                    this.retry();
                    return;
                }
            }
            if (a.posTag) {
                var c = a.posTag.split("#");
                if (c && c.length == 2) {
                    var e = p.getElementsByTagName(c[0]);
                    if (e.length == 0) {
                        this.retry();
                        return;
                    }
                    p = e[Math.min(c[1] - 1, e.length - 1)];
                }
            }
            if (a.posClass) {
                var c = a.posClass.split("#");
                var e = 1;
                if (c.length == 2) {
                    e = c[1];
                }
                var f = p.getElementsByClassName(c[0]);
                if (f.length > 0) {
                    p = f[Math.min(e - 1, f.length - 1)];
                }
                if (!p) {
                    this.retry();
                    return;
                }
            }
            if (a.posDfp1x1 && window.frameElement) {
                n = window.frameElement.parentNode.parentNode;
                p = n.parentNode;
                if (document.body.clientHeight > 5 && !a.nohideIframe) {
                    frameElement.style.height = "0px";
                }
                if (a.posType == "after") {
                    n = n.nextElementSibling;
                }
            }
            var n;
            if (p === this.doc) {
                n = this.doc.getElementById(a.scriptId);
                if (n) {
                    n.id += "-used";
                    p = n.parentNode;
                }
            }
            if (p === this.doc.head) {
                n = null;
                p = this.doc;
            }
            if (a.posType && a.posType !== "in" && !n) {
                if (a.posType === "after" && p.nextElementSibling) {
                    p = p.nextElementSibling;
                }
                n = p;
                p = n.parentNode;
            }
            if (p) {
                if (!p.av_setpos) {
                    p.av_setpos = {};
                }
                if (!p.av_setpos[a.position]) {
                    p.av_setpos[a.position] = true;
                    a.position += "-" + Date.now();
                    this.create(p, n);
                    this.load();
                }
            }
        },
        load: function() {
            var that = this;
            var scp = this.doc.createElement("script");
            scp.src = (a.baseJsUrl || "https://player.aniview.com/script/6.1/") + "player.js";
            scp.onload = function() {
                that.start();
            };
            scp.async = true;
            this.doc.body.appendChild(scp)
        },
        postStart: function(p) {
            
        },
        getAttr: function() {
            if (a.scriptId) {
                var s = document.getElementById(a.scriptId) || document.getElementById(a.scriptId + "-used");
                if (s) {
                    for (var i = 0, t = s.attributes; i < s.attributes.length; i++) {
                        if (t[i].nodeName && t[i].nodeName.indexOf("data-") == 0) {
                            var n = t[i].nodeName.replace("data-", "");
                            a[n] = t[i].nodeValue;
                        }
                    }
                    if (s.src) {
                        var p = s.src.indexOf("?");
                        if (p > 10) {
                            var r = (s.src.substring(p + 1, s.src.length));
                            a.ref1 = (a.ref1 || "") + "&" + (r || "");
                        }
                    }
                }
            }
        },
        start: function() {
            var b;
            this.getAttr();
            try {
                if (this.win.avPlayer) {
                    b = new this.win.avPlayer(a);
                } else if (window.avPlayer) {
                    b = new avPlayer(a);
                } else {
                    b = top.avPlayer(a);
                }
            } catch (exp) {
                b = new avPlayer(a);
            }
            this.p = b;
            if (this.pbjs)
                this.pbjs.preparePlayer(b, st);
            if (a.templateType != 0)
                b.startTemplate(this.doc.getElementById(a.position).parentNode);
            b.play(a);
            this.postStart(b);
        },
        preRun: function() {
            
        },
        run: function() {
            this.a = a;
            this.preRun();
            this.findWin();
            if (!this.doc.body) {
                this.doc.addEventListener("DOMContentLoaded", function() {
                    st.run();
                });
                if (this.bodyRetry > 0) {
                    setTimeout(function(){
                        st.run()
                    }, 250);
                    this.domRetry--;
                }
                return;
            }
            if (this.unique() && !this.loaded) {
                this.loaded = true;
                (new Image).src = "https://" + (a.trackDomain || "track1.aniview.com") + "/track?pid=" + a.publisherId + "&cid=" + a.channelId + "&e=playerLoaded&cb=" + Date.now();
                this.retryCnt = 0;
                this.timeout = a.posTimeout || 40;
                this.pbjs = window.aniviewRenderer && window.aniviewRenderer.units && window.aniviewRenderer.units[a.scriptId];
                if (this.pbjs)
                    this.pbjs.prepareConfig(a, st);
                this.position();
            }
        },
        domRetry: 20
    };
    st.run();
})(window);
