var liveClientInitialized = false;
var liveClientJmsCallbackArray = Array();

function liveClientInit() {
    liveClientInitialized = true;
    registerLiveClientCallback();
    window.onbeforeunload = function (evt) {
        liveClientClose();
    }
}

function liveClientClose() {
    getFlashMovieObject("liveclient").liveUpdateClose();

}

function getFlashMovieObject(movieName) {
    if (document.embeds[movieName])
        return document.embeds[movieName];
    if (window.document[movieName])
        return window.document[movieName];
    if (window[movieName])
        return window[movieName];
    if (document[movieName])
        return document[movieName];
    return null;
}

function registerLiveClientCallback() {
    if (liveClientInitialized === true) {
        for (var i = 0; i < liveClientJmsCallbackArray.length; i += 3) {
            getFlashMovieObject("liveclient").registerListener(liveClientJmsCallbackArray[i], liveClientJmsCallbackArray[i + 1], liveClientJmsCallbackArray[i + 2]);
        }
    }
}

function registerJmsCallback(channel, subTopic, functionName) {
    if (liveClientInitialized === true) {
        getFlashMovieObject("liveclient").registerListener(channel, subTopic, functionName);
    }
    else {
        liveClientJmsCallbackArray = liveClientJmsCallbackArray.concat(Array(channel, subTopic, functionName));
    }
}

function writeLiveClientEmbed(liveClientFlashUrl) {

    if (window.liveClientEmbedWritten) {
        return;
    }

    // Version check based upon the values entered above in "Globals"
    var hasRequestedVersion = DetectFlashVer(9, 0, 0);

    // Check to see if the version meets the requirements for playback
    if (hasRequestedVersion) {  // if we've detected an acceptable version
        // if we've detected an acceptable version
        // embed the Flash Content SWF when all tests are passed
        AC_FL_RunContent(
                "src", liveClientFlashUrl,
                "width", "150",
                "height", "30",
                "align", "middle",
                "id", "liveclient",
                "quality", "high",
                "bgcolor", "white",
                "allowScriptAccess","always",
                "allowNetworking", "all",
                "type", "application/x-shockwave-flash",
                "pluginspage", "http://www.adobe.com/go/getflashplayer"
                );
    } else {  // flash is too old or we can't detect the plugin
        //var alternateContent = "This content requires theAdobe Flash Player version 9 or above.";
        //document.write(alternateContent);  // insert non-flash content
    }
    window.liveClientEmbedWritten = true;
}