
  var playerNotFoundMessage = "The required browser plugin could not be found.";
  var pleaseDownloadMessage = "You can download it here";
  var qtPluginUrl = "http://www.apple.com/quicktime/download/";
  var wmPluginUrl = "http://www.microsoft.com/windows/windowsmedia/default.mspx";
    function qtInstalled() {
        return Plugin.isInstalled("QuickTime");
    }
    function wmInstalled() {
        return Plugin.isInstalled("Windows Media");
    }
    function vlcInstalled() {
        return Plugin.isInstalled("VLC");
    }
    function embedAndStartQT(target, w, h, url, id) {
        Plugin.embed("QuickTime", {
                width: w,
                height: h,
                src: url,
                autoplay: "true",
                controller: "false",
                id: id
            },
            target);
    }
    function embedAndStartWM(target, w, h, url, id) {
        Plugin.embed("Windows Media",{
                width: w,
                height: h,
                src: url,
                showcontrols: "false",
                showstatusbar: "true",
                standby: "Loading...",
                id: id,
                name: id
            },
            target);
    }
    function embedAndStartVLCAudio(target, w, h, url, id) {
        Plugin.embed("VLC", {
                width: w,
                height: h,
                src: url,
                showcontrols: "false",
                autoplay: "true", // autoplay true is required
                id: id,
                name: id
            },
            target);
    }
    function QTPlay(playerObj) {
        if (playerObj != null) {
            playerObj.Play();
        }
    }
    function QTStop(playerObj) {
        if (playerObj != null) {
            playerObj.Stop();
            playerObj.Rewind();
        }
    }
    function QTPause(playerObj) {
        if (playerObj != null) {
            playerObj.Stop();
        }
    }
    function WMPlay(playerObj) {
        if (playerObj != null) {
            try {
                playerObj.controls.play();
            } catch(e) {
                playerObj.play();
            }
        }
    }
    function WMStop(playerObj) {
        if (playerObj != null) {
            try {
                playerObj.controls.stop();
            } catch (e) {
                playerObj.stop();
            }
        }
    }
    function WMPause(playerObj) {
        if (playerObj != null) {
            try {
                playerObj.controls.pause();
            } catch (e) {
                playerObj.pause();
            }
        }
    }
        /**
        * Play a stream of type 'type' by eiter embedding an object or reusing an embedded object.
        * Will embed into a div with class 'pluginContainer' within the parent div of 'playerController'.
        */
        function play(playerController, type, url, width, height) {
            var pluginContainer = $(playerController).getParent().getParent().getElements("div[class='pluginContainer']")[0];
            var player = pluginContainer.getFirst();
            if (type == 'qt') {
                if (qtInstalled()) {
                    if (player == null) {
                        embedAndStartQT(pluginContainer, width, height, url);
                    } else {
                        QTPlay(player);
                    }
                } else {
                    //pluginContainer.set('html', playerNotFoundMessage + '<a href="' + qtPluginUrl + '" target="_blank">' + pleaseDownloadMessage + '</a>');
                    pluginContainer.innerHTML = playerNotFoundMessage + '<a href="' + qtPluginUrl + '" target="_blank">' + pleaseDownloadMessage + '</a>';
                }
            }
            if (type == 'wm') {
                if (wmInstalled()) {
                    if (player == null) {
                        embedAndStartWM(pluginContainer, width, height, url);
                    } else {
                        WMPlay(player);
                    }
                } else {
                    if (vlcInstalled()) {
                        if (player == null) {
                            embedAndStartVLCAudio(pluginContainer, width, height, url);
                        } else {
                            WMPlay(player);
                        }
                    } else {
                        pluginContainer.set('html', playerNotFoundMessage + '<a href="' + wmPluginUrl + '" target="_blank">' + pleaseDownloadMessage + '</a>');
                    }
                }
            }
        }
        function pause(playerController, type) {
            var pluginContainer = $(playerController).getParent().getParent().getElements("div[class='pluginContainer']")[0];
            var player = pluginContainer.getFirst();
            if (player != null) {
                switch (type) {
                    case "qt": QTPause(player);
                        break;
                    case "wm": WMPause(player);
                        break;
                }
            } else {
                //alert('No player found to pause.');
            }
        }
        function stop(playerController, type) {
            var pluginContainer = $(playerController).getParent().getParent().getElements("div[class='pluginContainer']")[0];
            var player = pluginContainer.getFirst();
            if (player != null) {
                switch (type) {
                    case "qt": QTStop(player);
                        break;
                    case "wm": WMStop(player);
                        break;
                }
            } else {
                //alert('No player found to stop');
            }
        }