function install (event) {
    var params = {
        "Moonshine": { 
            URL: event.target.href,
            IconURL: "http://abock.org/moonshine/moonshine-32.png",
            Hash: event.target.getAttribute ("hash"),
             toString: function () { return this.URL; }
        }
    };
      
    InstallTrigger.install (params);

    return false;
}

window.onload = function () {
    var install_host = document.getElementById ("install-host");
    var got_match = false;
    
    var install_list = document.createElement ("ul");
    install_list.id = "install-list";
    
    releases.sort (function (a, b) {
        a.matches = new RegExp (a.ua_arch_match).test (navigator.userAgent || navigator.vendor);
        b.matches = new RegExp (b.ua_arch_match).test (navigator.userAgent || navigator.vendor);
        return b.matches - a.matches;
    });
    
    for (var i in releases) {
        var release = releases[i];
        var matches = release.matches;
        got_match |= matches;
           
        var li = document.createElement ("li");
        if (matches) {
            li.setAttribute ("class", "detected");
        }

        var a = document.createElement ("a");
        a.setAttribute ("href", release.link);
        a.setAttribute ("hash", release.hash);
        a.onclick = install;
        a.appendChild (document.createTextNode (release.title));
        a.appendChild (document.createElement ("br"));
        var span = document.createElement ("span");
        a.appendChild (span);
        span.appendChild (document.createTextNode ("Last Updated: " + release.last_update));
        li.appendChild (a);
        install_list.appendChild (li);
    }
    
    if (!got_match) {
        var no_match = document.createElement ("li");
        var p = document.createElement ("p");
        no_match.appendChild (p);
        p.appendChild (document.createTextNode (
            "Your operating system or architecture could not be detected. Select a download from the list above."
        ));
        install_list.appendChild (no_match);
    }
    
    while (install_host.firstChild) {
        install_host.removeChild (install_host.firstChild);
    }
    
    install_host.appendChild (install_list);
    
    check_moonlight ();
};


