title: Close youtube video iframe after finished not working
body: <p>I have a youtube iframe video, and I want to close it when it ends.
  This should be working, but it is not. The fancybox launches and the video displays correctly,  but none of the <code>console.log</code> appears. What am I doing wrong?</p>
  
  <pre><code>        $.fancybox({
            href: "https://www.youtube.com/embed/8CR-zM6jwD8?rel=0&amp;autoplay=1",
            type: "iframe",
            beforeShow: function () {
                // Find the iframe ID
                var id = $.fancybox.inner.find('iframe').attr('id');
                // Create video player object and add event listeners
                var player = new YT.Player(id, {
                    events: {
                        'onStateChange': function (event) {
                          console.log('onStateChange fired');
                            if (event.data === 0) {
                                console.log('ended');
                                $.fancybox.close();
                            } // if
                        } // onStateChange
                    } // events
                }); // YT.Player
  
                loadPage();
            }, // beforeShow
        }); // fancybox
  </code></pre>
  
  <p><a href="http://jsfiddle.net/7r2ncdcr/" rel="nofollow">JSFIDDLE</a></p>