/* $Id: assessmentItemCommonFlexapp.js 53716 2009-07-14 09:05:34Z johnarne $ */

/* Should only reside in head of a document which may contain a flash/flex based question (and only once)
* PGS-522
* */
var arr_commonFlexappStatus = ["uninitialized", "initialized", "moved"];
var str_commonFlexappStatus = arr_commonFlexappStatus[0];

var flashRev = "?rev=5522";

/**
 * Requires swobject 2.1
 */
activateFlashObject = function(displayInElementId){
//    alert("activateFlashObject "+displayInElementId);
    var theSWF = document.getElementById('QTI_FLASH_PLAYER_MODULE');
//    alert("2activateFlashObject "+theSWF);
    var targetDiv = document.getElementById(displayInElementId);
    var displayInElement = targetDiv;
    if((theSWF == null || !theSWF) && !$('QTI_FLASH_PLAYER_MODULE_ASSESSMENT')){
        displayInElement.innerHTML = '<div id="QTI_FLASH_PLAYER_MODULE"/>';
        activateFlexappCommon();
    }else {
        try{
            moveCommonFlash(true);    
        }catch(err){
            
        }

    }
}

onModuleLoaded = function(a_event){
    alert("onModuleLoaded");
    alert("onModuleLoaded "+logObject_str(a_event));
}


activateFlexappCommon2= function(){
    if($('QTI_FLASH_PLAYER_MODULE')){
//        alert("activateFlexappCommon");
        var flashvarsObj = {bridgeName:"responseSwfCommon", MODULE_PATH:commonFolder+"gfx/assessment/"};
        var parObj = {quality :"high", bgcolor:"#869cFF", allowScriptAccess:"always", allowNetworking:"all", wmode:"opaque"};
        var attObj = {play:"true"};
        var swfWrapper = commonFolder+"scripts/test.swf";
        var swfWrapper = commonFolder+"gfx/assessment/customInteraction_jsplugin.swf"+flashRev;
        var expressInstallSWL = commonFolder+"scripts/expressInstall.swf";
        swfobject.embedSWF(swfWrapper, "QTI_FLASH_PLAYER_MODULE", "700", "385",
                "9.0.0", swfWrapper, flashvarsObj, parObj, attObj);
    }
}

/**
 * Delay calling, swfobject.addLoadEvent is wrong in ff2 PGS-660
 *
 */
activateFlexappCommon = function(){
    setTimeout("activateFlexappCommon2();", 1000);
}

initBridgeCommon = function(){
//    alert('tata');
    flexAppCommon = FABridge.responseSwfCommon.root();
//    if(flexAppCommon == null){
//        setTimeout("initBridgeCommon();", 50);
//        return;
//    }
    str_commonFlexappStatus = arr_commonFlexappStatus[1];

}

var b_initCommonFlex = false;
initCommonFlex = function(){
    if (b_initCommonFlex){
        alert('initCommonFlex called');
        return;
    }
//    alert('initCommonFlex');
    try{
        FABridge.addInitializationCallback("responseSwfCommon", initBridgeCommon);
    }catch(err){
        alert('init common swf failed '+err);
    }
    b_initCommonFlex = true;
}

b_commonFlexappInitializer = false;

commonFlexappInitializer = function(){
    if(b_commonFlexappInitializer) return;
    swfobject.addLoadEvent(activateFlexappCommon);
    swfobject.addLoadEvent(initCommonFlex);
    b_commonFlexappInitializer = true;
}



