title: cannot call method replace on undefined script issues
body: <p>What I am trying to do below since I don't have access to the PHP to my site, I am using this code to work around it. It will search for any links containing the two listed below. one from youtube with the /watch? in it and the other from youtube with just the /v in the url. It also is searching the any embedded elements. Problem is when I run the script it breaks all the other codes because of the error.</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot call method 'replace' of undefined </p>
  </blockquote>
  
  <p>Which is a pain in the butt! So I took it over to FF, says variable WT is not defined clearly it is though. Well it may not be since I used it outside the scope of the if statement. I'm not sure how to ensure if the link exist run the code. As well as if the Embed exist run the code too. These will be in my users post and want them automatically changed to work with my fancybox. </p>
  
  <p><a href="http://jsbin.com/agasux/1/edit" rel="nofollow">Here is a live example</a></p>
  
  <p>Its the copied markup from my page with a quick linked CSS so don't mind the buggy look.</p>
  
  <pre><code>$(function() {
      //if link contains /watch?
      var t = $('.entry-content div div a[href*="youtube.com/watch?"]').attr('href');
      if(typeof t !== "undefined") {
          //do nothing don't run the script below
      } else {
          var d = $('.entry-content div div a[href*="youtube.com/watch?"]');
          var newsrc = t.replace('watch?','');
          var asrc = newsrc.replace('=','/');
          var g = asrc.replace('http://www.','http://img.');
          var s = g.replace('v','vi');
          d.attr('class','ez_video');
          d.attr('href', asrc).html('&lt;img src="'+ s +'/0.jpg"/&gt;');
      }
      //if link contains /v
      var wt = $('.entry-content div div a[href*="youtube.com/v"]').attr('href');
  
      if(typeof wt !== "undefined") {
          //do nothing don't run script below
      } else {
          var wd = $('.entry-content div div a[href*="youtube.com/v"]');
          var o = wt.replace('http://www.','http://img.');
          var v = o.replace('v','vi');
          wd.attr('class','ez_video');
          wd.attr('href', v).html('&lt;img src="'+ v +'/0.jpg"/&gt;');
      }
  
      //if embeded file
      var src = $('.entry-content').find('embed').attr('src');
      if (typeof src !== "undefined") {
          //do nothing again unless true run script below
      } else {
          var qload = src.replace('http://youtube.com/v/','');
          var y = src.replace('http://','http://img.');
          var imgsrc = y.replace('v','vi');
          $('embed').before('&lt;a class="ez_video" id="'
              + qload +'" href="'+ src +'"&gt;&lt;img src="'
              + imgsrc +'/0.jpg" tile="" alt=""/&gt;&lt;/a&gt;');
          $('embed').remove();
  
      } 
      //Now make all work with the fancybox
  
      $('.ez_video').fancybox({
          'autoScale'     : false,
          'transitionIn'  : 'elastic',
          'transitionOut' : 'elastic',
          'width'         : 854,
          'height'        : 480,
          'type'          : 'swf',
          'swf'           : {
              'wmode'             : 'transparent',
              'allowfullscreen'   : 'true'
          }
      });
  });
  </code></pre>