/* $Id: assessmentItemCommonFlexapp.js 59330 2010-05-11 11:46:13Z 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=8389";

/**
 * 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{
            //alert('assessmentItemCommonFlexapp.js / activateFlashObject / calling moveCommonFlash(true)');
            moveCommonFlash(true);    
        }catch(err){
            
        }

    }
}

onModuleLoaded = function(a_event){
    alert("onModuleLoaded");
    alert("onModuleLoaded "+logObject_str(a_event));
}


activateFlexappCommon2= function(){
    var _QTI_FLASH_PLAYER_MODULE = $('QTI_FLASH_PLAYER_MODULE');
    if(typeof _QTI_FLASH_PLAYER_MODULE != 'undefined'){
//        alert("activateFlexappCommon");
        var flashvarsObj = {bridgeName:"responseSwfCommon", MODULE_PATH:commonFolder+"gfx/assessment/", LOCALE:pageInfoLocale};
        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_debug.swf"+flashRev;
        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);
        try{
//            moveCommonFlash(true);  // ie6 PGSCF-262
        }catch(err){

        }
        initBridgeCommon();

    }else{
        activateFlexappCommon();
        return;
    }
}

/**
 * Delay calling, swfobject.addLoadEvent is wrong in ff2 PGS-660
 *
 */
activateFlexappCommon = function(){
    setTimeout("activateFlexappCommon2();", 1000);
}

initBridgeCommon = function(){
    if(typeof FABridge == 'undefined' || typeof FABridge.responseSwfCommon == 'undefined'){
        setTimeout("initBridgeCommon();", 200);
        return;
    }
//    alert('tata');
    var b_isfirst = (typeof flexAppCommon == 'undefined');
    if(b_isfirst)flexAppCommon = FABridge.responseSwfCommon.root(); // ie6 PGSCF-262
//    if(flexAppCommon == null){
//        setTimeout("initBridgeCommon();", 50);
//        return;
//    }
    if(b_isfirst){
        try{
//            moveCommonFlash(false);     // ie6 PGSCF-262
        }catch(err){

        }
    }
    str_commonFlexappStatus = arr_commonFlexappStatus[1];

}

var b_initCommonFlex = false;
initCommonFlex = function(){
    if (b_initCommonFlex){
        //alert('initCommonFlex called');
        return;
    }
//    alert('initCommonFlex');
    try{
        if(typeof FABridge !== 'undefined'){
            FABridge.addInitializationCallback("responseSwfCommon", initBridgeCommon);
            activateFlexappCommon();
        }else{
            setTimeout(initCommonFlex, 200);
            return;
        }
    }catch(err){
        alert('init common swf failed '+err);
    }
    b_initCommonFlex = true;
}

b_commonFlexappInitializer = false;

commonFlexappInitializer = function(){
    if(b_commonFlexappInitializer) return;
    initCommonFlex();
//    swfobject.addLoadEvent(activateFlexappCommon);
//    swfobject.addLoadEvent(initCommonFlex);


    b_commonFlexappInitializer = true;
}



