title: How to use SWFObject correctly
body: <p>I am using SWFObject to embed YouTube videos into our website. There are many links to videos in one page and each link clears a wrapper div, then loads a new embed into it, with this code:</p>
  
  <pre><code>$('a.video-link').each(function () {
      $(this).on('click', function(e) {
          e.preventDefault();
  
          if ($('#video-wrap').has('object').length == 0) {
              var params = { allowScriptAccess: 'always', allowFullScreen: 'true' };
              var atts = { id: 'ytapiplayer' };
              swfobject.embedSWF($(this).attr('href'), 'ytapiplayer', '1000', '562', '8', null, null, params, atts);
              $('#video-wrap').show();
          } else {
              $('#video-wrap').find('object').remove();
              $(this).trigger('click');
          }
      });
  });
  </code></pre>
  
  <p>These are the Youtube links I am using for each embed:</p>
  
  <pre><code>http://www.youtube.com/v/{Youtube ID}?hl=en_US&amp;rel=0&amp;hd=1&amp;border=0&amp;version=3&amp;fs=1&amp;autoplay=1&amp;autohide=1&amp;enablejsapi=1&amp;playerapiid=ytapiplayer
  </code></pre>
  
  <p>Then, here is the onYouTubePlayerReady() event handler:</p>
  
  <pre><code>function onYouTubePlayerReady(id) {
      console.log('youtube player is ready.');
      var ytplayer = document.getElementById('ytapiplayer');
      ytplayer.addEventListener('onStateChange', 'onYouTubePlayerStateChange');
      ytplayer.addEventListener('onError', 'onYouTubePlayerError');
  }
  </code></pre>
  
  <p><strong>All videos load fine, however the onYouTubePlayerReady is never hit!</strong></p>
  
  <p>I have tried solutions from <a href="https://stackoverflow.com/questions/2083128/youtube-api-not-firing-onyoutubeplayerready">here</a> and <a href="https://stackoverflow.com/questions/2001558/embed-youtube-video-without-youtube-link">here</a> but nothing worked :(</p>
  
  <p>Please help me solve this problem. <strong>The ultimate goal is to get the Youtube API to work.</strong></p>
  
  <p>Thanks.</p>
  
  <p>EDIT: I tried to play with the code, make sure all names are correct, separate into different script tags and/or .js file, load it on the beginning, inside document.ready(), still, onYouTubePlayerReady is not firing. <strong>What do you think?</strong></p>