// arg0 = href
// arg1 = width
// arg2 = height
// arg3 = [] args (json)

$.fn.createFlashObject = function(href, width, height, args) {
  var href = href ? href : $(this).attr("href");
  var id = $(this).attr("id");
  // var width = width && width < 426 ? width : 425;
  // var height = height && height < 345 ? height : 344;
  var args = args ? args : { 'allowFullScreen': 'true' }

  $(this).get(0).removeChild($(this).get(0).firstChild);

  var o = document.createElement("object");
  if (id) o.id = id;
  if (width) o.width = width;
  else o.width = 425;
  if (height) o.height = height;
  else o.height = height = 344;

  var p1 = document.createElement("param");
  p1.name = "movie";
  p1.value = href;
  o.appendChild(p1);

  var p2 = document.createElement("param");
  p2.name = "type";
  p2.value = "application/x-shockwave-flash";
  o.appendChild(p2);

  for (var arg in args) {
    var prm = document.createElement("param");
    prm.name = arg.toLowerCase();
    prm.value = args[arg];
    o.appendChild(prm);
  }

  var em = document.createElement("embed");
  em.src = href;
  em.type = "application/x-shockwave-flash";

  for (var arg in args) {
    var param = document.createElement("param");
    em.setAttribute(arg, args[arg]);
    //eval("em." + arg + " = '" + args[arg] + "'");
    // eval("em."+arg.toLowerCase()+" = '"+args[arg]+"'");
  }

  if (id) em.id = id;
  if (width) em.width = width;
  else em.width = 425;
  if (height) em.height = height;
  else em.height = 344;
  targetObjParent = $(this).get(0).parentNode;
  targetObjParent.removeChild($(this).get(0));
  try {
    o.appendChild(em);
    targetObjParent.appendChild(o);
  }
  catch (e) {
    targetObjParent.appendChild(em);
  }

  return this;
};