# ta funkcja wołana jest bezpośrednio przez API Youtube i musi być
# dostępna globalnie
@.onYouTubeIframeAPIReady = ->
  onPlayerReady = (event) ->
    playButton = $('#play-button')
    playButton.on('click', ->
      player.playVideo();
      $('#overlay').hide();
    )
    skipButton = $('#skip-button')
    skipButton.on('click', ->
      $('#video-container').hide();
    )

  onPlayerStateChange = (event) ->
    containerButton = $('#video-container')
    containerButton.on('click', (e) ->
      if e.target != this
        return
      $('#video-container').hide();
      return
    )

  videoId = $('#player').data('video-id')

  player = new (YT.Player)('player',
    height: '531'
    width: '944'
    videoId: videoId
    playerVars:
      'showinfo': 0
      'rel': 0
    events:
      'onReady': onPlayerReady
      'onStateChange': onPlayerStateChange
  )
  return

@.youTubeIframeHandler = ->
  tag = document.createElement('script')
  tag.src = 'https://www.youtube.com/iframe_api'
  firstScriptTag = document.getElementsByTagName('script')[0]
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag)
  player = undefined
  return
