﻿/**
* @description Different Client detection data
*/
var clientHB1 = { mimeType: "application/x-nsclntax", progID: "HotbarAX.ClientDetector" },
	clientHB2 = { mimeType: "application/x-hbclntax", progID: "HotbarAX.Info" };

/**
* @description performs client checks in for a given mime type
* @param client The client object to check (e.g. clientHB1 or clientHB2)
*/
function checkHBInstall(client) {
    //Return value
    var isRunning = false;

    //Check we have correct variables on client
    if (client && client.mimeType && client.progID) {
        try {
            //For IE
            if (navigator.appName == "Microsoft Internet Explorer" && window.ActiveXObject) {
                try {
                    //Try to create the correct activexobject with the client's progid, then check the isRunning property
                    var axo = new ActiveXObject(client.progID);
                    isRunning = (axo.IsRunning == "1");
                }
                catch (e) { }
            }

            //For Firefox and equivalents
            else if (navigator.mimeTypes && navigator.mimeTypes.length > 0) {
                var installedMimeType = navigator.mimeTypes[client.mimeType];
                if (installedMimeType) {
                    //Found this mimeType - check to see if client is running
                    try {
                        //Attach an embed element of this mime type if one doesn't exist already
                        var oEmbed, embedID = "_client_plugin";
                        if (!document.getElementById(embedID)) {
                            oEmbed = document.createElement("embed");
                            oEmbed.id = embedID;
                            oEmbed.type = client.mimeType;
                            oEmbed.width = "0";
                            oEmbed.height = "0";
                            oEmbed.hidden = "true";
                            document.body.appendChild(oEmbed);
                        }

                        //Check the plugin
                        if (installedMimeType.enabledPlugin) {
                            var clntaxPlugin = document.embeds[embedID];
                            if (clntaxPlugin) {
                                isRunning = (clntaxPlugin.ClientIsRunning('Hotbar') == 1);
                            }
                        }

                        //Remove the element
                        oEmbed = document.getElementById(embedID);
                        if (oEmbed) oEmbed.parent.removeChild(oEmbed);
                    }
                    catch (e) { }
                }
            }
        }
        catch (e) { }
    }
    return isRunning;
}

/**
* @description Checks whether HB1 is installed
* @returns boolean
*/
function isHB1Installed() {
    return checkHBInstall(clientHB1);
}

/**
* @description Checks whether HB2 is installed
* @returns boolean
*/
function isHB2Installed() {
    return checkHBInstall(clientHB2);
}

/**
* @description Installs HB2 (used in conjunction with isHB2Installed) After installation is complete, executes post install function
* @param function fPostInstall The post install function to call (if any).  Can be null or empty (pass no ags to the function)
*/
function installHB2(fPostInstall) {
    //start install here. - TODO (Murph)

    /**********************************/

    //Install is complete, executes post install function if one has been supplied
    if (typeof fPostInstall == "function") fPostInstall();
}


function getContent() {
    var divPlayer = $get('player');
    var divPlaceholder = $get('play-placeholder');
    var divOverlay = $get('download-overlay');
    var frmPlayer = $get('playFrame');

    if (isHB2Installed())
    {
        divPlaceholder.style.display = 'none';
        divOverlay.style.display = 'none';
        divPlayer.style.display = 'block';
        frmPlayer.src = FrameSrc;
    }
    else {
        divPlaceholder.style.display = 'block';
        divOverlay.style.display = 'block';
        divPlayer.style.display = 'none';
        frmPlayer.src = "";
    }
}

function closeInstallOverlay() {
    var divOverlay = $get('download-overlay');
    divOverlay.style.display = 'none';
}

function checkClassic()
{
    if (isHB1Installed())
        document.location = "/classic/";
} 
