jQuery - moving embedded video to top?
<p>The code below will find an image if it exists and move it above the title and text.  So, if the markup looks like this:</p>

<pre><code>&lt;h2&gt;Some fancy title&lt;/h2&gt;
&lt;p&gt;Some interesting text&lt;/p&gt;
&lt;img src="someimage.jpg" /&gt;
</code></pre>

<p>or even this:</p>

<pre><code>&lt;p&gt;&lt;h2&gt;Some fancy title&lt;/h2&gt;&lt;/p&gt;
&lt;img src="someimage.jpg" /&gt;
&lt;p&gt;Some interesting text&lt;/p&gt;
</code></pre>

<p>It will reposition elements so that it looks like this:</p>

<pre><code>&lt;img src="someimage.jpg" /&gt;
&lt;h2&gt;Some fancy title&lt;/h2&gt;
&lt;p&gt;Some interesting text
</code></pre>

<p>Now, I'm trying to figure out how to rework the code so that if there's a video in the content (whether or not the post also has images), it will move the video above everything else.  Can someone suggest or show me a way to do that?</p>

<p>This is the current code, as I have it right now:</p>

<pre><code>$j('#hp-featured-item &gt; div[id^="post-"]').each(function() {
  if($j(this).find('embed')) {
  var id=this.id.match(/^post-([0-9]+)$/);
  var imgt = $j("img:eq(0)");
  var pt = $j("p:not(:has(img)):eq(0)");
  var hh = $j("h2:eq(0)");
  $j(this).html('');
  $j(this).append(imgt).append(hh).append(pt);
  $j(this).each(function() {
   var img = $j('img');
   $j(img).wrap($j('&lt;a&gt;').attr('href', '/blog/?p='+id[1]));
   var h2 = $j('h2');
   $j(h2).wrap($j('&lt;a&gt;').attr('href', '/blog/?p='+id[1]));
  });
  } else {
   var id=this.id.match(/^post-([0-9]+)$/);
   var imgt = $j("embed:eq(0)");
   var pt = $j("p:not(:has(embed)):eq(0)");
   var hh = $j("h2:eq(0)");
   $j(this).html('');
   $j(this).append(imgt).append(hh).append(pt);
   $j(this).each(function() {
    var img = $j('embed');
    $j(img).wrap($j('&lt;a&gt;').attr('href', '/blog/?p='+id[1]));
    var h2 = $j('h2');
    $j(h2).wrap($j('&lt;a&gt;').attr('href', '/blog/?p='+id[1]));
   });
  }
 });
</code></pre>
