
tokbox.focusMe = function() {
    if (document.getElementById(tokbox.FLASH.appName)) {

        // There is a bug where you cannot put focus in a flash object while running FireFox.  https://bugzilla.mozilla.org/show_bug.cgi?id=93149
        // To get around this bug, use the setTimeout since that is a non-blocking operation (calling focus directly is a blocking operation)
        // for execution of code.  It is a known issue that we still cannot auto focus Safari.
        setTimeout('document.getElementById(tokbox.FLASH.appName).focus();', 0);
    }
};

tokbox.blurMe = function() {
    if (document.getElementById(tokbox.FLASH.appName)) {
        document.getElementById(tokbox.FLASH.appName).blur();
    }
};

tokbox.load = function() {
    if (document.getElementById(tokbox.FLASH.appName) &&
        document.getElementById(tokbox.FLASH.appName).haveWindowFocus) {
        document.getElementById(tokbox.FLASH.appName).haveWindowFocus(true);
    }

    document.title = "Free video chat and video conferencing | TokBox";
};

tokbox.refreshView = function() {
    window.resizeBy(1,0);
    window.resizeBy(-1,0);
};

tokbox.changeTitle = function() {
    document.title = "Free video chat and video conferencing | TokBox";
};

tokbox.setGUID = function(guid, preinit, init, created, loadComplete) {
    tokbox.GUID = guid;

    tokbox.calculateLoadTime(preinit, init, created, loadComplete);
};

tokbox.calculateLoadTime = function(preinit, init, created, loadComplete) {
            var end = new Date();
            var loadTime = end.getTime() - tokbox.START.getTime();
            var preinitTime = loadTime - (loadComplete - preinit);
            var initTime = loadTime - (loadComplete - init);
            var createdTime = loadTime - (loadComplete - created);

    var url = "http://"+tokbox.DOMAIN+"/lib/logPageLoad.php";
    var data = "loadTime="+loadTime+"&preinitTime="+preinitTime+"&initTime="+initTime+"&createdTime="+createdTime+"&GUID="+tokbox.GUID;

            jQuery.ajax({
                    type: "POST",
                    url: url,
                    data: data,
                    success: function(msg){},
                    error: function(obj, text, error){}
            });

};

tokbox.writeSWF = function(swf, flashVars) {
    tokbox.START = new Date();
    // wmode needs to be set to window to allow for: (1) the activate method to be called on the swf and (2) full screen
    // but first we detect if the client is FF3
    // wmode needs to be transparent for FF3 so that the HTMLComponent works
    // wmode needs to be transparent for facebook embed in ff3 and ie. Trying transparent for all (will see what breaks and update)
    //TODO:facebook
    var agent = navigator.userAgent.toLowerCase();
    var wmode_setting = "window";
    var wmode_setting = "transparent";
    if (agent.indexOf("firefox/3") != -1) {
        wmode_setting = "transparent";
    }
    var params = {wmode: wmode_setting, allowScriptAccess:"always", allowFullScreen:"true"}; //wmode must be transparent or else ajax windows will not show up over swf

    var api_key = tokbox.FB.api_key;
    var id  	= tokbox.FLASH.appName;
    var width 	= "100%"
    var height	= "100%"
    var version	= tokbox.FLASH.minFlashVersion


    swfobject.embedSWF(swf, id, "100%", "100%", version, "expressInstall.swf", flashVars, params);
};

