<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: main.xml $
$Revision: 1018 $

last change: $Date: 2009-03-19 17:11:16 +0300 (Чт, 19 мар 2009) $
             $Author: Pavel $

  Lacerta Project
  version 1.0.0.2
  Copyright (C) 2007-2009 RNMC
-->
<include src="rnmc_labwork_loader.xml"/>
<include src="rnmc_style_manager.xml"/>
<include src="rnmc_control_manager.xml"/>
<include src="rnmc_sound_manager.xml"/>
<include src="rnmc_utils.xml"/>
<include src="rnmc_hint.xml"/>

<scene name="Lacerta" final="false">
<!--scene-->
<xml name="defaultXML"/>

<script src="labwork_const.mjs"/>
<script src="custom\custom_init.mjs"/>

<script event="Player.module.onUnload"><![CDATA[
  this.Labwork.unloadModule();
]]></script>

<!--script event="Player.module.onLoad">
</script-->

<script><![CDATA[
  this.labwork_xml        = null;
  this.style_xml          = null;
  this.controls_xml       = null;
  this.default_xml        = null;
  this.hint_xml           = null;
  this.scorm_xml          = null;
  this.rollover_menu_xml  = null;
  this.step_list_xml      = null;
  this.result_export_xml  = null;
  this.result_panel_xml   = null;
  this.step_indicator_xml = null;
  this.languages_xml      = null;

  this.Hint           = null;
  this.Utils          = null;
  this.CustomUtils    = null;
  this.StyleManager   = null;
  this.ControlManager = null;
  this.SoundManager   = null;
  this.ScormSupport   = null;
  this.Labwork        = null;

  function mainLibrary() {
    initializeLibrary();
    USE_OLD_STEPLIST_FORMAT = false;
    if(this.Labwork.loadLabwork(labwork_xml))
      this.Labwork.startStep(0);
  }

  function loadLibrary() {
    initializeLibrary();
    USE_OLD_STEPLIST_FORMAT = false;
    return this.Labwork.loadLabwork(labwork_xml);
  }  

  function loadLibrarySpecial(load_special) {
    initializeLibrary();
    USE_OLD_STEPLIST_FORMAT = false;
    if(this.Labwork.loadLabwork(labwork_xml)){
      if (load_special){
        this.SpecialManager = new Composition();
        this.SpecialManager._class = "rnmc_specialManager";
        this.SpecialManager.parent = this;
        this.SpecialManager.initFromFile("\\DATA\\components\\special\\special.xml");
      }
      this.Labwork.startStep(0);
    }
  }  
  
  function initializeLibrary(){
  // Загрузка конфигов
    this.loadSceneConfig("\\DATA\\scene\\config.xml");
    this.loadSkinConfig("\\DATA\\skin\\config.xml");
    
  // класс содержащий функции для отображения подсказки (hint) 
    if (this.Hint){
      this.Hint.parent = null;
      this.Hint = null;
    }
    this.Hint = new Composition();
    this.Hint._class = "rnmc_Hint";
    this.Hint.parent = this;
    this.Hint.loadHintFromFile(hint_xml);

  // класс содержащий общеиспользуемые функции
    if (this.Utils){
      this.Utils.parent = null;
      this.Utils = null;
    }
    this.Utils = new Composition();
    this.Utils._class = "rnmc_Utils";
    this.Utils.parent = this;
    
  // Класс для поддержки сторонних компонентов.
    if (this.CustomUtils){
      this.CustomUtils.parent = null;
      this.CustomUtils = null;
    }
    this.CustomUtils = new Composition();
    this.CustomUtils._class = "rnmc_CustomUtils";
    this.CustomUtils.parent = this;

  // менеджер стилей
    if (this.StyleManager){
      this.StyleManager.parent = null;
      this.StyleManager = null;
    }
    this.StyleManager = new Composition();
    this.StyleManager._class = "rnmc_StyleManager";
    this.StyleManager.parent = this;
    this.StyleManager.loadStylesFromFile(style_xml);

  // менеджер контролов
    if (this.ControlManager){
      this.ControlManager.parent = null;
      this.ControlManager = null;
    }
    this.ControlManager = new Composition();
    this.ControlManager._class = "rnmc_ControlManager";
    this.ControlManager.parent = this;
    this.ControlManager.loadControlsFromFile(controls_xml);

  // звуковой менеджер
    if (this.SoundManager){
      this.SoundManager.parent = null;
      this.SoundManager = null;
    }
    this.SoundManager = new Composition();
    this.SoundManager._class = "rnmc_SoundManager";
    this.SoundManager.parent = this;

  // SCORM  - вообще необходимо перенести в Player.module.onLoad!!!!!!
    if (this.ScormSupport){
      this.ScormSupport.parent = null;
      this.ScormSupport = null;
    }

    this.loadDefaultSettings(default_xml);

  // загрузчик лабораторной работы
    if (this.Labwork){
      this.Labwork.parent = null;
      this.Labwork = null;
    }
    this.Labwork = new Composition();
    this.Labwork._class = "RNMC_Labwork_Loader";
    this.Labwork.parent = this;
    this.Labwork.loadLanguagesSettings(languages_xml);

    this.ScormSupport = new Composition();
    this.ScormSupport._class = "rnmc_SCORMSupport";
    this.ScormSupport.parent = this;
    this.ScormSupport.initializeScormSupport();		
  }

  function loadDefaultSettings(srcFile){
    var xmlNode = null;
    var xmlAttributeMap = null;
    var xmlAttribute = null;

    if(resourceExists(srcFile)){
      defaultXML.src = srcFile;
    } else {
      trace("Файл " + srcFile + " не найден.");
      return false;
    }
    if (!defaultXML.XMLDocument){
      // Если загружаемый файл не правильный - пишем в трэйсер и выходим
      trace("Файл " + srcFile + " не является правильным XML файлом.");
      return false;
    } else {
      xmlNode = defaultXML.XMLDocument.firstChild.firstChild;
      this.defaultSettings = new Object();

      while(xmlNode){
        switch(xmlNode.nodeName){
        case "text":
          var objSettings = new Object();
          var newObject = this.Utils.initStdTextFromNode(xmlNode, this);
          if(newObject){
            objSettings.objectScroll = newObject.objectScroll;
            objSettings.scrollerIndent = newObject.scrollerIndent;
            objSettings.scrollerXOffset = newObject.scrollerXOffset;
            objSettings.scrollerYOffset = newObject.scrollerYOffset;
            objSettings.scrollerHeight = newObject.scrollerHeight;
            objSettings.objectStyle = newObject.objectStyle;
            objSettings.titleStyle = newObject.titleStyle;
            newObject.parent = null;
            newObject = null;
            this.defaultSettings.stdText = objSettings;
          } else {
            objSettings = null;
          }
          break;
        case "image":
          var objSettings = new Object();
          var newObject = this.Utils.initStdImageFromNode(xmlNode, this);
          if(newObject){
            objSettings.titleStyle = newObject.titleStyle;
            newObject.parent = null;
            newObject = null;
            this.defaultSettings.stdImage = objSettings;
          } else {
            objSettings = null;
          }
          break;
        case "amination":
          var objSettings = new Object();
          var newObject = this.Utils.initStdAnimationFromNode(xmlNode, this);
          if(newObject){
            objSettings.playing = newObject.playing;
            objSettings.objectLoop = newObject.objectLoop;          
            objSettings.titleStyle = newObject.titleStyle;
            newObject.parent = null;
            newObject = null;
            this.defaultSettings.stdAnimation = objSettings;
          } else {
            objSettings = null;
          }
          break;
        case "audio":
          var objSettings = new Object();
          var newObject = this.Utils.initStdAudioFromNode(xmlNode, this);
          if(newObject){
            objSettings.playing = newObject.playing;
            objSettings.objectLoop = newObject.objectLoop;
            objSettings.titleStyle = newObject.titleStyle;
            newObject.parent = null;
            newObject = null;
            this.defaultSettings.stdAudio = objSettings;
          } else {
            objSettings = null;
          }
          break;
        case "video":
          var objSettings = new Object();
          var newObject = this.Utils.initStdVideoFromNode(xmlNode, this);
          if(newObject){
            objSettings.playing = newObject.playing;
            objSettings.objectLoop = newObject.objectLoop;
            objSettings.titleStyle = newObject.titleStyle;
            newObject.parent = null;
            newObject = null;
            this.defaultSettings.stdVideo = objSettings;
          } else {
            objSettings = null;
          }
          break;
        case "flash":
          var objSettings = new Object();
          var newObject = this.Utils.initStdFlashFromNode(xmlNode, this);
          if(newObject){
            objSettings.titleStyle = newObject.titleStyle;
            newObject.parent = null;
            newObject = null;
            this.defaultSettings.stdFlash = objSettings;
          } else {
            objSettings = null;
          }
          break;
        case "quicktime":
          var objSettings = new Object();
          var newObject = this.Utils.initStdQTFromNode(xmlNode, this);
          if(newObject){
            objSettings.titleStyle = newObject.titleStyle;
            newObject.parent = null;
            newObject = null;
            this.defaultSettings.stdQT = objSettings;
          } else {
            objSettings = null;
          }
          break;
        case "slideshow":
          var objSettings = new Object();
          var newObject = this.Utils.initStdSlideshowFromNode(xmlNode, this);
          if(newObject){
            objSettings.playing = newObject.playing;
            objSettings.loop = newObject.loop;
            objSettings.slideshowMode = newObject.slideshowMode;
            objSettings.controlMode = newObject.controlMode;
            newObject.parent = null;
            newObject = null;
            this.defaultSettings.stdSlideshow = objSettings;
          } else {
            objSettings = null;
          }
          break;
        case "button":
          var objSettings = new Object();
          var newObject = this.Utils.initStdButtonFromNode(xmlNode, this);
          if(newObject){
            objSettings.buttonType = newObject.buttonType;
            objSettings.buttonNormalTextStyle = newObject.buttonNormalTextStyle;
            objSettings.buttonActiveTextStyle = newObject.buttonActiveTextStyle;
            objSettings.buttonPressedTextStyle = newObject.buttonPressedTextStyle;
            objSettings.buttonDisabledTextStyle = newObject.buttonDisabledTextStyle;
            newObject.parent = null;
            newObject = null;
            this.defaultSettings.stdButton = objSettings;
          } else {
            objSettings = null;
          }
          break;          
        case "crossword":
          var objSettings = new Object();
          var newObject = this.Utils.initCrosswordFromNode(xmlNode, this);
          if(newObject){
            objSettings.cellWidthNormal = newObject.cellWidthNormal;
            objSettings.cellWidthActive = newObject.cellWidthActive;
            objSettings.cellWidthDisabled = newObject.cellWidthDisabled;
            objSettings.cellHeightNormal = newObject.cellHeightNormal;
            objSettings.cellHeightActive = newObject.cellHeightActive;
            objSettings.cellHeightDisabled = newObject.cellHeightDisabled;
            objSettings.cellStyleNormal = newObject.cellStyleNormal;
            objSettings.cellStyleActive = newObject.cellStyleActive;
            objSettings.cellStyleDisabled = newObject.cellStyleDisabled;
            objSettings.cellBorderNormal = newObject.cellBorderNormal;
            objSettings.cellBorderActive = newObject.cellBorderActive;
            objSettings.cellBorderDisabled = newObject.cellBorderDisabled;
            objSettings.cellBgColorNormal = newObject.cellBgColorNormal;
            objSettings.cellBgColorActive = newObject.cellBgColorActive;
            objSettings.cellBgColorDisabled = newObject.cellBgColorDisabled;
            objSettings.cellBorderColorNormal = newObject.cellBorderColorNormal;
            objSettings.cellBorderColorActive = newObject.cellBorderColorActive;
            objSettings.cellBorderColorDisabled = newObject.cellBorderColorDisabled;
            objSettings.indexStyle = newObject.indexStyle;
            objSettings.cellSpacing = newObject.cellSpacing;
            objSettings.checkImmediately = newObject.checkImmediately;
            objSettings.autoSkip = newObject.autoSkip;
            objSettings.setFocusOnRollover = newObject.setFocusOnRollover;
            objSettings.autoFitStyle = newObject.autoFitStyle;
            objSettings.currentSymbolTable = newObject.currentSymbolTable;
            objSettings.lineSpacing = newObject.linaSpacing;

            newObject.parent = null;
            newObject = null;
            this.defaultSettings.stdCrossword = objSettings;
          } else {
            objSettings = null;
          }
          break;
        }
        xmlNode = xmlNode.nextSibling;
      }
    }
  }
  
  function loadSkinConfig(configPath){
    var xmlConfig = null;
    var xmlNode = null;
    var xmlAttributeMap = null;
    var xmlAttribute = null;
    
    xmlConfig = new XML();
    xmlConfig.src = configPath;
    
    if (!xmlConfig.XMLDocument || !xmlConfig.XMLDocument.firstChild){
      trace("#FF0000Невозможно загрузить конфигурационный файл ("+configPath+")");
    } else {
      xmlConfig.XMLDocument.source = xmlConfig.src;
      xmlNode = xmlConfig.XMLDocument.firstChild.firstChild;
      while(xmlNode){
        if(xmlNode.nodeName == "setting"){
          xmlAttributeMap = xmlNode.attributes;
          if (xmlAttributeMap){
            xmlAttribute =  xmlAttributeMap.getNamedItem("element");
            if (xmlAttribute != null && xmlAttribute.specified){
              switch(xmlAttribute.value.toLowerCase()){
              case "defaults":
                this.default_xml = this.getConfigHref(xmlNode);
                break;
              case "textstyles":
                this.style_xml = this.getConfigHref(xmlNode);
                break;
              case "controls":
                this.controls_xml = this.getConfigHref(xmlNode);
                break;
              case "hints":
                this.hint_xml = this.getConfigHref(xmlNode);
                break;
              case "rollovermenu":
                this.rollover_menu_xml = this.getConfigHref(xmlNode);
                break;
              case "steplist":
                this.step_list_xml = this.getConfigHref(xmlNode);
                break;
              case "resultexport":
                this.result_export_xml = this.getConfigHref(xmlNode);
                break;
              case "resultPanel":
                this.result_panel_xml = this.getConfigHref(xmlNode);
                break;
              case "stepindicator":
                this.step_indicator_xml = this.getConfigHref(xmlNode);
                break;
              case "languages":
                this.languages_xml = this.getConfigHref(xmlNode);
                break;
              }
            }
          }
        }
        xmlNode = xmlNode.nextSibling;
      }
    }
  }
  
  function loadSceneConfig(configPath){
    var xmlConfig = null;
    var xmlNode = null;
    var xmlAttributeMap = null;
    var xmlAttribute = null;
    
    xmlConfig = new XML();
    xmlConfig.src = configPath;
    
    if (!xmlConfig.XMLDocument || !xmlConfig.XMLDocument.firstChild){
      trace("#FF0000Невозможно загрузить конфигурационный файл ("+configPath+")");
    } else {
      xmlConfig.XMLDocument.source = xmlConfig.src;
      xmlNode = xmlConfig.XMLDocument.firstChild.firstChild;
      while(xmlNode){
        if(xmlNode.nodeName == "setting"){
          xmlAttributeMap = xmlNode.attributes;
          if (xmlAttributeMap){
            xmlAttribute =  xmlAttributeMap.getNamedItem("element");
            if (xmlAttribute != null && xmlAttribute.specified){
              switch(xmlAttribute.value.toLowerCase()){
              case "steps":
                labwork_xml = this.getConfigHref(xmlNode);
                break;
              case "scorm":
                scorm_xml = this.getConfigHref(xmlNode);
                break;
              }
            }
          }
        }
        xmlNode = xmlNode.nextSibling;
      }
    }
  }
  
  function getConfigHref(srcNode){
    var xmlNode = null;
    var xmlAttributeMap = null;
    var xmlAttribute = null;
    
    if (!srcNode || !srcNode.firstChild)
      return null;
      
    xmlNode = srcNode.firstChild;
    while(xmlNode){
      if(xmlNode.nodeName == "location"){
        xmlAttributeMap = xmlNode.attributes;
        if (xmlAttributeMap){
          xmlAttribute =  xmlAttributeMap.getNamedItem("href");
          if (xmlAttribute != null && xmlAttribute.specified){
            return xmlAttribute.value.toLowerCase();
          }
        }
      }
      xmlNode = xmlNode.nextSibling;
    }
  }
]]></script>
</scene>
</rmml>