document.addEventListener("DOMContentLoaded", function(e) {
    var doc = e.target;
    var ns = "http://www.w3.org/1999/xhtml";
    var requirement = doc.getElementById("requirement");
    var typeCheck = navigator.mimeTypes["application/x-mplayer2"];
    if (!(typeCheck && typeCheck.description == "Npdsplay dll" && navigator.javaEnabled())) {
        requirement.textContent = "Plugins must be turned on, Java must be turned on, Windows Media Player 11 must be installed and application/x-mplayer must be associated with 'Windows Media Plug-in Dynamic Link Library' ";
        var a = doc.createElementNS(ns, "a");
        a.href = "http://www.microsoft.com/downloads/details.aspx?FamilyID=99655624-ca38-49b7-a701-93f5f0e501dd&displaylang=en";
        a.textContent = "(npdsplay.dll + npds.zip)";
        requirement.appendChild(a);
        return;
    }
    doc.body.removeChild(requirement);
    var obj = doc.createElementNS(ns, "object");
    obj.setAttributeNS(null, "type", "application/x-mplayer2");
    obj.setAttributeNS(null, "width", "320");
    obj.setAttributeNS(null, "height", "66");
    var player = doc.getElementById("player");
    var stream = player.getAttributeNS(null, "data-stream");
    player.appendChild(obj);
    var wmpScriptingAvailable = false;
    function loadFile() {
        if (obj.SetFileName) {
            wmpScriptingAvailable = true;
            doc.defaultView.clearInterval(check);
            obj.SetPlayCount(0);
            obj.SetVolume(0);
            obj.SetShowStatusBar(true);
            obj.SetDisplaySize(0);
            obj.SetAutoSize(false);
            obj.SetAutoStart(true);
            obj.SetFileName(stream);
        }
    }
    var check = doc.defaultView.setInterval(loadFile, 1000);
    doc.defaultView.setTimeout(function() {
        if (!wmpScriptingAvailable) {
            doc.defaultView.clearInterval(check);
            player.textContent = "It appears scripting wasn't available on the WMP object.";
        }
    }, 15000);
}, false);
