function wmpIsMac() {
  return (navigator.userAgent.indexOf("Mac") > -1);
}

function wmpEmbed64(stream, width, height) {
  document.write('<embed type="application/x-mplayer2"');
  document.write(' pluginspage="http://www.microsoft.com/windows/windowsmedia/"');
  document.write(' src="'+stream+'"');
  document.write(' name="wmpPlayer"');
  document.write(' showstatusbar=1');
  document.write(' showcontrols=1');
  document.write(' showgotobar=0');
  document.write(' EnableContextMenu=1');  
  document.write(' InvokeURLs=0'); 
  document.write(' width="' + width + '" height="' + height + '">');
  document.write('</embed>');
}

function wmpObject64Begin(stream, width, height) {
  document.write('<object id="wmpPlayer"');
  document.write(' classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"');
  document.write(' standby="Loading components..."');
  document.write(' type="application/x-oleobject"');
  document.write(' width="' + width + '" height="' + height + '">');
  document.write('  <param name="filename" value="'+stream+'">');
  document.write('  <param name="autostart" value="true">');
  document.write('  <param name="transparentatstart" value="true">');
  document.write('  <param name="animationatstart" value="false">');
  document.write('  <param name="showcontrols" value="true">');
  document.write('  <param name="showstatusbar" value="true">');
  document.write('  <param name="showgotobar" value="false">');
  document.write('  <param name="showdisplay" value="false">');
  document.write('  <param name="EnableContextMenu" value="true">');
  document.write('  <param name="InvokeURLs" value="false">');
}

function wmpObject7or9Begin(stream, width, height) {
  document.write('<object id="wmpPlayer"');
  document.write(' classid="CLSID:6bf52a52-394a-11d3-b153-00c04f79faa6"');
  document.write(' standby="Loading components..."');
  document.write(' type="application/x-oleobject"');
  document.write(' width="' + width + '" height="' + height + '">');
  document.write('  <param name="url" value="'+stream+'">');
  document.write('  <param name="autostart" value="true">');
  document.write('  <param name="showcontrols" value="true">');
  document.write('  <param name="showstatusbar" value="true">');
  document.write('  <param name="showgotobar" value="false">');
  document.write('  <param name="showdisplay" value="false">');
  document.write('  <param name="enablecontextmenu" value="true">');
  document.write('  <param name="uimode" value="full">');
  document.write('  <param name="stretchToFit" value="true">');
  document.write('  <param name="InvokeURLs" value="false">');
}

function wmpObjectEnd() {
  document.write('</object>');
}

function insertPlugin(stream, width, height) {
  var detect;

  if (width == undefined)
    width = 320;

  if (height == undefined)
    height = 305;

  if (wmpIsMac()) {
    detect = "Mac OS: embed WMP 6.4";
    wmpObject64Begin(stream, width, height);
    wmpEmbed64(stream, width, height);
    wmpObjectEnd();
  } else if (window.ActiveXObject) {
    var wmp7or9;

    wmp7or9 = new ActiveXObject("WMPlayer.OCX.7");

    if (wmp7or9) {
      detect = "Modern IE: object WMP 7 or 9";
      wmpObject7or9Begin(stream, width, height);
      wmpEmbed64(stream, width, height);
      wmpObjectEnd();
    } else {
      detect = "Modern IE: object WMP 6.4";
      wmpObject64Begin(stream, width, height);
      wmpEmbed64(stream, width, height);
      wmpObjectEnd();
    }
  } else if (window.GeckoActiveXObject) {
    detect = "Netscape 7.1: object WMP 7 or 9";
    wmpObject7or9Begin(stream, width, height);
    wmpEmbed64(stream, width, height);
    wmpObjectEnd();
  } else {
    detect = "Older IE, Netscape: embed WMP 6.4";
    wmpObject64Begin(stream, width, height);
    wmpEmbed64(stream, width, height);
    wmpObjectEnd();
  }

  //alert(detect)
}
