(function() {
    var data = xmlrpc.getPlatformInfo();
    var root = webPluginRoot;
    var objectType = 'application/x-' + tbVendor.toLowerCase() + '-tblive-' + tbMajorSeries + '-plugin';
    /**
     * Inject the appropriate object tag into Mozilla and Safari browsers.
     *
     * \param codebase File name of the plugin file to load.
     */
    function putPlugin() {
        $(function() {
            $("body").append($.create('object', {
                type: objectType,
                id: 'TBLive',
                width: 0,
                height: 0
            }));
        });
    }

    function hasTBLivePlugin() {
        if(data.browser == 'IE') {
            try {
                var plugin = new ActiveXObject(tbTypeName);
                if (plugin != null) {
                    /* Preserve the object */
                    _cached_tblive = plugin;
                    return true;
                }
            } catch(e) { } /* SQUELCH */
            return false;
        }
        if (navigator.mimeTypes &&
                navigator.mimeTypes[objectType] &&
                navigator.mimeTypes[objectType].enabledPlugin)
            return true;
        for(var i = 0, len = navigator.plugins.length; i < len; ++i) {
            var p = navigator.plugins[i];
            for(var j = 0, jlen = p.length; j < jlen; ++j) {
                if(p[j].type == objectType)
                    return true;
            }
        }

        /* plugin not installed */
        return false;
    }
    window.hasTBLivePlugin = hasTBLivePlugin;
    if(!hasTBLivePlugin()) {
        return;
    }
    if(data.os == 'WIN') {
        if(data.browser == 'IE') {
            if (_cached_tblive)
                return; /* Already have a TBLive instance, no need to load a new one up via DOM */
            return;
        }
    }
    /* Assume NPAPI supported - ex: chrome */
    return putPlugin();
})();

