
(function(w, d) {
  try {
    d = w.top.document || d; w = w.top.document ? w.top : w;
  } catch (e) {}
  var ttag = function() {
    var pageScript = document.querySelector("script[data-ob-106564]");
    var obSessionId = pageScript ? pageScript.getAttribute("data-ob-106564") : "";
    var bridgeName = "teadsObj" + obSessionId;
    var slot = ".teads" + obSessionId;
    

    if (pageScript) {
      pageScript.removeAttribute("data-ob-106564");
    }

    window[bridgeName] = {
      AdLoaded: [],
      AdImpression: [],
      AdStarted: [],
      AdStopped: [],
      AdSkipped: [],
      AdVideoStart: [],
      AdVideoFirstQuartile: [],
      AdVideoMidpoint: [],
      AdVideoThirdQuartile: [],
      AdVideoComplete: [],
      AdClickThru: [],
      AdUserClose: [],
      AdPaused: [],
      AdPlaying: [],
      AdError: [],
      mute: [],
      unmute: [],
      noAd: [],
      AdRemainingTimeChange: []
    };

    function teadsEvent(eventType) {
      if (window[bridgeName] && window[bridgeName][eventType] && window[bridgeName][eventType].length) {
        var eventArray = window[bridgeName][eventType];
        for (var i = 0; i < eventArray.length; i++) {
          eventArray[i]();
        }
      }
    }
function isPubCPMAlreadySet() {
  return !!window[bridgeName] && !!window[bridgeName].pubCPM;
}
function addPubCPMIfCostExistOnResources(resources) {
  if (!isPubCPMAlreadySet()) {
    for (var j = 0; j < resources.length; j++) {
      var url = resources[j].url;
      var splitedUrl =
        url && url.split ? url.split("&costForPublisher=") : [];
      if (splitedUrl.length > 1) {
        window[bridgeName].pubCPM = splitedUrl[1].split("&")[0];
      }
    }
  }
}
function setCFP() {
  var tags = w.teads.ArrayHelper.filter(w.teads.TAG[106564][115544],function(t) {return !!t.formatInstance.value;});
  var tag = tags[tags.length - 1];
  var inread = tag.formatInstance.value;
  if (!!inread.linearAd.tracking.start) {
    addPubCPMIfCostExistOnResources(inread.linearAd.tracking.start);
  }
  if (!!inread.linearAd.tracking.impression) {
    addPubCPMIfCostExistOnResources(inread.linearAd.tracking.impression);
  }
}
    var durationSent = false;
    var playerWrapper = window.document.querySelector(".teads").parentNode.parentNode;
    var playerWrapperHeight = playerWrapper.offsetHeight;
    var playerDivHeight = playerWrapper.children[0].offsetHeight;
    var videoText = playerWrapper.children[1];
    var ratioCheck = playerWrapper.offsetWidth / playerWrapper.offsetHeight;
    if ((ratioCheck > (16 / 9)) && videoText) {
        var videoTextHeight = videoText.offsetHeight;
        var teadsPlayerWidth = (playerWrapperHeight - videoTextHeight) * 16 / 9;
        var _tt_css = "margin: 0px auto; max-width: " + teadsPlayerWidth + "px;";
    } else if (ratioCheck > (16 / 9)) {
        var teadsPlayerWidth = (playerWrapperHeight) * 16 / 9;
        var _tt_css = "margin: 0px auto; max-width: " + teadsPlayerWidth + "px;";
    } else if ((ratioCheck < (16 / 9)) && videoText) {
        var videoTextHeight = videoText.offsetHeight;
        var teadsPlayerWidth = (playerWrapperHeight - videoTextHeight) * 16 / 9;
        var _tt_css = "margin: 0px auto; max-width: " + teadsPlayerWidth + "px;";
        var playerMargin = (playerWrapperHeight - (playerWrapper.offsetWidth / (16 / 9))) / 2;
        playerWrapper.children[0].setAttribute("style", "margin-top: " + playerMargin + "px;");
        playerWrapper.style.background = "black";
    } else if (ratioCheck < (16 / 9)) {
        var teadsPlayerWidth = (playerWrapperHeight) * 16 / 9;
        var _tt_css = "margin: 0px auto; max-width: " + teadsPlayerWidth + "px;";
        var playerMargin = (playerWrapperHeight - (playerWrapper.offsetWidth / (16 / 9))) / 2;
        playerWrapper.children[0].setAttribute("style", "margin-top: " + playerMargin + "px;");
        playerWrapper.style.background = "black";
    } else {
        var teadsPlayerWidth = (playerWrapperHeight) * 16 / 9;
        var teadsHeight = playerWrapper.offsetWidth / (16 / 9);
        var teadsMarginTop = (playerWrapperHeight - teadsHeight) / 2 + "px";
        var _tt_css = "margin: " + teadsMarginTop + " auto 0px; max-width: " + teadsPlayerWidth + "px;";
        playerWrapper.style.background = "black";
    }
    var teadsPlayerWrapper = window.document.querySelector(".teads").parentNode;
    if (teadsPlayerWrapper) {
        teadsPlayerWrapper.style.background = "black";
    }

    w.teads.page(106564).placement(115544, {slider: {allow_corner_position: false, allow_top_position: false}, "callbacks":{
      "AdLoaded":function () {teadsEvent("AdLoaded");},
      "AdStarted":function () {teadsEvent("AdStarted");},
      "AdStopped":function () {teadsEvent("AdStopped");},
      "AdSkipped":function () {teadsEvent("AdSkipped");},
      "AdVideoStart":function () {
        setCFP();teadsEvent("AdVideoStart");
        var teadsPlayers = window.document.querySelectorAll(".teads-player");
        for (var i = 0; i < teadsPlayers.length; i++) {
            var clickButton = teadsPlayers[i].children[0].contentWindow.document.querySelector(".teads-ui-component-clickbutton");
            if (clickButton) {
                clickButton.setAttribute("style", "display: none!important;");
            }
        }
       },
       "AdVideoFirstQuartile":function () {teadsEvent("AdVideoFirstQuartile");},
       "AdVideoMidpoint":function () {teadsEvent("AdVideoMidpoint");},
       "AdVideoThirdQuartile":function () {teadsEvent("AdVideoThirdQuartile");},
       "AdVideoComplete":function () {teadsEvent("AdVideoComplete");},
       "AdClickThru":function () {teadsEvent("AdClickThru");},
       "AdPaused":function () {teadsEvent("AdPaused");},
       "AdPlaying":function () {teadsEvent("AdPlaying");},
       "AdError":function () {teadsEvent("AdError");},
       "mute":function () {teadsEvent("mute");},
       "unmute":function () {teadsEvent("unmute");},
       "AdRemainingTimeChange":function () {
          var adDuration = teads.instances.inread[0].adDuration;
          if (!durationSent && adDuration > 0) {
              teadsEvent("adDuration: " + adDuration);
          }
        },
        "AdUserClose":function () {teadsEvent("AdUserClose");},
        "AdImpression":function () {
          setCFP();
          teadsEvent("AdImpression");
        }
     },"format":"inread","slot":{"insertBefore":true,"btf":false,"selector":slot,"minimum":1}}).serve();
  };
  if (w.teads && w.teads.page) { ttag(); }
  else if (!w.teadsscript) {
    var s = document.createElement('script');
    var protocol = 'https:';
    s.src = protocol + '//static.teads.tv/static/master/media/format/v3/teads-format.min.js';
    s.async = true; s.onload = ttag; w.teadsscript = d.getElementsByTagName('head')[0].appendChild(s);
  } else {
    w.teadsscript.addEventListener('load', ttag);
  }
})(window, document);
