function flash_url_from_page_url(url) {
  if (url.match(/vimeo.com/)) {
    return vimeo_flash_url_from_page_url(url);
  } else {
    return youtube_flash_url_from_page_url(url);
  }
}

function vimeo_flash_url_from_page_url(url) {
  var matches = url.match(/\/(\d+)/);
  var id = matches[1];
  return 'http://vimeo.com/moogaloop.swf?clip_id=' + id + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=' + id + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1';
}

function youtube_flash_url_from_page_url(url) {
  var matches = url.match(/\?v=([A-Za-z0-9]+)/);
  var id = matches[1];
  return 'http://www.youtube.com/v/' + id + '&hl=en_GB&fs=1';
}

$(document).ready(function () {
  swfobject.embedSWF(initial_flash_url, "player", player_width, player_height, "9.0.0", false, flashvars, params, attributes);
  
  $('.podcasts li.video a').click(function (event) {
    var url = $(this).attr('href');
    var swf_url = flash_url_from_page_url(url);
    swfobject.embedSWF(swf_url, "player", player_width, player_height, "9.0.0", false, flashvars, params, attributes);
    return false;
  });
  $('.podcasts li.podcast a').click(function (event) {
    var item = $(this).closest('li');
    var id = item.attr('id').replace('article-', '');
    window.open('/audio.php?id=' + id, 'audio', 'height=200,width=230,scrollbars=no,toolbar=no');
    return false;
  });
})