function check_moonlight () {

    var released_version = "1.0";
    var plugin = navigator.plugins["Silverlight Plug-In"];
    if (plugin.filename.indexOf("libmoonloader") != 0) {
        return;
    }

    var moonlight_banner = document.getElementById ("moonlight-banner");

    function onPluginError (sender, args) {
        moonlight_banner.style.background = "#900";
        moonlight_banner.innerHTML = "Error initializing Moonlight plugin: " + args.errorMessage;
    }

    function control_resize (control) {
        var message = control.findName ("message");
        var background = control.findName ("background");
        var html_width = parseFloat (document.defaultView.getComputedStyle (
            moonlight_banner, null).getPropertyValue ("width"));
        message.width = html_width - 20;
        control.width = background.width = html_width;
        message["Canvas.Left"] = 10;
        message["Canvas.Top"] = 10;
        control.height = background.height = Math.ceil (message.actualHeight) + 20;
        moonlight_banner.firstChild.style.height = control.height + "px";
    }

    function onPluginLoad (control, userContext, rootElement) {
        control.content.onResize = control_resize;
        
        message = rootElement.findName ("message");
        var moonlight_version = control.settings.version;
        
        if (moonlight_version == released_version) {
            message.text = "Congratulations, you're running the current release of Moonlight! You will be able to use Moonshine.";
        } else if ((moonlight_version < released_version) || 
            (moonlight_version == "1.0b1") ||
            (moonlight_version == "1.0b2")) {
            message.text = "You're running an older release of moonlight. Please upgrade.";
        } else if (moonlight_version > released_version) {
            message.text = "You're running an unstable build of moonlight.";
        }
        
        moonlight_banner.style.background = "transparent";
        moonlight_banner.style.border = "none";
    }
    
    Silverlight.createObjectEx ({
        source: "#bannerxaml",
        parentElement: document.getElementById ("moonlight-banner"),
        id: "moonlight-banner-control",
        properties: {
            width: "100%",
            height: 1,
            version: "1.0",
            isWindowless: "true"
        },
        events: {
            onError: onPluginError,
            onLoad: onPluginLoad
        }
    });
}



