jQuery(function() {
  jQuery("a.flashMovie").ReplaceByFlashMovie();
});

// on $(document).ready
(function($){
 /*
  Replaces an a-tag by a flashmovie
  */
  $.createFlashMovie = function (targetObj,flashUrl,w,h,id) {
    targetObj.removeChild(targetObj.firstChild);
    var o = document.createElement("object");
    o.id = id;
    o.width = w;
    o.height = h;
    var p1 = document.createElement("param");
    p1.name = "movie";
    p1.value = baseUrl+flashUrl.substring(1);
    o.appendChild(p1);
    var p2 = document.createElement("param");
    p2.name = "quality";
    p2.value = "high";
    var p3 = document.createElement("param");
    p3.name = "wmode";
    p3.value = "transparent";
    o.appendChild(p3);
    var p4 = document.createElement("param");
    p4.name = "play";
    p4.value = "true";
    o.appendChild(p3);
    var em = document.createElement("embed");
    em.src = flashUrl;
    em.type = "application/x-shockwave-flash";
    em.quality = "high";
    em.wmode = "transparent";
    em.play = "true";
    em.id = id;
    em.width = w;
    em.height = h;
    targetObjParent = targetObj.parentNode;
    targetObjParent.removeChild(targetObj);
    try {
      o.appendChild(em);
      targetObjParent.appendChild(o);
    }
    catch (e) {
      targetObjParent.appendChild(em);
    }
  }

 /*
  Chain functions down here
  */
  
 /*
  Replaces links by an iframe with src = href
  Returns the filtered wrapped set
  */
  $.fn.ReplaceByFlashMovie = function() {
      $(this).filter("a[href]").each(function() {
        var dims = $(this).attr('title').split('Flash: ')[1];
        var width = (dims && dims != '')?dims.split(',')[0]:249;
        var height = (dims && dims != '')?dims.split(',')[1]:249;
        var id = $(this).attr('id');
        
        $.createFlashMovie(this,$(this).attr("href"),width,height,id)
      }); 
    };
})(jQuery); 