$(document).ready(function(){

if( navigator.userAgent.match(/Android/i) ||
 navigator.userAgent.match(/webOS/i) ||
 navigator.userAgent.match(/iPhone/i) ||
 navigator.userAgent.match(/Mobile/i) ||
 navigator.userAgent.match(/Smartphone/i) ||
 navigator.userAgent.match(/iPod/i)
 ){
 return;
}  
  var sSel = 'a[href^="http://www.youtube.com/watch"]:not(.dont-embed)';
  sSel += ',a[href^="http://youtube.com/watch"]:not(.dont-embed)';
  sSel += ',a[href^="http://www.youtube.com/view_play_list"]:not(.dont-embed)';
  sSel += ',a[href^="http://youtube.com/view_play_list"]:not(.dont-embed)';
  $(sSel).each( function(){
    SetupYoutubeVideo(this);
  });
});

function SetupYoutubeVideo(oVideoEle)
{

  if($(oVideoEle).hasClass('smaller-video')) {
    nWidth  = 400
    nHeight = 245
  } else if($(oVideoEle).hasClass('trust-video')) {
    nWidth  = 354
    nHeight = 213
  } else if($(oVideoEle).hasClass('news-story')) {
    nWidth  = 440
    nHeight = 270
  } else if($(oVideoEle).hasClass('header-video')) {
    nWidth  = 392
    nHeight = 234
  } else {
    nWidth  = 480
    nHeight = 295
  }
  $(oVideoEle).flash(
  { width: nWidth, height: nHeight, wmode: 'transparent' },
  { version: 8 },
  function(htmlOptions) {

    // first check for playlist
    if($(oVideoEle).attr('href').match('view_play_list')) {
      bPlaylist = true
      // aMatches = /p=(.+?)(&|$)/i.exec($(oVideoEle).attr('href'))
      aMatches = /[\?|&]p=([^&]+)/i.exec($(oVideoEle).attr('href'))
      href = aMatches[1]
    } else {
      bPlaylist = false
      // aMatches = /v=(.+?)(&|$)/i.exec($(oVideoEle).attr('href'))
      aMatches = /[\?|&]v=([^&]+)/i.exec($(oVideoEle).attr('href'))
      href = aMatches[1]
    }
    if(bPlaylist) {
      htmlOptions.src = "http://youtube.com/p/" + href;
    } else {
      htmlOptions.src = "http://youtube.com/v/" + href;
    }
    //$(oVideoEle).parent().css("text-align","center")
    $(oVideoEle).css("display","block")
   // $(oVideoEle).css("text-align","center")
    $(oVideoEle).before($.fn.flash.transform(htmlOptions));
    if($(oVideoEle).hasClass('header-video')) {
      $(oVideoEle).children('img').remove();
    } 
  }
  );
}

$(document).ready(function(){
if( navigator.userAgent.match(/Android/i) ||
 navigator.userAgent.match(/webOS/i) ||
 navigator.userAgent.match(/iPhone/i) ||
 navigator.userAgent.match(/Mobile/i) ||
 navigator.userAgent.match(/Smartphone/i) ||
 navigator.userAgent.match(/iPod/i)
 ){
 return;
}    
  $('a.header-thumbvideo').click(function() {
    var sHTML = '';
    sHTML = '<a href="'+$(this).attr('href')+'" title="'+$(this).attr('title')+'" class="header-video"></a>';
    sHTML += $(this).attr('title');
    $('div#video-container').html(sHTML);
    SetupYoutubeVideo($('div#video-container a'));
    return false;
  });
  
})


