(function(window) {
    var ya = window.ya || (window.ya = {});
    (function(window) {
        "use strict";
        if (!window.ya) {
            window.ya = {};
        }
        if (!window.ya.videoAd) {
            window.ya.videoAd = {};
        }
        if (!window.ya.mediaAd) {
            window.ya.mediaAd = {};
        }
        var NS = window.ya.mediaAd;
        if (NS.DOMAIN === undefined) {
            NS.DOMAIN = "yastatic.net";
        }
        if (NS.SDK_VERSION === undefined) {
            NS.SDK_VERSION = "1.0-190";
        }
        if (NS.SDK_FULL_VERSION === undefined) {
            NS.SDK_FULL_VERSION = "js:" + NS.SDK_VERSION;
        }
        if (NS.SDK_URL_VERSION === undefined) {
            NS.SDK_URL_VERSION = window.ya.mediaAd.SDK_VERSION.split("-")[0].split(".").join("_") + "/v-" + window.ya.mediaAd.SDK_VERSION;
        }
    })(window);
    (function(root, name, make) {
        if (typeof module != "undefined" && module["exports"]) module["exports"] = make(); else root[name] = make();
    })(this, "verge", function() {
        var xports = {}, win = typeof window != "undefined" && window, doc = typeof document != "undefined" && document, docElem = doc && doc.documentElement, matchMedia = win["matchMedia"] || win["msMatchMedia"], mq = matchMedia ? function(q) {
            return !!matchMedia.call(win, q).matches;
        } : function() {
            return false;
        }, viewportW = xports["viewportW"] = function() {
            var a = docElem["clientWidth"], b = win["innerWidth"];
            return b ? b : a;
        }, viewportH = xports["viewportH"] = function() {
            var a = docElem["clientHeight"], b = win["innerHeight"];
            return b ? b : a;
        };
        xports["mq"] = mq;
        xports["matchMedia"] = matchMedia ? function() {
            return matchMedia.apply(win, arguments);
        } : function() {
            return {};
        };
        function viewport() {
            return {
                width: viewportW(),
                height: viewportH()
            };
        }
        xports["viewport"] = viewport;
        xports["scrollX"] = function() {
            return win.pageXOffset || docElem.scrollLeft;
        };
        xports["scrollY"] = function() {
            return win.pageYOffset || docElem.scrollTop;
        };
        function calibrate(coords, cushion) {
            var o = {};
            cushion = +cushion || 0;
            o["width"] = (o["right"] = coords["right"] + cushion) - (o["left"] = coords["left"] - cushion);
            o["height"] = (o["bottom"] = coords["bottom"] + cushion) - (o["top"] = coords["top"] - cushion);
            return o;
        }
        function rectangle(el, cushion) {
            el = el && !el.nodeType ? el[0] : el;
            if (!el || 1 !== el.nodeType) return false;
            return calibrate(el.getBoundingClientRect(), cushion);
        }
        xports["rectangle"] = rectangle;
        function aspect(o) {
            o = null == o ? viewport() : 1 === o.nodeType ? rectangle(o) : o;
            var h = o["height"], w = o["width"];
            h = typeof h == "function" ? h.call(o) : h;
            w = typeof w == "function" ? w.call(o) : w;
            return w / h;
        }
        xports["aspect"] = aspect;
        xports["inX"] = function(el, cushion) {
            var r = rectangle(el, cushion);
            return !!r && r.right >= 0 && r.left <= viewportW();
        };
        xports["inY"] = function(el, cushion) {
            var r = rectangle(el, cushion);
            var result = !!r && r.bottom >= 0 && r.top <= viewportH();
            return result;
        };
        xports["inViewport"] = function(el, cushion) {
            var r = rectangle(el, cushion);
            return !!r && r.bottom >= 0 && r.right >= 0 && r.top <= viewportH() && r.left <= viewportW();
        };
        return xports;
    });
    (function() {
        this.ResizeSensor = function(element, callback) {
            function EventQueue() {
                this.q = [];
                this.add = function(ev) {
                    this.q.push(ev);
                };
                var i, j;
                this.call = function() {
                    for (i = 0, j = this.q.length; i < j; i++) {
                        this.q[i].call();
                    }
                };
            }
            function getComputedStyle(element, prop) {
                if (element.currentStyle) {
                    return element.currentStyle[prop];
                } else if (window.getComputedStyle) {
                    return window.getComputedStyle(element, null).getPropertyValue(prop);
                } else {
                    return element.style[prop];
                }
            }
            function attachResizeEvent(element, resized) {
                if (!element.resizedAttached) {
                    element.resizedAttached = new EventQueue();
                    element.resizedAttached.add(resized);
                } else if (element.resizedAttached) {
                    element.resizedAttached.add(resized);
                    return;
                }
                element.resizeSensor = document.createElement("div");
                element.resizeSensor.className = "resize-sensor";
                var style = "position: absolute; left: 0; top: 0; right: 0; bottom: 0; overflow: scroll; z-index: -1; visibility: hidden;";
                var styleChild = "position: absolute; left: 0; top: 0;";
                element.resizeSensor.style.cssText = style;
                element.resizeSensor.innerHTML = '<div class="resize-sensor-expand" style="' + style + '">' + '<div style="' + styleChild + '"></div>' + "</div>" + '<div class="resize-sensor-shrink" style="' + style + '">' + '<div style="' + styleChild + ' width: 200%; height: 200%"></div>' + "</div>";
                element.appendChild(element.resizeSensor);
                if (!{
                    fixed: 1,
                    absolute: 1
                }[getComputedStyle(element, "position")]) {
                    element.style.position = "relative";
                }
                var expand = element.resizeSensor.childNodes[0];
                var expandChild = expand.childNodes[0];
                var shrink = element.resizeSensor.childNodes[1];
                var shrinkChild = shrink.childNodes[0];
                var lastWidth, lastHeight;
                var reset = function() {
                    expandChild.style.width = expand.offsetWidth + 10 + "px";
                    expandChild.style.height = expand.offsetHeight + 10 + "px";
                    expand.scrollLeft = expand.scrollWidth;
                    expand.scrollTop = expand.scrollHeight;
                    shrink.scrollLeft = shrink.scrollWidth;
                    shrink.scrollTop = shrink.scrollHeight;
                    lastWidth = element.offsetWidth;
                    lastHeight = element.offsetHeight;
                };
                reset();
                var changed = function() {
                    if (element.resizedAttached) {
                        element.resizedAttached.call();
                    }
                };
                var addEvent = function(el, name, cb) {
                    if (el.attachEvent) {
                        el.attachEvent("on" + name, cb);
                    } else {
                        el.addEventListener(name, cb);
                    }
                };
                var onScroll = function() {
                    if (element.offsetWidth != lastWidth || element.offsetHeight != lastHeight) {
                        changed();
                    }
                    reset();
                };
                addEvent(expand, "scroll", onScroll);
                addEvent(shrink, "scroll", onScroll);
            }
            var elementType = Object.prototype.toString.call(element);
            var isCollectionTyped = "[object Array]" === elementType || "[object NodeList]" === elementType || "[object HTMLCollection]" === elementType || "undefined" !== typeof jQuery && element instanceof jQuery || "undefined" !== typeof Elements && element instanceof Elements;
            if (isCollectionTyped) {
                var i = 0, j = element.length;
                for (;i < j; i++) {
                    attachResizeEvent(element[i], callback);
                }
            } else {
                attachResizeEvent(element, callback);
            }
            this.detach = function() {
                if (isCollectionTyped) {
                    var i = 0, j = element.length;
                    for (;i < j; i++) {
                        ResizeSensor.detach(element[i]);
                    }
                } else {
                    ResizeSensor.detach(element);
                }
            };
        };
        this.ResizeSensor.detach = function(element) {
            if (element.resizeSensor) {
                element.removeChild(element.resizeSensor);
                delete element.resizeSensor;
                delete element.resizedAttached;
            }
        };
    })();
    var require, define;
    (function() {
        var modules = {}, factories = {};
        (require = function(id) {
            if (id.pop) id = id[0];
            var m = modules[id];
            if (!m) {
                m = {
                    id: id,
                    exports: {}
                };
                modules[id] = m.module = m;
                m.exports = factories[id].apply(m, factories[id].deps.map(m.require = function(id) {
                    return m[id] || require(rel(id, m.id));
                })) || m.exports;
            }
            return m.exports;
        }).config = valueOf;
        (define = function(id, deps, factory) {
            (factories[id] = typeof (factory = factory || deps) !== "function" ? function() {
                return factory;
            } : factory).deps = deps.pop ? deps : [];
        }).amd = {};
        function rel(name, path) {
            name = name.replace(/^(?:\.\/|(\.\.\/))/, path.replace(/[^\/]+$/g, "") + "$1");
            while (name !== (name = name.replace(/[^\/]+\/\.\.\/?/g, ""))) ;
            return name;
        }
    })();
    define("adsdk/AdConfig", [ "require", "exports" ], function(require, exports) {
        "use strict";
    });
    define("util/util", [ "require", "exports" ], function(require, exports) {
        "use strict";
        var YANDEX_DOMAINS = [ "yandex.ru", "yandex.com", "yandex.net", "yandex.com.tr", "yandex.ua", "yandex.by", "yandex.kz", "yastatic.net", "yandex.st", "yandex-team.ru", "yandex-team.com", "yandex-team.com.ua", "yandex-team.net.ua", "yandex-team.com.tr", "ya.ru" ], YANDEX_FRIENDS_DOMAINS = [ "kinopoisk.ru", "kinopoisk.ua", "kinopoisk.by", "kinopoisk.tel", "vidigital.ru", "tns-counter.ru", "adfox.ru" ];
        function log(message) {
            var args = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                args[_i - 1] = arguments[_i];
            }
            if (!ya.mediaAd.DEV_MODE || !console || !console.log) {
                return;
            }
            console.log.apply(console, [ message ].concat(args));
        }
        exports.log = log;
        function fireCallback(callback) {
            var args = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                args[_i - 1] = arguments[_i];
            }
            if (!callback) {
                return;
            }
            if (typeof callback === "function") {
                callback.apply(void 0, args);
            } else if (callback && callback.hasOwnProperty("length")) {
                var callbacks = callback;
                callbacks.forEach(function(callback) {
                    return callback.apply(void 0, args);
                });
            }
        }
        exports.fireCallback = fireCallback;
        function addCallback(object, eventName, callback) {
            eventName = "on" + eventName.substr(0, 1).toUpperCase() + eventName.substr(1);
            if (!object[eventName]) {
                object[eventName] = callback;
                return;
            }
            if (typeof object[eventName] === "function") {
                object[eventName] = [ object[eventName], callback ];
                return;
            }
            object[eventName].push(callback);
        }
        exports.addCallback = addCallback;
        function endsWith(input, suffix) {
            return suffix === input.substring(input.length - suffix.length);
        }
        exports.endsWith = endsWith;
        function getDomainFromUrl(url) {
            if (!url) {
                return "";
            }
            var aNode = document.createElement("a");
            aNode.setAttribute("href", url);
            return aNode.hostname;
        }
        exports.getDomainFromUrl = getDomainFromUrl;
        function isTrueYandexDomain(url) {
            return isYandexDomain(url, true);
        }
        exports.isTrueYandexDomain = isTrueYandexDomain;
        function isYandexDomain(url, ignoreFriends) {
            if (ignoreFriends === void 0) {
                ignoreFriends = false;
            }
            if (!url) {
                return false;
            }
            var domain = getDomainFromUrl(url), domains = ignoreFriends ? YANDEX_DOMAINS : YANDEX_DOMAINS.concat(YANDEX_FRIENDS_DOMAINS);
            if (!domain || domain.length === 0) {
                return false;
            }
            for (var i = 0, len = domains.length; i < len; i++) {
                var yaDomain = domains[i];
                if (endsWith(domain, yaDomain)) {
                    return true;
                }
            }
            return false;
        }
        exports.isYandexDomain = isYandexDomain;
        function createVideoNode(containerElement, sourceOrSources, poster, autoplay) {
            var videoNode = document.createElement("video");
            videoNode.id = "yaVideoPlayer_" + Math.floor(Math.random() * 1e6);
            videoNode.setAttribute("x-webkit-airplay", "allow");
            if (Array.isArray(sourceOrSources)) {
                sourceOrSources.forEach(function(source) {
                    var sourceNode = document.createElement("source");
                    sourceNode.src = source.src;
                    sourceNode.type = source.type;
                    videoNode.appendChild(sourceNode);
                });
            } else if (sourceOrSources) {
                videoNode.src = sourceOrSources;
            }
            if (poster) {
                videoNode.poster = poster;
            }
            videoNode.autoplay = autoplay;
            videoNode.preload = autoplay ? "auto" : "none";
            containerElement.appendChild(videoNode);
            return videoNode;
        }
        exports.createVideoNode = createVideoNode;
        function adjustElementHeight(element, wRatio, hRatio) {
            if (wRatio === void 0) {
                wRatio = 4;
            }
            if (hRatio === void 0) {
                hRatio = 3;
            }
            var videoElement = element;
            var width = videoElement.width > 0 ? videoElement.width : element.clientWidth;
            var height = Math.floor(width * hRatio / wRatio);
            if (element.nodeName.toLowerCase() == "video") {
                videoElement.height = height;
            } else {
                element.style.height = height + "px";
            }
        }
        exports.adjustElementHeight = adjustElementHeight;
        function createWrapperNode(containerElement) {
            var wrapperNode = createDiv("yaAdSdkGui");
            wrapperNode.id = "videoPlayerWrapper_" + Math.floor(Math.random() * 1e6);
            containerElement.appendChild(wrapperNode);
            return wrapperNode;
        }
        exports.createWrapperNode = createWrapperNode;
        function isTouchDevice() {
            return "ontouchstart" in window || window.navigator.maxTouchPoints > 0 || window.navigator.msMaxTouchPoints > 0;
        }
        exports.isTouchDevice = isTouchDevice;
        function isIPhone() {
            return navigator.userAgent.toLowerCase().indexOf("iphone") > -1;
        }
        exports.isIPhone = isIPhone;
        function isIOS() {
            var userAgent = navigator.userAgent.toLowerCase();
            return userAgent.indexOf("iphone") > -1 || userAgent.indexOf("ipad") > -1 || userAgent.indexOf("ipod") > -1;
        }
        exports.isIOS = isIOS;
        function parseVASTTime(timeString) {
            if (timeString.search(/^\d{2}:\d{2}:\d{2}(\.\d{1,3})?$/) == -1) {
                return NaN;
            }
            var skipTimeParts = timeString.trim().split(":");
            if (skipTimeParts.length < 2 || skipTimeParts.length > 3) {
                return NaN;
            }
            var msParts = skipTimeParts[skipTimeParts.length - 1].split(".");
            var value = 0;
            if (msParts.length == 2) {
                value = +msParts[1] / 1e3;
            }
            if (skipTimeParts.length == 2) {
                value += +skipTimeParts[0] * 60 + +skipTimeParts[1];
            } else {
                value += +skipTimeParts[0] * 3600 + +skipTimeParts[1] * 60 + +skipTimeParts[2];
            }
            return value;
        }
        exports.parseVASTTime = parseVASTTime;
        function createDiv(className, innerHtml) {
            var div = document.createElement("div");
            div.className = className;
            if (innerHtml) {
                div.innerHTML = innerHtml;
            }
            return div;
        }
        exports.createDiv = createDiv;
        function createControl(elementClass, clickHandler, text, parent) {
            var element = createDiv(elementClass, text);
            element.addEventListener("click", clickHandler);
            if (parent) {
                parent.appendChild(element);
            }
            return element;
        }
        exports.createControl = createControl;
        function createElementAfterSelector(selector, position) {
            var elements = document.querySelectorAll(selector);
            var numPos = typeof position == "string" ? parseInt(position, 10) : position;
            if (elements.length == 0) {
                return null;
            }
            if (!position) {
                numPos = 0;
            } else if (typeof position == "string" && position.indexOf("%") > -1) {
                numPos = Math.round(numPos * (elements.length - 1) / 100);
            } else {
                numPos = Math.max(0, numPos - 1);
            }
            var prevElement = elements[Math.min(elements.length - 1, numPos)];
            var containerElement = document.createElement("div");
            containerElement.id = "yaAdSdkContainer_" + Math.floor(Math.random() * 1e7);
            containerElement.className = "yaAdSdkContainer";
            prevElement.parentNode.insertBefore(containerElement, prevElement.nextSibling);
            return containerElement;
        }
        exports.createElementAfterSelector = createElementAfterSelector;
        function getElement(elementOrElementId, insertAfterSelector, insertPosition) {
            if (insertAfterSelector) {
                var element = createElementAfterSelector(insertAfterSelector, insertPosition);
                if (element) {
                    return element;
                }
            }
            return typeof elementOrElementId == "string" ? document.getElementById(elementOrElementId) : elementOrElementId;
        }
        exports.getElement = getElement;
        function getReferrer() {
            var href;
            try {
                href = top.location.href;
            } catch (ex) {
                href = location.href;
            }
            return href;
        }
        exports.getReferrer = getReferrer;
        function addTouchSafeMouseEnterHandler(element, handler) {
            var isOver = false;
            var lastMoveHandler;
            element.addEventListener("mousemove", function(overEvent) {
                if (lastMoveHandler) {
                    return;
                }
                lastMoveHandler = function onMouseMove(moveEvent) {
                    if (!isOver && (moveEvent.clientX != overEvent.clientX || moveEvent.clientY != overEvent.clientY)) {
                        isOver = true;
                        handler(overEvent);
                        element.removeEventListener("mousemove", onMouseMove);
                        lastMoveHandler = null;
                    }
                };
                element.addEventListener("mousemove", lastMoveHandler);
                setTimeout(function() {
                    if (!lastMoveHandler) {
                        return;
                    }
                    element.removeEventListener("mousemove", lastMoveHandler);
                    lastMoveHandler = null;
                }, 250);
            });
            element.addEventListener("mouseleave", function() {
                isOver = false;
            });
        }
        exports.addTouchSafeMouseEnterHandler = addTouchSafeMouseEnterHandler;
        ya.mediaAd.util = ya.mediaAd.util || {};
        ya.mediaAd.util.isIOS = isIOS;
        ya.mediaAd.util.isTouchDevice = isTouchDevice;
    });
    define("inpage/ViewportMonitor", [ "require", "exports", "util/util" ], function(require, exports, util_1) {
        "use strict";
        var ViewportMonitor = function() {
            function ViewportMonitor(containerElement) {
                var _this = this;
                this.containerElement = containerElement;
                this.viewportHandlers = [];
                this._isInViewport = false;
                this.updateIsInViewport = function() {
                    if (document.readyState == "loading" || document.readyState == "loaded") {
                        document.addEventListener("DOMContentLoaded", function() {
                            _this.updateIsInViewport();
                        });
                        return;
                    }
                    var isInViewport = verge.inY(_this.containerElement, -_this.containerElement.clientHeight / 2);
                    if (isInViewport && !_this._isInViewport) {
                        _this.onShow();
                    } else if (!isInViewport && _this._isInViewport) {
                        _this.onHide();
                    }
                    _this._isInViewport = isInViewport;
                };
                this.onTouchEnd = function() {
                    _this.updateIsInViewport();
                    if (_this._isInViewport) {
                        _this.onTouchedInViewport();
                    }
                };
            }
            ViewportMonitor.prototype.initViewportHandlers = function(handlers) {
                var wasWatching = this.isWatching;
                this.viewportHandlers.push(handlers);
                if (wasWatching) {
                    return handlers;
                }
                for (var el = this.containerElement.parentElement.parentElement; el != null; el = el.parentElement) {
                    el.addEventListener("scroll", this.updateIsInViewport);
                }
                window.addEventListener("resize", this.updateIsInViewport);
                window.addEventListener("scroll", this.updateIsInViewport);
                window.addEventListener("touchend", this.onTouchEnd);
                this.updateIsInViewport();
                return handlers;
            };
            ViewportMonitor.prototype.disposeViewportHandlers = function(handlers) {
                var index = this.viewportHandlers.indexOf(handlers);
                if (index > -1) {
                    this.viewportHandlers.splice(index, 1);
                }
                if (!this.isWatching) {
                    for (var el = this.containerElement.parentElement.parentElement; el != null; el = el.parentElement) {
                        el.removeEventListener("scroll", this.updateIsInViewport);
                    }
                    window.removeEventListener("resize", this.updateIsInViewport);
                    window.removeEventListener("scroll", this.updateIsInViewport);
                    window.removeEventListener("touchend", this.onTouchEnd);
                }
            };
            Object.defineProperty(ViewportMonitor.prototype, "isInViewport", {
                get: function() {
                    this.updateIsInViewport();
                    return this._isInViewport;
                },
                enumerable: true,
                configurable: true
            });
            Object.defineProperty(ViewportMonitor.prototype, "isWatching", {
                get: function() {
                    return this.viewportHandlers.length > 0;
                },
                enumerable: true,
                configurable: true
            });
            ViewportMonitor.prototype.onShow = function() {
                this.viewportHandlers.forEach(function(handlers) {
                    return util_1.fireCallback(handlers.onShow);
                });
            };
            ViewportMonitor.prototype.onHide = function() {
                this.viewportHandlers.forEach(function(handlers) {
                    return util_1.fireCallback(handlers.onHide);
                });
            };
            ViewportMonitor.prototype.onTouchedInViewport = function() {
                this.viewportHandlers.forEach(function(handlers) {
                    return util_1.fireCallback(handlers.onTouchedInViewport);
                });
            };
            return ViewportMonitor;
        }();
        Object.defineProperty(exports, "__esModule", {
            value: true
        });
        exports.default = ViewportMonitor;
    });
    define("inpage/ViewportPlayerController", [ "require", "exports", "inpage/ViewportMonitor", "util/util" ], function(require, exports, ViewportMonitor_1, util_2) {
        "use strict";
        var ViewportPlayerController = function() {
            function ViewportPlayerController(containerElement) {
                this.containerElement = containerElement;
                this.isTimeoutComplete = false;
                this.monitor = new ViewportMonitor_1.default(containerElement);
            }
            ViewportPlayerController.prototype.waitForInitialShow = function(startPlaybackCallback, startTimeout) {
                var _this = this;
                if (startTimeout === void 0) {
                    startTimeout = 0;
                }
                var delayTimeoutId = 0;
                var tryToFireStartCallback = function() {
                    if (!_this.getIsInViewport()) {
                        return;
                    }
                    _this.dispose();
                    startPlaybackCallback();
                };
                var onTimeoutComplete = function() {
                    _this.isTimeoutComplete = true;
                    tryToFireStartCallback();
                };
                this.handlers = this.monitor.initViewportHandlers({
                    onShow: function() {
                        if (_this.isTimeoutComplete) {
                            tryToFireStartCallback();
                        } else if (!delayTimeoutId) {
                            delayTimeoutId = setTimeout(onTimeoutComplete, startTimeout);
                        }
                    },
                    onHide: function() {
                        if (delayTimeoutId) {
                            clearTimeout(delayTimeoutId);
                            delayTimeoutId = 0;
                        }
                    },
                    onTouchedInViewport: function() {
                        return _this.onTouchedInViewport();
                    }
                });
            };
            ViewportPlayerController.prototype.onTouchedInViewport = function() {
                if (!util_2.isIPhone()) {
                    var video = this.containerElement.querySelector("video");
                    video.play();
                }
            };
            ViewportPlayerController.prototype.getIsInViewport = function() {
                return this.monitor.isInViewport && this.isTimeoutComplete;
            };
            ViewportPlayerController.prototype.monitorPlayback = function(viewer) {
                var _this = this;
                if (this.handlers) {
                    this.monitor.disposeViewportHandlers(this.handlers);
                }
                this.handlers = this.monitor.initViewportHandlers({
                    onShow: function() {
                        if (!util_2.isIPhone()) {
                            viewer.resume();
                        }
                    },
                    onHide: function() {
                        return viewer.pause();
                    },
                    onTouchedInViewport: function() {
                        return _this.onTouchedInViewport();
                    }
                });
            };
            ViewportPlayerController.prototype.dispose = function() {
                if (!this.handlers) {
                    return;
                }
                this.monitor.disposeViewportHandlers(this.handlers);
                this.handlers = null;
            };
            return ViewportPlayerController;
        }();
        Object.defineProperty(exports, "__esModule", {
            value: true
        });
        exports.default = ViewportPlayerController;
    });
    define("inpage/PlayerCallbacks", [ "require", "exports" ], function(require, exports) {
        "use strict";
    });
    define("adsdk/AdType", [ "require", "exports" ], function(require, exports) {
        "use strict";
        var AdType = {
            PREROLL: "preroll",
            MIDROLL: "midroll",
            PAUSEROLL: "pauseroll",
            OVERLAY: "overlay",
            POSTROLL: "postroll"
        };
        Object.defineProperty(exports, "__esModule", {
            value: true
        });
        exports.default = AdType;
        ya.mediaAd.AdType = AdType;
    });
    define("util/LibLoader", [ "require", "exports" ], function(require, exports) {
        "use strict";
        var LibLoader = new (function() {
            function LibLoader() {
                this.loadedLibs = [];
                this.libToCallbacksMap = {};
            }
            LibLoader.prototype.load = function(url, callback) {
                var _this = this;
                if (this.loadedLibs.indexOf(url) > -1) {
                    callback();
                    return;
                }
                if (this.libToCallbacksMap[url]) {
                    this.libToCallbacksMap[url].push(callback);
                    return;
                }
                this.libToCallbacksMap[url] = [ callback ];
                var script = document.createElement("script");
                script.src = url;
                script.onload = function() {
                    _this.libToCallbacksMap[url].forEach(function(callback) {
                        callback();
                    });
                    _this.libToCallbacksMap[url] = null;
                    _this.loadedLibs.push(url);
                };
                document.head.appendChild(script);
            };
            return LibLoader;
        }())();
        Object.defineProperty(exports, "__esModule", {
            value: true
        });
        exports.default = LibLoader;
    });
    define("inpage/HtmlPlayer", [ "require", "exports", "adsdk/AdType", "util/LibLoader", "util/util" ], function(require, exports, AdType_1, LibLoader_1, util_3) {
        "use strict";
        var AD_SDK_URL = "/awaps-ad-sdk-js/" + ya.mediaAd.SDK_URL_VERSION + "/adsdk.min.js", IMPRESSION_TRACK_OFFSET = 5;
        function initVideoNode(wrapperNode) {
            var videoNode = util_3.createVideoNode(wrapperNode, null, null, true);
            videoNode.volume = 0;
            videoNode.muted = true;
            videoNode.setAttribute("width", "100%");
            videoNode.setAttribute("height", "100%");
            videoNode.style.backgroundColor = "black";
            return videoNode;
        }
        function createHtmlAdPlayer(wrapper, adConfig, callbacks) {
            if (ya.mediaAd.initAdDisplay === undefined) {
                LibLoader_1.default.load("https://" + ya.mediaAd.DOMAIN + AD_SDK_URL, function() {
                    createHtmlAdPlayer(wrapper, adConfig, callbacks);
                });
                return;
            }
            var wrapperNode = util_3.createWrapperNode(wrapper), videoNode = initVideoNode(wrapperNode);
            if (ya.mediaAd.SDK_FULL_VERSION.indexOf(":inpage") == -1) {
                ya.mediaAd.SDK_FULL_VERSION += ":inpage";
            }
            videoNode.addEventListener("playing", callbacks.onVideoPlaying);
            if (util_3.isIPhone()) {
                videoNode.addEventListener("loadedmetadata", callbacks.onVideoPlaying);
            }
            ya.mediaAd.initAdDisplay(adConfig, videoNode.id, wrapperNode.id, function(displayControllerOrError) {
                if (displayControllerOrError instanceof Error) {
                    util_3.fireCallback(callbacks.onPlayerPrepared, displayControllerOrError);
                    return;
                }
                var displayController = displayControllerOrError;
                util_3.fireCallback(callbacks.onPlayerPrepared, function showAd(onAdCreatedCallback) {
                    var onCreate = function(adViewer) {
                        adViewer.impressionTrackOffset = IMPRESSION_TRACK_OFFSET;
                        util_3.fireCallback(onAdCreatedCallback, null, adViewer);
                    };
                    var onError = function(error) {
                        util_3.fireCallback(callbacks.onComplete);
                        util_3.fireCallback(onAdCreatedCallback, error);
                    };
                    displayController.showAd(AdType_1.default.PREROLL, onCreate, callbacks.onComplete, onError);
                });
            });
        }
        exports.createHtmlAdPlayer = createHtmlAdPlayer;
    });
    define("util/flash_util", [ "require", "exports", "util/LibLoader", "util/util" ], function(require, exports, LibLoader_2, util_4) {
        "use strict";
        var SWF_OBJECT_URL = "/awaps-ad-sdk-js/" + ya.mediaAd.SDK_URL_VERSION + "/swfobject.min.js";
        var STATIC_SWF_INFO_URL = "/swf/{PACKAGE}/{BUILD}/info?nc=";
        var STATIC_SWF_URL_BASE = "/swf/{PACKAGE}/{BUILD}/v-{VERSION}/{PACKAGE}.swf";
        var JS_TO_FLASH_AD_PARAMS_MAP = {
            partnerId: "partner-id",
            category: "category",
            tagsList: "tags-list",
            emptyId: "empty-id",
            extParam: "ext-param",
            videoContentId: "video-content-id",
            videoContentName: "video-content-name",
            videoPublisherId: "video-publisher-id",
            videoPublisherName: "video-publisher-name",
            videoGenreId: "video-genre-id",
            videoGenreName: "video-genre-name",
            duration: "duration"
        };
        function checkForFlashPlayer(callback) {
            function hasFlashPlayer() {
                return swfobject.getFlashPlayerVersion().major > 0;
            }
            if (window.swfobject === undefined) {
                LibLoader_2.default.load("https://" + ya.mediaAd.DOMAIN + SWF_OBJECT_URL, function() {
                    callback(hasFlashPlayer());
                });
                return;
            }
            callback(hasFlashPlayer());
        }
        exports.checkForFlashPlayer = checkForFlashPlayer;
        function fetchStaticSwfVersion(packageName, build, onSuccess, onError) {
            var xhr = new XMLHttpRequest();
            var infoUrl = ("https://" + ya.mediaAd.DOMAIN + STATIC_SWF_INFO_URL).replace(/\{PACKAGE\}/g, packageName).replace(/\{BUILD\}/g, build) + Math.random();
            xhr.onreadystatechange = function() {
                if (xhr.readyState === XMLHttpRequest.DONE) {
                    if (xhr.status === 200) {
                        onSuccess(xhr.responseText.split("'")[1]);
                    } else {
                        onError(new Error(xhr.statusText));
                    }
                }
            };
            try {
                xhr.open("GET", infoUrl, true);
                xhr.send();
            } catch (error) {
                onError(error);
            }
        }
        function fetchStaticSwfUrl(packageName, build, onSuccess, onError) {
            fetchStaticSwfVersion(packageName, build, function(version) {
                onSuccess(("//" + ya.mediaAd.DOMAIN + STATIC_SWF_URL_BASE).replace(/\{PACKAGE\}/g, packageName).replace(/\{BUILD\}/g, build).replace(/\{VERSION\}/g, version));
            }, onError);
        }
        exports.fetchStaticSwfUrl = fetchStaticSwfUrl;
        function adConfigToFlashvars(adConfig, flashvars) {
            for (var propName in adConfig) {
                if (adConfig.hasOwnProperty(propName) && JS_TO_FLASH_AD_PARAMS_MAP[propName]) {
                    flashvars[JS_TO_FLASH_AD_PARAMS_MAP[propName]] = adConfig[propName];
                }
            }
            if (adConfig.adFoxUrl !== undefined) {
                flashvars["ad-fox-url"] = encodeURIComponent(adConfig.adFoxUrl);
            }
            if (adConfig.adFoxUrlMidRoll !== undefined) {
                flashvars["ad-fox-url-midroll"] = encodeURIComponent(adConfig.adFoxUrlMidRoll);
            }
            if (adConfig.adFoxUrlPauseRoll !== undefined) {
                flashvars["ad-fox-url-pauseroll"] = encodeURIComponent(adConfig.adFoxUrlPauseRoll);
            }
            if (adConfig.adFoxUrlPostRoll !== undefined) {
                flashvars["ad-fox-url-postroll"] = encodeURIComponent(adConfig.adFoxUrlPostRoll);
            }
            if (adConfig.vastUrl !== undefined) {
                flashvars["vast-url"] = encodeURIComponent(adConfig.vastUrl);
            }
            flashvars["target-referrer"] = encodeURIComponent(util_4.getReferrer());
            flashvars["page-referrer"] = encodeURIComponent(document.referrer) || "unknown";
        }
        exports.adConfigToFlashvars = adConfigToFlashvars;
    });
    define("inpage/FlashPlayer", [ "require", "exports", "util/flash_util", "util/util" ], function(require, exports, flash_util_1, util_5) {
        "use strict";
        var SWF_PLAYER_PACKAGE_NAME = "adplayer", SWF_PLAYER_BUILD = "1_2", MIN_FLASH_PLAYER_VERSION = "10.2";
        var FlashAdViewer = function() {
            function FlashAdViewer(adPlayer) {
                this.adPlayer = adPlayer;
            }
            FlashAdViewer.prototype.getAdDimensions = function() {
                try {
                    var targetWidth = this.adPlayer.getMediaWidth();
                    var targetHeight = this.adPlayer.getMediaHeight();
                } catch (e) {
                    return null;
                }
                return {
                    width: targetWidth,
                    height: targetHeight
                };
            };
            FlashAdViewer.prototype.pause = function() {
                this.adPlayer.pause();
            };
            FlashAdViewer.prototype.resume = function() {
                this.adPlayer.resume();
            };
            FlashAdViewer.prototype.changeMute = function(muted, fade) {};
            return FlashAdViewer;
        }();
        function sanitizeId(id) {
            return id.replace(/[^a-zA-Z0-9_]/g, "_");
        }
        function loadSwfPlayer(containerElement, insertId, swfUrl, adConfig, callback) {
            var flashvars = {
                onStateChange: "window.ya.mediaAd.inPage." + insertId + ".onStateChange",
                onError: "window.ya.mediaAd.inPage." + insertId + ".onError",
                "hide-ui": "true",
                autostart: "false",
                inpage: "true",
                "switch-volume-on-roll-over": "true"
            }, attributes = {
                id: containerElement.id,
                name: containerElement.id,
                bgcolor: "#000000",
                background: "#000000",
                width: "100%",
                height: "100%"
            }, params = {
                movie: swfUrl,
                allowfullscreen: "true",
                bgcolor: "#000000",
                allowscriptaccess: "always",
                wmode: "opaque"
            };
            flash_util_1.adConfigToFlashvars(adConfig, flashvars);
            swfobject.embedSWF(swfUrl, containerElement.id, "100%", "100%", MIN_FLASH_PLAYER_VERSION, null, flashvars, params, attributes, callback);
        }
        function createSwfAdPlayer(wrapper, adConfig, playerCallbacks) {
            function fireOnPlayerPrepared(arg) {
                util_5.fireCallback(playerCallbacks.onPlayerPrepared, arg);
                playerCallbacks.onPlayerPrepared = null;
            }
            var sanitizedElementId = sanitizeId(wrapper.id);
            var swfElement;
            ya.mediaAd.inPage[sanitizedElementId] = {
                onStateChange: function(state) {
                    if (state === "stop") {
                        util_5.fireCallback(playerCallbacks.onComplete);
                    }
                    if (state === "ready") {
                        fireOnPlayerPrepared(function showAd(onCreated) {
                            onCreated(null, new FlashAdViewer(swfElement));
                            swfElement.start();
                        });
                    }
                    if (state === "play") {
                        wrapper.style.width = "auto";
                        util_5.fireCallback(playerCallbacks.onVideoPlaying);
                    }
                },
                onError: function(errorString) {
                    fireOnPlayerPrepared(new Error(errorString));
                }
            };
            flash_util_1.fetchStaticSwfUrl(SWF_PLAYER_PACKAGE_NAME, SWF_PLAYER_BUILD, function(url) {
                var swfElementPlaceholder = document.createElement("div");
                wrapper.appendChild(swfElementPlaceholder);
                swfElementPlaceholder.id = wrapper.id + "swf";
                wrapper.style.overflow = "hidden";
                loadSwfPlayer(swfElementPlaceholder, sanitizedElementId, url, adConfig, function(param) {
                    if (param instanceof Error) {
                        fireOnPlayerPrepared(param);
                        return;
                    }
                    if (param.ref) {
                        swfElement = param.ref;
                    } else {
                        fireOnPlayerPrepared(new Error("Error creating object element."));
                    }
                });
            }, fireOnPlayerPrepared);
        }
        exports.createSwfAdPlayer = createSwfAdPlayer;
    });
    define("shared/rollover_mute", [ "require", "exports", "util/util" ], function(require, exports, util_6) {
        "use strict";
        function addRollOverMuteHandlers(wrapperElement, adViewer) {
            util_6.addTouchSafeMouseEnterHandler(wrapperElement, function() {
                adViewer.changeMute(false, true);
            });
            wrapperElement.addEventListener("mouseleave", function() {
                adViewer.changeMute(true, true);
            });
        }
        exports.addRollOverMuteHandlers = addRollOverMuteHandlers;
    });
    define("InPage", [ "require", "exports", "inpage/ViewportPlayerController", "inpage/HtmlPlayer", "inpage/FlashPlayer", "util/flash_util", "util/util", "shared/rollover_mute" ], function(require, exports, ViewportPlayerController_1, HtmlPlayer_1, FlashPlayer_1, flash_util_2, util_7, rollover_mute_1) {
        "use strict";
        if (!ya.mediaAd.inPage) {
            ya.mediaAd.inPage = {};
        }
        var DEFAULT_STARTUP_TIMEOUT = 1e3, PLAYER_TRANSITION_DURATION = .3, PLAYER_REMOVE_DELAY = PLAYER_TRANSITION_DURATION + .1, MIN_VIABLE_MEDIA_WIDTH = 200;
        function removeAdElement(adElement) {
            if (adElement && adElement.parentNode) {
                adElement.parentNode.removeChild(adElement);
            }
        }
        function closeAdElement(adElement) {
            adElement.style.height = adElement.clientHeight + "px";
            setTimeout(function() {
                adElement.style.height = "0px";
                setTimeout(function() {
                    removeAdElement(adElement);
                }, PLAYER_REMOVE_DELAY * 1e3);
            }, 20);
        }
        function adjustAdHeight(adElement, adViewer) {
            if (!adViewer) {
                util_7.adjustElementHeight(adElement);
                return;
            }
            var adSize = adViewer.getAdDimensions();
            if (adSize && adSize.width > MIN_VIABLE_MEDIA_WIDTH && adSize.height) {
                util_7.adjustElementHeight(adElement, adSize.width, adSize.height);
            }
        }
        function openContainer(containerElement, wrapper) {
            containerElement.style.height = wrapper.style.height;
            setTimeout(function() {
                var transitionStyle = containerElement.style.transition;
                containerElement.style.transition = "";
                containerElement.style.height = "auto";
                setTimeout(function() {
                    containerElement.style.transition = transitionStyle;
                }, 20);
            }, PLAYER_TRANSITION_DURATION * 1e3);
        }
        function prepareAdPlayer(containerElement, wrapperElement, adConfig, callbacks) {
            if (adConfig.slide) {
                containerElement.style.transition = "height " + PLAYER_TRANSITION_DURATION + "s ease-out";
            }
            if (!adConfig.visibleAfterInit) {
                containerElement.style.height = "0px";
            }
            if (adConfig.noFlash === true) {
                HtmlPlayer_1.createHtmlAdPlayer(wrapperElement, adConfig, callbacks);
                return;
            }
            flash_util_2.checkForFlashPlayer(function(hasFlashPlayer) {
                if (!hasFlashPlayer) {
                    HtmlPlayer_1.createHtmlAdPlayer(wrapperElement, adConfig, callbacks);
                    return;
                }
                if (!adConfig.visibleAfterInit) {
                    containerElement.style.height = "1px";
                    wrapperElement.style.width = "1px";
                    wrapperElement.style.height = "1px";
                }
                FlashPlayer_1.createSwfAdPlayer(wrapperElement, adConfig, {
                    onVideoPlaying: callbacks.onVideoPlaying,
                    onComplete: callbacks.onComplete,
                    onPlayerPrepared: function(showAdOrError) {
                        if (showAdOrError instanceof Error) {
                            if (!adConfig.visibleAfterInit) {
                                containerElement.style.height = "0px";
                            }
                            HtmlPlayer_1.createHtmlAdPlayer(wrapperElement, adConfig, callbacks);
                        } else {
                            util_7.fireCallback(callbacks.onPlayerPrepared, showAdOrError);
                        }
                    }
                });
            });
        }
        function validateAdConfig(adConfig) {
            if (!adConfig) {
                return new Error("Parameter 'adConfig' is required.");
            }
            var url = adConfig.adFoxUrl;
            if (url && !((url.indexOf("getCode?") > -1 || url.indexOf("getCodeTest?") > -1 || url.indexOf("prepareCode?") > -1 || url.indexOf("prepareCodeTest?") > -1) && (url.indexOf("pp=") > -1 && url.indexOf("ps=") > -1 && url.indexOf("p2=") > -1 || url.indexOf("p1=") > -1 && url.indexOf("p2=") > -1 || url.indexOf("pfc=") > -1 && url.indexOf("pfb=") > -1))) {
                return new Error("Invalid format of 'adConfig.adFoxUrl' parameter.");
            }
            return null;
        }
        function setupResizeSensor(containerElement, wrapperElement) {
            var lastWidth = containerElement.clientWidth;
            var resizeSensor = new ResizeSensor(containerElement, function onContainerResize() {
                if (lastWidth == containerElement.clientWidth) {
                    return;
                }
                adjustAdHeight(wrapperElement, resizeSensor.adViewer);
            });
            adjustAdHeight(wrapperElement);
            return resizeSensor;
        }
        function setupContainer(containerElementOrId, adConfig) {
            var containerElement = util_7.getElement(containerElementOrId, adConfig.insertAfter, adConfig.insertPosition), wrapperElement = document.createElement("div");
            wrapperElement.id = "wrapper" + containerElement.id;
            containerElement.appendChild(wrapperElement);
            var resizeSensor = setupResizeSensor(containerElement, wrapperElement);
            containerElement.style.overflow = "hidden";
            return {
                containerElement: containerElement,
                wrapperElement: wrapperElement,
                resizeSensor: resizeSensor
            };
        }
        function setupAdConfig(adConfig) {
            if (adConfig.beta) {
                ya.mediaAd.DOMAIN = "betastatic.yastatic.net";
            }
            adConfig.minimalGui = true;
            if (!adConfig.hasOwnProperty("noFlash")) {
                adConfig.noFlash = false;
            }
            if (adConfig.adFoxUrl) {
                adConfig.preferAdfox = false;
            }
            if (adConfig.startupTimeout === undefined) {
                adConfig.startupTimeout = DEFAULT_STARTUP_TIMEOUT;
            }
        }
        ya.mediaAd.inPage.addInPageVideo = function(containerElementOrId, adConfig, callback) {
            var adConfigValidationError = validateAdConfig(adConfig);
            if (adConfigValidationError) {
                util_7.fireCallback(callback, adConfigValidationError);
                return;
            }
            var _a = setupContainer(containerElementOrId, adConfig), containerElement = _a.containerElement, wrapperElement = _a.wrapperElement, resizeSensor = _a.resizeSensor;
            setupAdConfig(adConfig);
            var viewportController = new ViewportPlayerController_1.default(wrapperElement);
            viewportController.waitForInitialShow(checkForAdStart, adConfig.startupTimeout);
            var showAd;
            var adViewer;
            prepareAdPlayer(containerElement, wrapperElement, adConfig, {
                onPlayerPrepared: function(showAdOrError) {
                    if (showAdOrError instanceof Error) {
                        removeAdElement(containerElement);
                        util_7.fireCallback(callback, showAdOrError);
                        return;
                    }
                    showAd = showAdOrError;
                    checkForAdStart();
                },
                onVideoPlaying: function() {
                    adjustAdHeight(wrapperElement, adViewer);
                    openContainer(containerElement, wrapperElement);
                },
                onComplete: function() {
                    closeAdElement(containerElement);
                    viewportController.dispose();
                    resizeSensor.detach();
                }
            });
            function checkForAdStart() {
                if (!showAd || !viewportController.getIsInViewport()) {
                    return;
                }
                showAd(function onAdReady(error, adViewerParam) {
                    if (error) {
                        viewportController.dispose();
                        return;
                    }
                    adViewer = adViewerParam;
                    viewportController.monitorPlayback(adViewer);
                    rollover_mute_1.addRollOverMuteHandlers(wrapperElement, adViewer);
                    resizeSensor.adViewer = adViewer;
                    util_7.fireCallback(callback, adViewer);
                });
            }
        };
    });
    var verge = this.verge;
    require("InPage");
}).call({}, window);
//# sourceMappingURL=inpage.js.map
