// 
  var evVarDebuggingOutput = false
  // 

  function logToConsole () {
    if(typeof evVarDebuggingOutput !== 'undefined' && evVarDebuggingOutput === true) {
      var grayb = 'color:white;background:darkgray;padding:4px;border-radius:4px;'
      console.log('%cReely', grayb, ...arguments)
    }
  }
  function warnToConsole () {
    if(typeof evVarDebuggingOutput !== 'undefined' && evVarDebuggingOutput === true) {
      var orangeb = 'color:white;background:darkorange;padding:4px;border-radius:4px;'
      console.warn('%cReely', orangeb, ...arguments)
    }
  }
  function loggfdnpbjs () {
    if(typeof evVarDebuggingOutput !== 'undefined' && evVarDebuggingOutput === true) {
      var greenb = 'color:white;background:forestgreen;padding:4px;border-radius:4px;'
      console.log('%cfdnpbjs', greenb, ...arguments)
    }
  }

    

    

    
    
    
    
    
    


    
    

    (function() {
      // houstonpress

      /*  */

      window.Reely = window.Reely || {}
      Reely.PlayerEmbedList = Reely.PlayerEmbedList || []
      Reely.PlayerEmbeds = Reely.PlayerEmbeds || {}

      var playerEmbedId = 'real1-player-' + (Reely.PlayerEmbedList.length + 1)
      Reely.PlayerEmbedList.push(playerEmbedId)

      Reely.PlayerEmbeds[playerEmbedId] = {
        id: playerEmbedId,
        iframeElement: null,
        scriptElement: null,
        inViewFocusTypes: ['scroll','blur','focus','resize'],
        interactionTypes: ['click','tap','scroll','resize'],
        init () {
          if (this.iframeElement != null || this.scriptElement != null) {
            logToConsole('TSV EmbedJS', 'Reely.PlayerEmbeds[' + this.id + '] already initiated.')
            return;
          }

          var embedInstance = this

          this.iframeElement = document.createElement('iframe')
          this.iframeElement.id = this.id + '-iframe'
          this.iframeElement.src = 'https://www.hub.fdncms.com/gyrobase/Responsive/Components/Content/TopStoriesVideo?cb=9a9fc4ca&key=4c13beaef3305ae21a81a3df96a5343e&req=iframe&vrd=null&vri=2'
          this.iframeElement.style.setProperty("width", "100%")
          this.iframeElement.style.setProperty("height", "100%")
          this.iframeElement.style.setProperty("border", "0")
          this.iframeElement.onload = function () {
            embedInstance.reportInViewAndFocusData()
            embedInstance.reportReferringDomain()
            embedInstance.reportEmbedId()
          }

          this.scriptElement = document.querySelector('#fdncms-carousel-top-stories-video')
          this.scriptElement.id = this.scriptElement.id + this.id + '-script'
          this.scriptElement.parentNode.insertBefore(this.iframeElement, this.scriptElement)

          for (const focusType of this.inViewFocusTypes) {
            // logToConsole('TSV EmbedJS', 'adding listener for: ' + focusType)
            window.addEventListener(focusType, function (e) {
              embedInstance.inViewAndFocusHandler(e)
            })
          }

          for(const interactionType of this.interactionTypes) {
            // logToConsole('TSV EmbedJS', 'adding listener for: ' + interactionType)
            window.addEventListener(interactionType, function (e) {
              embedInstance.interactionHandler(e)
            })
          }

          /*  */
          window.addEventListener('message', function(e) {
            if(e.origin.match(/^https\:\/\/.*fdncms.com$/)) {

              // Validate datas 
              if(typeof e.data.FDNCarouselHeight === 'number') {
                embedInstance.iframeElement.style.setProperty("height", e.data.FDNCarouselHeight + "px")
              }

              if (typeof Reely.PrebidEmbedTools === 'object') {
                if (typeof Reely.PrebidEmbedTools.requestSomeBids === 'function') {
                  // Validate datas 

                  logToConsole('TSV EmbedJS', 'message received requestSomeBids', e.origin, e)
                  if (typeof e.data.FDNPrebidRequestBids === 'string'
                      && embedInstance.id === e.data.FDNPrebidRequestBids) {
                    Reely.PrebidEmbedTools.requestSomeBids(embedInstance.id)
                  }
                }
              }
            }
          })
        },

        reportInViewAndFocusData () {
          var documentHasFocus = document.hasFocus()
          var boundingRect = this.iframeElement.getBoundingClientRect()
          this.iframeElement.contentWindow.postMessage({
            FDNIframeInParentBoundingRectHeight: boundingRect.height,
            FDNIframeInParentBoundingRectTop: boundingRect.top,
            FDNParentInnerHeight: window.innerHeight,
            FDNParentHasFocus: documentHasFocus,
          },'*')
        },

        reportReferringDomain () {
          this.iframeElement.contentWindow.postMessage({
            FDNReferringDomain: window.location.origin,
          },'*')
        },

        reportEmbedId () {
          logToConsole('TSV EmbedJS', 'reportEmbedId: ' + this.id)
          this.iframeElement.contentWindow.postMessage({
            FDNEmbedId: this.id,
          },'*')
        },

        reportInteractionData () {
          this.iframeElement.contentWindow.postMessage('interactions were had','*')
        },

        inViewAndFocusHandler (e) {
          // logToConsole('TSV EmbedJS', this.inViewFocusTypes,e)
          if(this.inViewFocusTypes.includes(e.type)) {
            // logToConsole('TSV EmbedJS', e.type + ' inViewAndFocusHandler fired')
            this.reportInViewAndFocusData()
          }
        },

        interactionHandler(e) {
          if(this.interactionTypes.includes(e.type)) {
            // logToConsole('TSV EmbedJS', e.type + ' interactionHandler fired')
            this.reportInteractionData()
          }
        },
      }

      Reely.PlayerEmbeds[playerEmbedId].init()
    })()
