/**
 * @author Microcraft eLearning
 * @version 1.0
 */
/**
 * The lessonNode object.
 * @param {Object} nodeXML
 */
function LessonNode(nodeXML){
    this.xml = nodeXML;
    this.type = nodeXML.attributes[0].nodeValue;
    this.id = nodeXML.attributes[1].nodeValue;
    this.parent = nodeXML.attributes[2].nodeValue;
    this.name = nodeXML.attributes[3].nodeValue;
    this.scoring = false;
    this.optionStart = null;
    this.showInReference = true;
    switch (this.type) {
        case "MENU":
            try {
                this.showInReference = (nodeXML.attributes[4].nodeValue.toLowerCase() == "true");
            } 
            catch (err) {
            }
            break;
        case "SEQUENCE":
            this.scoring = (nodeXML.attributes[4].nodeValue.toLowerCase() == "true");
            try {
                this.showInReference = (nodeXML.attributes[5].nodeValue.toLowerCase() == "true");
            } 
            catch (err) {
            }
            break;
        case "RANDOM":
            this.scoring = (nodeXML.attributes[8].nodeValue.toLowerCase() == "true");
            try {
                this.showInReference = (nodeXML.attributes[9].nodeValue.toLowerCase() == "true");
            } 
            catch (err) {
            }
            break;
    }
    this.children = new Ext.util.MixedCollection;
    if (this.parent != 0) {
        Author.lessonNodes.nodes.get(this.parent).children.add(this.id, this);
    }
    this.elements = new Ext.util.MixedCollection;
    this.finished = false;
}

LessonNode.prototype.saveBookmark = function(){
    if (Author.bookMark) {
        Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
            expires: new Date(new Date().getTime() + (1000 * 60 * 60 * 24 * 365))
        }));
        Ext.state.Manager.set(Author.projectName + Author.traineeID + "[OPTION" + this.id + "]", this.finished);
        //alert(Author.projectName + Author.traineeID + "[OPTION" + this.id + "]"+" >> "+this.finished+ " saved");
    }
}
LessonNode.prototype.readBookmark = function(){
    if (Author.bookMark) {
        this.finished = Ext.state.Manager.get(Author.projectName + Author.traineeID + "[OPTION" + this.id + "]", false);
        //   alert(this.finished);
    }
}
LessonNode.prototype.addElement = function(element){
    this.elements.add(element.id, element);
}
LessonNode.prototype.getOptionMaxScore = function(){
    if (!this.scoring) 
        return 0;
    var totalMax = 0;
    for (var i = 0; i < this.elements.getCount(); i++) {
        totalMax += this.elements.itemAt(i).maxScore;
    }
    return totalMax;
}
LessonNode.prototype.getOptionScore = function(){
    if (!this.scoring) 
        return 0;
    var totalScore = 0;
    for (var i = 0; i < this.elements.getCount(); i++) {
        totalScore += this.elements.itemAt(i).scoreEarned;
    }
    return totalScore;
}
/**
 * The element Object.
 * @param {Object} elementXML
 * @param {Object} elementPos
 */
function Element(elementXML, elementPos){
    this.xml = elementXML;
    this.pos = elementPos;
    this.type = this.xml.attributes[0].nodeValue;
    this.id = this.xml.attributes[1].nodeValue;
    this.name = this.xml.attributes[2].nodeValue;
    this.anyKey = (this.xml.attributes[3].nodeValue.toLowerCase() == "true");
    this.anyClick = (this.xml.attributes[4].nodeValue.toLowerCase() == "true");
    this.maxScore = parseInt(this.xml.attributes[5].nodeValue);
    this.lessonNodeId = this.xml.attributes[6].nodeValue;
    this.timeout = (this.xml.attributes[7].nodeValue.toLowerCase() == "true");
    this.timeoutValue = parseFloat(this.xml.attributes[8].nodeValue);
    this.scoreEarned = 0;
    try {
        this.showInReference = (this.xml.attributes[9].nodeValue.toLowerCase() == "true");
    } 
    catch (err) {
        this.showInReference = true;
    }
}

Element.prototype.setScore = function(score){
    this.scoreEarned = score;
}

function Variable(name, value){
    this.name = name;
    this.value = value;
    this.myValue = value;
    this.bookmark = false;
    this.variableType = 0; //0 - numerical; 1 - string
    this.userVariable = false;
}

Variable.prototype.saveBookmark = function(){
    if (this.bookmark && Author.bookMark) {
        Ext.state.Manager.set(Author.projectName + Author.traineeID + "[" + this.name.toUpperCase() + "]", this.value);
    }
}
Variable.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    try {
        this.name = trim(cfgXML.getElementsByTagName("name")[0].childNodes[0].nodeValue).toUpperCase();
    } 
    catch (err) {
        this.name = "";
        alert("Fail to load Uservarable: " + this.id + "\nPlease check it in the orginal lesson.");
    }
    this.value = null;
    this.variableType = parseInt(trim(cfgXML.getElementsByTagName("type")[0].childNodes[0].nodeValue));//0 - numerical; 1 - string
    this.userVariable = true;
    this.RTFName = "";
    try {
        this.RTFName = trim(cfgXML.getElementsByTagName("RTFName")[0].childNodes[0].nodeValue);
    } 
    catch (err) {
    }
    this.myValue = null;
    this.bookmark = trim(cfgXML.getElementsByTagName("bookMark")[0].childNodes[0].nodeValue).toLowerCase() == "true";
    if (this.variableType == 0) 
        this.value = 0;
    else 
        this.value = "";
}

Variable.prototype.init = function(name, id){
    this.id = trim(id);
    this.name = name;
    this.variableType = 0; //0 - numerical; 1 - string
    this.userVariable = false;
    this.RTFName = "";
    this.myValue = null;
    if (this.variableType == 0) 
        this.value = 0;
    else 
        this.value = "";
}
Variable.prototype.setValue = function(value){
    switch (this.name) {
        case "SCORM_STUDENT_ID":
            break;
        case "SCORM_STUDENT_NAME":
            break;
        case "SCORM_LESSON_LOCATION": //
            ScormProcessSetValue("cmi.core.lesson_location", value);
            break;
        case "SCORM_CREDIT":
            break;
        case "SCORM_LESSON_STATUS": //
            ScormProcessSetValue("cmi.core.lesson_status", value);
            break;
        case "SCORM_ENTRY":
            break;
        case "SCORM_SCORE_RAW": //
            ScormProcessSetValue("cmi.core.score.raw", value);
            break;
        case "SCORM_TOTAL_TIME": //
            ScormProcessSetValue("cmi.core.session_time", value);
            break;
        case "SCORM_LESSON_MODE":
            ScormProcessSetValue("cmi.core.lesson_mode", value);
            break;
        case "SCORM_EXIT_REASON": //
            ScormProcessSetValue("cmi.core.exit", value);
            break;
        case "SCORM_COMMENTS": //
            ScormProcessSetValue("cmi.coments", value);
            break;
        case "SCORM_COMMENTS_FROM_LMS":
            ScormProcessSetValue("cmi.comments_from_lms", value);
            break;
        case "SCORM_MAX_TIME_ALLOWED":
            ScormProcessSetValue("cmi.student_data.max_time_allowed", value);
            break;
        case "SCORM_TIME_LIMIT_ACTION":
            ScormProcessSetValue("cmi.student_data.time_limit_action", value);
            break;
        case "SCORM_LANGUAGE": //
            ScormProcessSetValue("cmi.student_preference.language", value);
            break;
        case "SCORM_SERVERPATH":
            this.value = value;
            this.myValue = value;
            break;
        case "SCORM_EXECUTABLELESSON":
            this.value = value;
            this.myValue = value;
            break;
        default:
            this.value = value;
            this.myValue = value;
    }
    
}
Variable.prototype.getValue = function(){
    switch (this.name) {
    
        case "ELEMENTNUMBER":
            return Author.current.currentElementPosition + 1;
        case "TIMEOUT":
            return this.value;
        case "FIRSTNAME":
            return this.value;
        case "LASTNAME":
            return this.value;
        case "FULLNAME":
            return this.value;
        case "USERID":
            return this.value;
        case "SELECTEDVALUE":
            return this.value;
        case "SELECTEDNAME":
            return this.value;
        case "ANSWER", "ATTEMPT":
            return this.value;
        case "DATE":
            return Ext.util.Format.date(new Date());
        case "DAY":
            return new Date().getDate();
        case "MONTH":
            return new Date().getMonth();
        case "YEAR":
            return new Date().getYear();
        case "TIME":
            return Ext.util.Format.date(new Date(), "g:i:s A");
        case "COLOURS":
            return this.value;
        case "SCORE":
            return getLessonScore();
        case "TOTAL":
            return getLessonTotal();
        case "%SCORE":
            var total = getLessonTotal();
            if (total == 0) {
                return 0;
            }
            else {
                return parseInt(getLessonScore() * 100 / total);
            }
        case "CORRECTANSWER":
            return this.name;
        case "QUESTIONANSWER":
            return this.name;
        case "RESOLUTION":
            return this.value;
        case "RESPONSETIME":
            return this.value;
        case "TIMER":
            return this.name;
        case "OPSCORE":
            return Author.current.currentNode.getOptionScore();
        case "OPTOTAL":
            return Author.current.currentNode.getOptionMaxScore();
        case "CHECKBOXES":
            return getCheckBoxValues();
        case "CORRECT":
            return checkAnswer();
        case "INCORRECT":
            return !checkAnswer();
        case "ELAPSEDTIME":
            return new Date() - Author.variables.get(variableName("STARTTIME")).value;
        case "INTELAPSEDTIME":
            //GetSystemValue = FindTimeDifference(Format(LastInteraction, "short time"), Format(Now, "short time"))
            return this.name;
        case "OPTIONTIME":
            var opStart = Author.current.currentNode.optionStart;
            if (opStart != null) {
                return new Date() - opStart;
            }
            else {
                return 0;
            }
        case "RUNTOTAL":
            return getLessonTotal();
        case "RUNOPTOTAL":
            return Author.current.currentNode.getOptionMaxScore();
        case "RUN%SCORE":
            var total = getLessonTotal();
            if (total == 0) {
                return 0;
            }
            else {
                return parseInt(getLessonScore() * 100 / total);
            }
        case "SCORM_STUDENT_ID":
            return ScormProcessGetValue("cmi.core.student_id");
        case "SCORM_STUDENT_NAME":
            return ScormProcessGetValue("cmi.core.student_name");
        case "SCORM_LESSON_LOCATION": //
            return ScormProcessGetValue("cmi.core.lesson_location");
        case "SCORM_CREDIT":
            return ScormProcessGetValue("cmi.core.credit");
        case "SCORM_LESSON_STATUS": //
            return ScormProcessGetValue("cmi.core.lesson_status");
        case "SCORM_ENTRY":
            return ScormProcessGetValue("cmi.core.entry");
        case "SCORM_SCORE_RAW": //
            return ScormProcessGetValue("cmi.core.score.raw");
        case "SCORM_TOTAL_TIME": //
            return ScormProcessGetValue("cmi.core.session_time");
        case "SCORM_LESSON_MODE":
            return ScormProcessGetValue("cmi.core.lesson_mode");
        case "SCORM_EXIT_REASON": //
            return ScormProcessGetValue("cmi.core.exit");
        case "SCORM_COMMENTS": //
            return ScormProcessGetValue("cmi.coments");
        case "SCORM_COMMENTS_FROM_LMS":
            return ScormProcessGetValue("cmi.comments_from_lms");
        case "SCORM_MAX_TIME_ALLOWED":
            return ScormProcessGetValue("cmi.student_data.max_time_allowed");
        case "SCORM_TIME_LIMIT_ACTION":
            return ScormProcessGetValue("cmi.student_data.time_limit_action");
        case "SCORM_LANGUAGE": //
            return ScormProcessGetValue("cmi.student_preference.language");
        case "SCORM_SERVERPATH":
            alert("SCORM_SERVERPATH is not implemented.");
            return this.name;
        case "SCORM_EXECUTABLELESSON":
            alert("SCORM_EXECUTABLELESSON is not implemented");
            return this.name;
        default:
            return this.value;
    }
}
function ResponseClass(condition, responseListXML){
    this.doing = false;
    this.condition = condition;
    this.responseListXML = responseListXML;
    this.score = parseInt(this.responseListXML.getElementsByTagName("score")[0].childNodes[0].nodeValue);
}

function ProgressbarClass(body, cfgXML){
    this.objectType = "PROGRESSBAR";
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue))
    this.left = parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue));
    this.top = parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue));
    this.borderWidth = parseInt(trim(cfgXML.getElementsByTagName("borderWidth")[0].childNodes[0].nodeValue));
    this.hide = trim(cfgXML.getElementsByTagName("hide")[0].childNodes[0].nodeValue).toLowerCase();
    this.visible = trim(cfgXML.getElementsByTagName("hide")[0].childNodes[0].nodeValue).toLowerCase() == "false";
    this.bgImage = Author.resourcePath + trim(cfgXML.getElementsByTagName("bgImage")[0].childNodes[0].nodeValue);
    this.barImage = Author.resourcePath + trim(cfgXML.getElementsByTagName("barImage")[0].childNodes[0].nodeValue);
    this.value = 50;
    this.content = body.createChild({
        tag: "div",
        style: "position:absolute;width:" + this.width + "px;height:" + this.height + "px"
    });
    this.bg = this.content.createChild({
        tag: "img",
        style: "position:absolute;left:0px;top:0px;width:" + this.width + "px;height:" + this.height + "px",
        src: this.bgImage
    })
    this.bar = this.content.createChild({
        tag: "img",
        style: "position:absolute;left:" + this.borderWidth + "px;top:0px;height:" + this.height + "px",
        src: this.barImage
    })
    this.content.on("mouseDown", function(e){
        e.stopEvent();
    })
}

ProgressbarClass.prototype.readConfig = function(cfgXML){
    this.setLeft(this.left);
    this.setTop(this.top);
    this.setValue(this.value);
    this.setVisible(this.visible);
    return 0;
}
ProgressbarClass.prototype.setValue = function(value){
    this.value = value;
    var barWidth = parseInt((this.width - this.borderWidth * 2) * value / 100);
    this.bar.setWidth(barWidth + "px");
}
ProgressbarClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
ProgressbarClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}

ProgressbarClass.prototype.setVisible = function(visible){
    this.visible = visible;
    this.content.setVisible(visible);
}
ProgressbarClass.prototype.remove = function(){
    this.content.remove();
}
/**
 * BackgroundClass
 * @param {Object} documentBody
 */
function BackgroundClass(documentBody){

    this.objectType = "BACKGROUNDOBEJCT";
    this.content = documentBody.createChild({
        tag: "div",
        style: "overflow:hidden;position:absolute;width:" + Author.lessonWidth + "px;height:" + Author.lessonHeight + "px"
    });
    
    this.center();
};

BackgroundClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    
    // this.setWidth(Author.lessonWidth + "px");
    // this.setHeight(Author.lessonHeight + "px");
    // this.setWidth(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue) + "px");
    //this.setHeight(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue) + "px");
    this.bgColor = "";
    this.bgImage = "";
    this.type = trim(cfgXML.getElementsByTagName("type")[0].childNodes[0].nodeValue);
    this.originalType = this.type;
    if (this.type == "color") {
        this.setBackgroundColor(trim(cfgXML.getElementsByTagName("background-color")[0].childNodes[0].nodeValue));
        this.originalColor = trim(cfgXML.getElementsByTagName("background-color")[0].childNodes[0].nodeValue);
        this.bgColor = this.originalColor;
    }
    else 
        if (this.type == "image") {
            this.setBackgroundImage(Author.resourcePath + trim(cfgXML.getElementsByTagName("image")[0].childNodes[0].nodeValue));
            this.originalImage = Author.resourcePath + trim(cfgXML.getElementsByTagName("image")[0].childNodes[0].nodeValue);
            this.bgImage = trim(cfgXML.getElementsByTagName("image")[0].childNodes[0].nodeValue);
        }
    
    if (Ext.isIE && typeof(Author.autoZoom) != 'undefined' && Author.autoZoom) {
    }
    else {
        this.setFx(cfgXML);
    }
    return 0;
    
}
BackgroundClass.prototype.setFx = function(cfgXML){

    try {
        if (!Author.travellingList) {
            this.fxEffect = parseInt(trim(cfgXML.getElementsByTagName("FxEffect")[0].childNodes[0].nodeValue));
            this.fxDuration = parseInt(trim(cfgXML.getElementsByTagName("FxDuration")[0].childNodes[0].nodeValue)) / 1000;
            return setFxToElement(this, this.fxEffect, this.fxDuration);
        }
        else {
            return 0;
        }
    } 
    catch (err) {
        return 0;
    }
}
BackgroundClass.prototype.setBg = function(bgObject){

    if (bgObject.type == "color") {
        this.type = "color";
        this.removeBackgroundImage();
        this.setBackgroundColor(bgObject.color);
        this.bgColor = bgObject.color;
        this.bgImage = "";
    }
    else 
        if (bgObject.type == "image") {
            this.type = "image";
            this.setBackgroundImage(Author.resourcePath + bgObject.image);
            this.bgColor = "";
            this.bgImage = bgObject.image;
        }
    
}
BackgroundClass.prototype.setOriginal = function(){

    if (this.originalType == "color") {
        this.removeBackgroundImage();
        this.setBackgroundColor(this.originalColor);
    }
    else 
        if (this.originalType == "image") {
            this.setBackgroundImage(this.originalImage);
        }
}


BackgroundClass.prototype.change = function(cfgXML){
    var changeBgObject = {
        epos: Author.current.currentElementPosition,
        type: this.type,
        color: this.bgColor,
        image: this.bgImage
    }
    if (!Author.travellingList) {
        var orginalBG = Ext.getBody().createChild({
            tag: "div",
            // style: "overflow:hidden;position:absolute;left:" + this.content.getStyle("left") + ";top:" + this.content.getStyle("top") + ";width:" + this.content.getStyle("width") + ";height:" + this.content.getStyle("height") 
            style: "overflow:hidden;position:absolute;left:" + this.content.getStyle("left") + ";top:" + this.content.getStyle("top") + ";width:" + Author.lessonWidth * Author.zoomRatio + "px;height:" + Author.lessonHeight * Author.zoomRatio + "px"
        });
        if (this.type == "color") {
        
            orginalBG.setStyle("background-color", this.color);
        }
        
        else 
            if (this.type == "image") {
                orginalBG.setStyle("background-image", "url(" + Author.resourcePath + this.bgImage + ")");
            }
        orginalBG.insertBefore(Author.backgroundObject.content);
    }
    var removeActions = true;
    try {
        removeActions = (cfgXML.attributes[1].nodeValue).toLowerCase() == "true";
    } 
    catch (err) {
    
    }
    if (removeActions) {
        //alert("removeActions");
        clearScreen();
    }
    if (cfgXML.getElementsByTagName("background-color")[0].childNodes[0] != null) {
        this.setBackgroundColor(trim(cfgXML.getElementsByTagName("background-color")[0].childNodes[0].nodeValue));
        changeBgObject.epos = Author.current.currentElementPosition;
        this.type = "color";
        this.bgColor = trim(cfgXML.getElementsByTagName("background-color")[0].childNodes[0].nodeValue);
        this.bgImage = "";
    }
    
    if (cfgXML.getElementsByTagName("image")[0].childNodes[0] != null) {
    
        this.setBackgroundImage(Author.resourcePath + trim(cfgXML.getElementsByTagName("image")[0].childNodes[0].nodeValue).toLowerCase());
        changeBgObject.epos = Author.current.currentElementPosition;
        //alert(changeBgObject.epos);
        this.type = "image";
        this.bgColor = ""
        this.bgImage = trim(cfgXML.getElementsByTagName("image")[0].childNodes[0].nodeValue).toLowerCase();
    }
    else {
        this.removeBackgroundImage();
    }
    
    Author.current.currentBgStack.add(new String(Author.current.currentElementPosition), changeBgObject);
    var effectDuration;
    if (Ext.isIE && typeof(Author.autoZoom) != 'undefined' && Author.autoZoom && Author.zoomRatio < 1) {
        //effectDuration = this.setFx(cfgXML);
    }
    else {
        effectDuration = this.setFx(cfgXML);
    }
    //alert(effectDuration);
    if (!Author.travellingList) {
        setTimeout(function(){
            // alert(orginalBG.getStyle("background-image"));
            orginalBG.remove();
            
        }, (effectDuration + 1000));
    }
    return 0;
}
BackgroundClass.prototype.setWidth = function(width){
    this.content.setWidth(width);
    this.center();
}
BackgroundClass.prototype.setHeight = function(height){
    this.content.setHeight(height);
    this.center();
    
}
BackgroundClass.prototype.center = function(){

    this.content.center();
    if (Ext.isIE && typeof(Author.autoZoom) != 'undefined' && Author.autoZoom) {
        var screenWidth = Ext.lib.Dom.getViewWidth();
        var screenHeight = Ext.lib.Dom.getViewHeight();
        var ratioV = screenHeight / Author.lessonHeight
        var ratioW = screenWidth / Author.lessonWidth
        var ratio = Math.min(ratioV, ratioW, 1);
        Author.zoomRatio = ratio;
        this.zoomTo(ratio);
    }
}
BackgroundClass.prototype.zoomTo = function(zoomRate){
    //alert("zoom to 75");
    //var zoomRate = 0.75;
    this.content.setStyle("zoom", zoomRate);
    var viewWidth = Ext.lib.Dom.getViewWidth();
    var viewHeight = Ext.lib.Dom.getViewHeight();
    
    this.content.setLeft((viewWidth - this.content.getWidth() * zoomRate) / 2);
    this.content.setTop((viewHeight - this.content.getHeight() * zoomRate) / 2);
}
BackgroundClass.prototype.setBackgroundColor = function(color){
    this.content.setStyle("background-color", color);
}
BackgroundClass.prototype.removeBackgroundImage = function(){
    this.content.setStyle("background-image", "");
}
BackgroundClass.prototype.setBackgroundImage = function(url){

    this.content.setStyle("background-image", "url(" + Ext.encode(url.toLowerCase()) + ")");
}

BackgroundClass.prototype.getContent = function(){
    return this.content;
}

function SpecialClass(cfgXML){
    this.objectType = "SPECIAL";
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.specialType = parseInt(trim(cfgXML.getElementsByTagName("specialType")[0].childNodes[0].nodeValue));
    switch (this.specialType) {
        case 0:
            this.specialExit = parseInt(trim(cfgXML.getElementsByTagName("specialExit")[0].childNodes[0].nodeValue));
            if (this.specialExit == 0) {
                if (Author.pause != null && Author.pause.cancelType != 0) {
                    Author.pause = null;
                    window.clearTimeout(Author.actionTimer);
                }
                window.open('', '_self', '');
                window.close();
            }
            else {
                // Author.backgroundObject.setOriginal();
                Author.current.currentNode = Author.lessonNodes.nodes.get(getParentNode());
                while (Author.current.currentBgStack.getCount() > 0) {
                    var bgObject = Author.current.currentBgStack.last();
                    Author.current.currentBgStack.remove(bgObject);
                    if (Author.current.currentBgStack.getCount() == 0) {
                        Author.backgroundObject.setBg(bgObject);
                    }
                }
                Author.current.currentElementXML = null;
                Author.current.currentElementType = "";
                Author.current.currentElementResponses.clear();
                Author.current.currentElementPosition = -1;
                Author.current.currentListPosition = 0;
                Author.response.clear();
                Author.current.currentElementResponses.clear();
                Author.current.randomOptionsCollection.clear();
                Author.clearBackgroundObjects = true;
                Author.backToMenu = true;
                Author.responseEnd = true;
                Author.inResponse = false;
                showLessonNode();
            }
            
            break;
        case 3:
            this.url = cfgXML.getElementsByTagName("URL")[0].childNodes[0].nodeValue;
            if (isUrl(this.url)) {
                myRef = window.open('' + this.url, 'win' + this.id);
            }
            else {
                var tryThis = "http://" + this.url;
                if (isUrl(tryThis)) {
                    myRef = window.open('' + tryThis, 'win' + this.id);
                }
                else {
                    displayError(this.url + " is not a vaild URL, please check it in the orginal lesson.\nNote: HTML lesson can only open url links.")
                }
            }
            
            break;
        case 4:
            this.innerHTML = cfgXML.getElementsByTagName("html")[0].childNodes[0].nodeValue;
            
            if (Ext.isIE) {
                printHidden(replaceVariableNameWithValue(this.innerHTML));
            }
            else {
                this.content = Author.backgroundObject.getContent().createChild({
                    tag: "iframe",
                    style: "position:absolute;overflow:auto;visible:none"
                });
                this.content.setWidth(0);
                this.content.setHeight(0);
                this.content.setVisible(false);
                var ifrm = this.content.dom;
                ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
                ifrm.document.open();
                ifrm.document.write(replaceVariableNameWithValue(this.innerHTML));
                ifrm.document.close();
                ifrm.focus();
                ifrm.print();
                this.content.remove();
            }
            break;
        case 11:
            this.specialID = parseInt(trim(cfgXML.getElementsByTagName("specialID")[0].childNodes[0].nodeValue));
            Author.current.currentNode = Author.lessonNodes.nodes.get(this.specialID);
            Author.current.currentElementXML = null;
            Author.current.currentElementType = "";
            Author.current.currentElementResponses.clear();
            Author.current.currentElementPosition = -1;
            Author.current.currentListPosition = 0;
            Author.response.clear();
            Author.current.randomOptionsCollection.clear();
            Author.current.currentElementResponses.clear();
            Author.clearBackgroundObjects = true;
            Author.backToMenu = true;
            showLessonNode();
            break;
        case 12:
            Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
                expires: new Date(new Date().getTime() + (1000 * 60 * 60 * 24 * 365))
            }));
            var lessonName = trim(cfgXML.getElementsByTagName("lessonName")[0].childNodes[0].nodeValue);
            var vName = trim(cfgXML.getElementsByTagName("variableName")[0].childNodes[0].nodeValue).toUpperCase();
            Author.variables.get(variableName(vName)).value = Ext.state.Manager.get(lessonName + Author.traineeID + "[" + vName + "]", "");
            break;
        case 13:
            try {
                this.showElementCode = (trim(cfgXML.getElementsByTagName("showElementCode")[0].childNodes[0].nodeValue.toLowerCase() == "true"));
                this.expandNode = (trim(cfgXML.getElementsByTagName("expandNode")[0].childNodes[0].nodeValue.toLowerCase() == "true"));
            } 
            catch (err) {
                this.showElementCode = false;
                this.expandNode = true;
            }
            showLessonStructure(this.showElementCode, this.expandNode);
            break;
    }
}

SpecialClass.prototype.readConfig = function(cfgXML){
}
SpecialClass.prototype.remove = function(){
    if (this.specialType == 4) {
        if (!Ext.isIE) {
            this.content.remove();
        }
    }
}
SpecialClass.prototype.setVisible = function(visible){
}

function WebElementClass(bgObject){
    this.objectType = "WEBBROWSEROBJECT";
    this.content = bgObject.createChild({
        tag: "iframe",
        frameborder: Ext.isIE ? "0" : "1",
        style: "position:absolute;background-color:#fff"
    })
}

WebElementClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.content.setStyle("position", "absolute");
    this.setTop(parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue)));
    this.setLeft(parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)));
    this.setWidth(parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue)));
    this.setHeight(parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue)));
    this.type = trim(cfgXML.getElementsByTagName("type")[0].childNodes[0].nodeValue);
    this.url = trim(cfgXML.getElementsByTagName("url")[0].childNodes[0].nodeValue);
    this.setURL(this.url);
    try {
        this.content.setStyle("border-style", trim(cfgXML.getElementsByTagName("borderStyle")[0].childNodes[0].nodeValue));
        this.content.setStyle("border-width", trim(cfgXML.getElementsByTagName("borderWidth")[0].childNodes[0].nodeValue));
        this.content.setStyle("border-color", trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue));
        
    } 
    catch (err) {
        alert("WebElement:\n" + err.description);
    }
    this.setVisible(true);
    return 0;
}


WebElementClass.prototype.toFront = function(){
    this.content.setStyle("z-index", 80);
}
WebElementClass.prototype.setURL = function(url){
    if (this.type == "WWW") 
        this.content.dom.src = eval(Ext.encode(url.toLowerCase()));
    else {
        var pagePath = location.pathname;
        pagePath = pagePath.substring(pagePath.lastIndexOf('/') + 1);
        var base = location.href.replace(pagePath, Author.resourcePath);
        this.content.dom.src = eval(Ext.encode(base + url.toLowerCase()));
    }
}
WebElementClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
WebElementClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
WebElementClass.prototype.setWidth = function(width){
    this.content.setWidth(width);
}
WebElementClass.prototype.setHeight = function(height){
    this.content.setHeight(height);
}
WebElementClass.prototype.setVisible = function(visible){
    this.visible = visible;
    this.content.setVisible(visible);
}
WebElementClass.prototype.remove = function(){

    this.content.remove();
}
/**
 * ImageClass
 * @param {Object} documentBody
 */
function ImageClass(bgObject, cfgXML){
    this.objectType = "IMAGEOBEJCT";
    this.changeByID = null;
    this.cfgXML = cfgXML;
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue))
    this.left = parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue));
    this.top = parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue));
    this.imageName = cfgXML.getElementsByTagName("image")[0].childNodes[0].nodeValue.toLowerCase();
    var imagePreLoad = new Image();
    imagePreLoad.src = Author.resourcePath + this.imageName;
    this.changeAction = trim(cfgXML.getElementsByTagName("changeAction")[0].childNodes[0].nodeValue).toLowerCase();
    this.hasShadow = trim(cfgXML.getElementsByTagName("shadow")[0].childNodes[0].nodeValue).toLowerCase();
    this.hide = trim(cfgXML.getElementsByTagName("hide")[0].childNodes[0].nodeValue).toLowerCase();
    this.addToBackground = (trim(cfgXML.getElementsByTagName("addToBackground")[0].childNodes[0].nodeValue).toLowerCase() == "true");
    // this.hasShadow="false";
    this.bgObject = bgObject;
    if (this.changeAction == "true") {
        this.originalID = trim(cfgXML.getElementsByTagName("originalID")[0].childNodes[0].nodeValue);
        this.changeID = trim(cfgXML.getElementsByTagName("changeID")[0].childNodes[0].nodeValue);
        try {
            this.addToBackground = Author.current.currentList.item(this.changeID).addToBackground;
        } 
        catch (err) {
            this.addToBackground = false;
        }
    }
    else {
        if (this.hasShadow == "true") {
            this.content = bgObject.createChild({
                tag: "div",
                style: "overflow:hidden;background: url(lib/images/upperrightfade.png) right top no-repeat;position:absolute;left:" + (this.left) + "px;top:" + (this.top) + "px;width:" + (this.width + 8) + "px;height:" + (this.height + 8) + "px"
            })
            var op2 = this.content.createChild({
                tag: "div",
                style: "overflow:hidden;background: url(lib/images/lowerleftfade.png) left bottom no-repeat; padding-top: 8px; padding-left: 8px;"
            })
            var shadowBox = op2.createChild({
                tag: "div",
                style: "background: url(lib/images/shadow.png) bottom right no-repeat;width:" + this.width + "px;height:" + this.height + "px;"
            })
            var innerBox = shadowBox.createChild({
                tag: "div",
                style: "overflow:hidden;position:relative;width:" + this.width + "px;height:" + this.height + "px; left: -8px; top: -8px;"
            })
            this.img = innerBox.createChild({
                tag: "img",
                style: "position:absolute;left:" + (0) + "px;top:" + (0) + "px;width:" + this.width + "px;height:" + this.height + "px;"
            })
        }
        else {
            this.content = bgObject.createChild({
                tag: "div",
                width: this.width + "px",
                height: this.height + "px",
                style: "position:absolute;left:" + (this.left) + "px;top:" + (this.top) + "px"
            });
            this.img = this.content.createChild({
                tag: "img",
                width: this.width + "px",
                height: this.height + "px",
                style: "position:absolute;left:" + (0) + "px;top:" + (0) + "px"
            })
        }
        this.content.on("mouseDown", function(e){
            e.stopEvent();
        })
        this.visible = true;
    }
};

ImageClass.prototype.toFront = function(){
    this.content.setStyle("z-index", 80);
}
ImageClass.prototype.change = function(cfgXML){
    Author.current.currentList.item(this.changeID).changeByID = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    var animate = trim(cfgXML.getElementsByTagName("AnimateImage")[0].childNodes[0].nodeValue).toLowerCase() == "true";
    this.imageName = cfgXML.getElementsByTagName("image")[0].childNodes[0].nodeValue.toLowerCase();
    var changeObject = Author.current.currentList.item(this.changeID);
    // var pageXY1 = Author.backgroundObject.content.getXY();
    
    changeObject.content.applyStyles("position:absolute;left:" + changeObject.left + "px;top:" + changeObject.top + "px");
    
    var oldLeft = changeObject.content.getStyle("left");
    var oldTop = changeObject.content.getStyle("top");
    //  alert(oldLeft + ", " + oldTop);
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue))
    this.left = parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue));
    this.top = parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue));
    this.hasShadow = trim(cfgXML.getElementsByTagName("shadow")[0].childNodes[0].nodeValue).toLowerCase();
    
    if (!animate) {
        //alert("not animate");
        oldLeft = this.left;
        oldTop = this.top;
    }
    if (this.hasShadow == "true") {
        this.content = this.bgObject.createChild({
            tag: "div",
            style: "background: url(lib/images/upperrightfade.png) right top no-repeat;position:absolute;left:" + (oldLeft) + ";top:" + (oldTop) + ";width:" + (this.width + 8) + "px;height:" + (this.height + 8) + "px"
        })
        var op2 = this.content.createChild({
            tag: "div",
            style: "background: url(lib/images/lowerleftfade.png) left bottom no-repeat; padding-top: 8px; padding-left: 8px;"
        })
        var shadowBox = op2.createChild({
            tag: "div",
            style: "background: url(lib/images/shadow.png) bottom right no-repeat;"
        })
        var innerBox = shadowBox.createChild({
            tag: "div",
            style: "position:relative;width:" + this.width + "px;height:" + this.height + "px; left: -8px; top: -8px;"
        })
        this.img = innerBox.createChild({
            tag: "img",
            style: "width:" + this.width + "px;height:" + this.height + "px"
        })
    }
    else {
        this.content = this.bgObject.createChild({
            tag: "div",
            width: this.width + "px",
            height: this.height + "px",
            style: "position:absolute;left:" + (oldLeft) + ";top:" + (oldTop) + ""
        });
        
        this.img = this.content.createChild({
            tag: "img",
            width: this.width + "px",
            height: this.height + "px",
            style: "position:absolute;left:" + (0) + "px;top:" + (0) + "px"
        })
    }
    
    
    var pageXY = Author.backgroundObject.content.getXY();
    var xy = this.content.getOffsetsTo(Author.backgroundObject.content);
    //alert(this.left-oldLeft1+"\n"+Author.zoomRatio);
    
    var xyOld = changeObject.content.getOffsetsTo(Author.backgroundObject.content);
    
    // this.x1 = pageXY[0] + xy[0] + (this.left - xyOld[0]);
    // this.y1 = pageXY[1] + xy[1] + (this.top - xyOld[1]);
    // alert(this.left - xyOld[0]+"\n"+Author.zoomRatio);
    this.x1 = pageXY[0] + xy[0] + this.left - xyOld[0] / Author.zoomRatio;
    this.y1 = pageXY[1] + xy[1] + this.top - xyOld[1] / Author.zoomRatio;
    this.imageName = cfgXML.getElementsByTagName("image")[0].childNodes[0].nodeValue.toLowerCase();
    
    this.addToBackground = Author.current.currentList.item(this.changeID).addToBackground;
    if (this.addToBackground) {
        this.addToBackgroundAtElementPosition = Author.current.currentList.item(this.changeID).addToBackgroundAtElementPosition;
        this.orginalListID = Author.current.currentListXML.attributes[1].nodeValue;
        Author.backgroundList.list.add(this.id, this);
    }
    
    this.setImage(Author.resourcePath + this.imageName);
    this.setVisible(true);
    
    this.setAnimation(cfgXML) + this.setFx(cfgXML);
    return 0;
}
ImageClass.prototype.setProperties = function(cfgXML){
    this.imageName = cfgXML.getElementsByTagName("image")[0].childNodes[0].nodeValue.toLowerCase();
    this.setTop(parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue)));
    this.setLeft(parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)));
    this.setWidth(parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue)));
    this.setHeight(parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue)));
    this.setImage(Author.resourcePath + this.imageName);
    this.setVisible(true);
    try {
        //   this.doRotationAndFlip(cfgXML);
    } 
    catch (err) {
    }
}
/**
 * this is the code for doing the rotation and flipping and shadow of the image using the Raphael Library, unfortunately since it is not
 * quite compatible with the Opacity, we just forget it for the moment.
 *
 *
 * @param {Object} cfgXML
 */
ImageClass.prototype.doRotationAndFlip = function(cfgXML){
    // resize the container
    
    // hide the current image 
    this.img.setVisible(false);
    var flip = cfgXML.getElementsByTagName("flip")[0].childNodes[0].nodeValue;
    var rotation = parseInt(cfgXML.getElementsByTagName("rotation")[0].childNodes[0].nodeValue);
    // if (rotation > 0) {
    
    //calculate the smallest square that can contain the rotation of the image
    var r = parseInt(Math.sqrt(this.width * this.width + this.height * this.height));
    var newLeft = this.left - (r - this.width) / 2;
    var newTop = this.top - (r - this.height) / 2;
    //move the container to a proper location so that when drawing the image in the center, the position of the image will not change.
    this.content.applyStyles("position:absolute;left:" + newLeft + "px;top:" + newTop + "px;width:" + (r) + "px;height:" + (r) + "px");
    var imageContainer = Raphael(this.content.dom, r, r);
    //   }
    // else {
    //     var imageContainer = Raphael(this.content.dom, this.width, this.height);
    // }
    
    // only to match the 4 rotations in author. no need to do so ..
    var angle = 360 - 90 * rotation;
    
    if (rotation == 1) {
        angle = 270;
        var temp = this.height;
        this.height = this.width;
        this.width = temp;
        if (flip == "V") {
            flip = "H";
        }
        else 
            if (flip == "H") {
                flip = "V";
            }
    }
    if (rotation == 3) {
        angle = 90;
        var temp = this.height;
        this.height = this.width;
        this.width = temp;
        if (flip == "V") {
            flip = "H";
        }
        else 
            if (flip == "H") {
                flip = "V";
            }
    }
    // alert(angle +", "+flip);
    // this.RImage = imageContainer.set();
    // alert(this.hasShadow);
    if (this.hasShadow == "true") {
    
        // Draw the shadow.
        // Params: 	shadowR -shadow Size
        //			shadowColor 
        //			offsetX
        //			offsetY
        //			alpha
        try {
            this.RShadow = imageContainer.set();
            var shadowR = parseInt(cfgXML.getElementsByTagName("shadowSize")[0].childNodes[0].nodeValue);
            var shadowColor = cfgXML.getElementsByTagName("shadowColor")[0].childNodes[0].nodeValue;
            var offsetX = parseInt(cfgXML.getElementsByTagName("shadowX")[0].childNodes[0].nodeValue);
            var offsetY = parseInt(cfgXML.getElementsByTagName("shadowY")[0].childNodes[0].nodeValue);
            var alpha = parseInt(cfgXML.getElementsByTagName("shadowAlpha")[0].childNodes[0].nodeValue) / 255;
            
            var shadowWidth = this.width + shadowR * 2;
            var shadowHeight = this.height + shadowR * 2;
            shadowR = shadowR * 2;
            var rect = imageContainer.rect((r - shadowWidth) / 2 + shadowR, (r - shadowHeight) / 2 + shadowR, shadowWidth - shadowR * 2, shadowHeight - shadowR * 2);
            rect.attr({
                fill: shadowColor,
                stroke: 0,
                opacity: alpha
            })
            rect.translate(offsetX, offsetY);
            this.RShadow.push(rect);
            
            for (var i = 0; i < shadowR; i += Author.zoomRatio) {
                var rect = imageContainer.rect((r - shadowWidth) / 2 + shadowR - i, (r - shadowHeight) / 2 + shadowR - i, shadowWidth - (shadowR - i) * 2, shadowHeight - (shadowR - i) * 2, i);
                rect.attr({
                    stroke: shadowColor,
                    "stroke-opacity": curve((i / shadowR), 1.28) * alpha,
                    "stroke-width": Author.zoomRatio
                })
                rect.translate(offsetX, offsetY);
                this.RShadow.push(rect);
            }
        } 
        catch (err) {
        
        }
    }
    // this.RImage=imageContainer.image(this.img.dom.src, (r - this.width) / 2, (r - this.height) / 2, this.width, this.height);
    // if (rotation > 0) {
    this.RImage = imageContainer.image(this.img.dom.src, (r - this.width) / 2, (r - this.height) / 2, this.width, this.height);
    this.rotate(angle);
    // }
    // else {
    //    this.RImage = imageContainer.image(this.img.dom.src, 0, 0, this.width, this.height);
    
    // }
    
    /*
     this.RImage.attr({
     stroke:"none",
     "stroke-width":0
     })
     */
    // alert(Author.zoomRatio);
    
    this.flip(flip);
    
    
}
/**
 * Rotate the image by angle degree
 * @param {Object} angle
 */
ImageClass.prototype.rotate = function(angle){
    this.RImage.attr({
        rotation: angle
    });
    if (this.hasShadow == "true") {
        this.RShadow.attr({
            rotation: angle
        });
    }
}
/**
 * flip the image
 * @param {Object} type
 */
ImageClass.prototype.flip = function(type){
    if (type == "V") {
        this.RImage.scale(1, -1);
    }
    if (type == "H") {
        this.RImage.scale(-1, 1);
    }
    if (type == "VH") {
        this.RImage.scale(-1, -1);
    }
}
/**
 * hide or show the shadow of the image
 * @param {Object} visible
 */
ImageClass.prototype.setShadowVisible = function(visible){
    this.content.setVisible(visible);
    this.img.setVisible(true);
    /*
     try {
     if (visible) {
     this.RShadow.show();
     
     }
     else {
     this.RShadow.hide();
     }
     }
     catch (err) {
     }
     */
}
ImageClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    if (this.changeAction == "true") {
        Author.current.currentList.item(this.changeID).setVisible(false);
        return this.change(cfgXML);
    }
    this.setProperties(cfgXML);
    this.addToBackground = (trim(cfgXML.getElementsByTagName("addToBackground")[0].childNodes[0].nodeValue).toLowerCase() == "true");
    if (this.addToBackground) {
        this.orginalListID = Author.current.currentListXML.attributes[1].nodeValue;
        Author.backgroundList.list.add(this.id, this);
        this.addToBackgroundAtElementPosition = Author.current.currentElementPosition;
    }
    this.setFx(cfgXML);
    return 0;
}
ImageClass.prototype.setAnimation = function(cfgXML){
    try {
        var animate = trim(cfgXML.getElementsByTagName("AnimateImage")[0].childNodes[0].nodeValue).toLowerCase();
        if (animate == "true") {
            var speed = parseInt(trim(cfgXML.getElementsByTagName("AnimateSpeed")[0].childNodes[0].nodeValue));
            var steps = parseInt(trim(cfgXML.getElementsByTagName("AnimateSteps")[0].childNodes[0].nodeValue));
            var fxElement = (this.hasShadow == "true") ? this.img : this.content;
            var duration = speed * steps * 20 / 1000
            fxElement.sequenceFx();
            fxElement.shift({
                width: this.width,
                height: this.height,
                x: this.x1,
                y: this.y1,
                duration: duration
            });
            return duration * 1000;
        }
        else {
            return 0;
        }
    } 
    catch (err) {
        return 0;
    }
}
ImageClass.prototype.setFx = function(cfgXML){
    this.fxEffect = 0;
    try {
        this.fxEffect = parseInt(trim(cfgXML.getElementsByTagName("FxEffect")[0].childNodes[0].nodeValue));
        this.fxDuration = parseInt(trim(cfgXML.getElementsByTagName("FxDuration")[0].childNodes[0].nodeValue)) / 1000;
        return setFxToElement(this, this.fxEffect, this.fxDuration);
    } 
    catch (err) {
        return 0;
    }
}
ImageClass.prototype.setImage = function(url){
    this.img.dom.src = eval(Ext.encode(url.toLowerCase()));
    this.fixPng();
}
ImageClass.prototype.fixPng = function(){
    var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
    var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
    if (Ext.isIE && (ie55 || ie6) && (this.imageName.indexOf(".png") >= 0)) {
        this.img.setStyle("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + Author.resourcePath + this.imageName + "',sizingMethod='scale')");
        this.img.dom.src = "lib/images/blank.gif";
    }
}
ImageClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
ImageClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
ImageClass.prototype.setWidth = function(width){
    if (this.hasShadow == "true") 
        width = width + 8;
    this.content.setWidth(width);
}
ImageClass.prototype.setHeight = function(height){
    if (this.hasShadow == "true") 
        height = height + 8;
    this.content.setHeight(height);
}
ImageClass.prototype.setVisible = function(visible){
    //alert("setVisible "+visible +","+this.changeByID);
    //alert(this.changeByID);
    this.visible = visible;
    
    if (this.changeByID != null) {
    
        Author.current.currentList.item(this.changeByID).setVisible(visible);
    }
    else {
        if (this.hasShadow == "true") {
            this.setShadowVisible(visible);
        }
        this.img.setVisible(visible);
    }
}
ImageClass.prototype.hide = function(visible){

    if (this.changeByID != null) {
        Author.current.currentList.item(this.changeByID).setVisible(visible);
    }
    else {
        this.setVisible(visible);
    }
}
ImageClass.prototype.remove = function(){
    try {
    
        if (this.changeAction == "true") {
            Author.current.currentList.item(this.originalID).changeByID = null;
        }
        if (this.fxEffect != 0) {
            this.img.stopFx();
        }
        this.content.remove();
    } 
    catch (err) {
    }
}
/**
 * MediaClass
 * @param {Object} documentBody
 */
function MediaClass(bgObject, cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.top = parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue));
    this.left = parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue));
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue))
    this.objectType = "MEDIAOBJECT";
    this.url = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("url")[0].childNodes[0].nodeValue))).toLowerCase();
    this.autoStart = trim(cfgXML.getElementsByTagName("autoStart")[0].childNodes[0].nodeValue).toLowerCase();
    this.playCount = trim(cfgXML.getElementsByTagName("playCount")[0].childNodes[0].nodeValue);
    this.uiMode = (trim(cfgXML.getElementsByTagName("uiMode")[0].childNodes[0].nodeValue));
    this.playSelection = (trim(cfgXML.getElementsByTagName("playSelection")[0].childNodes[0].nodeValue).toLowerCase() == "true");
    this.startPos = parseFloat(trim(cfgXML.getElementsByTagName("startPosition")[0].childNodes[0].nodeValue));
    this.endPos = parseFloat(trim(cfgXML.getElementsByTagName("endPosition")[0].childNodes[0].nodeValue))
    this.visible = true;
    
    if (Ext.isMac) {
        this.height = (this.height - (this.uiMode == "none" ? 0 : 65))
        this.mediaObject = bgObject.createChild({
            tag: "OBJECT",
            classid: "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B",
            codebase: "http://www.apple.com/qtactivex/qtplugin.cab",
            style: "position:absolute;left:" + this.left + "px;top:" + this.top + "px;width:" + this.width + "px;height:" + this.height + "px",
            children: [{
                tag: "PARAM",
                NAME: "src",
                VALUE: this.url
            }, {
                tag: "PARAM",
                NAME: "controller",
                VALUE: "false"
            }, {
                tag: "PARAM",
                NAME: "AUTOPLAY",
                VALUE: this.autoStart
            }, {
                tag: "embed",
                name: "quickTime" + this.id,
                width: this.width + "px",
                height: this.height + "px",
                src: this.url,
                enablejavascript: "true",
                postdomevents: "True",
                autoPlay: this.autoStart,
                type: "video/quicktime",
                controller: "false"
            }]
        });
        this.qtObject = (Ext.isGecko ? this.mediaObject.dom.children[3] : this.mediaObject.dom);
        this.qtObject.uiMode = this.uiMode;
        Ext.EventManager.addListener(this.qtObject, "qt_pause", function(e){
            var obj = e.getTarget();
            if (obj.uiMode != "none") {
                obj.controller.container.playing = false;
                obj.controller.container.stopped = true;
                obj.controller.container.playBtn.dom.src = "lib/images/" + (obj.controller.container.playing ? "pauseBtnNormal.jpg" : "playBtnNormal.jpg");
                obj.controller.container.stopBtn.dom.src = "lib/images/" + (obj.controller.container.stopped ? "stopBtnStopped.jpg" : "stopBtnNormal.jpg");
                obj.controller.container.statusSpan.dom.innerHTML = "Paused"
                obj.controller.container.timeSpan.dom.innerHTML = obj.controller.container.formatTime(obj.controller.container.qtObject.GetTime() * 1000 / obj.controller.container.qtObject.GetTimeScale());
            }
        })
        Ext.EventManager.addListener(this.qtObject, "qt_play", function(){
            var qtObject = Author.current.currentPlayingWMPObject;
            qtObject = (Ext.isGecko ? qtObject.dom.children[3] : qtObject.dom);
            
            var duration = qtObject.GetDuration();
            var timeEclipsed = qtObject.GetTime();
            var timeScaled = qtObject.GetTimeScale();
            var countDown = (duration - timeEclipsed) * 1000 / timeScaled;
            window.clearTimeout(Author.actionTimer);
            Author.pause = {
                cancelType: 1,
                startTime: new Date(),
                id: 0,
                key1: "none",
                key2: "none"
            }
            Author.pause.countDown = countDown;
            Author.actionTimer = setTimeout(showList, countDown);
        })
        
        this.mediaObject.checkStatus = function(object){
            var quickTimeObject = (Ext.isGecko ? object.dom.children[3] : object.dom);
            try {
                var plugStatus = quickTimeObject.GetPluginStatus();
                if (plugStatus.indexOf("Error") > 0) {
                    alert(plugStatus);
                }
            } 
            catch (err) {
                object.mediaTimer = setTimeout(object.checkStatus, 200, object);
            }
        }
        if (this.uiMode != "none") {
            this.controller = new MediaController(bgObject, this.left, this.width, this.height + this.top, this.qtObject, this.autoStart == "true");
            this.qtObject.controller = this.controller;
        }
        Author.mediaList.add(this.id, this);
        return;
    }
    else {
    
        if (Ext.isIE) {
            Author.mediaList.eachKey(function(key, object){
                if (object.objectType == "MEDIAOBJECT") {
                    try {
                        object.mediaObject.dom.controls.stop();
                        object.mediaObject.dom.settings.mute = true;
                    } 
                    catch (err) {
                    }
                }
                if (object.objectType == "SOUNDOBJECT") {
                    object.mediaObject.dom.controls.stop();
                }
            });
            this.mediaObject = bgObject.createChild({
                tag: "OBJECT",
                CLASSID: "CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6",
                type: "application/x-oleobject",
                children: [{
                    tag: "PARAM",
                    NAME: "URL",
                    VALUE: this.url
                }, {
                    tag: "PARAM",
                    NAME: "autoStart",
                    VALUE: "false"//this.autoStart
                }, {
                    tag: "PARAM",
                    NAME: "uiMode",
                    VALUE: this.uiMode
                }, {
                    tag: "PARAM",
                    NAME: "PlayCount",
                    VALUE: this.playCount
                }, {
                    tag: "PARAM",
                    NAME: "SendPlayStateChangeEvents",
                    VALUE: "True"
                }],
                style: "position:absolute;left:" + this.left + "px;top:" + this.top + "px;width:" + this.width + "px;height:" + this.height + "px"
            
            });
            this.mediaObject.autoStart = this.autoStart;
            this.mediaObject.startPosition = this.startPos;
            this.mediaObject.endPosition = this.endPos;
            this.mediaObject.playSelection = this.playSelection;
            this.mediaObject.checkSelection = function(){
                // alert("checking");
                if (!Author.selectionMediaObject.playSelection) {
                    return;
                }
                try {
                    var wmpObject = Author.selectionMediaObject.dom.object;
                    //window.status=wmpObject.controls.currentPosition +", "+wmpObject.controls.currentPositionString;
                    if (wmpObject.controls.currentPosition < Author.selectionMediaObject.startPosition) {
                    
                        if ((wmpObject.controls.currentPositionString != "")) {
                            wmpObject.controls.pause();
                        }
                        wmpObject.controls.currentPosition = Author.selectionMediaObject.startPosition;
                        //wmpObject.controls.play();
                    }
                    
                    if (wmpObject.controls.currentPosition > Author.selectionMediaObject.endPosition) {
                        // wmpObject.controls.currentPosition = Author.selectionMediaObject.startPosition;
                        wmpObject.controls.pause();
                    }
                    //  alert(Author.selectionMediaObject.firstPlay);
                    
                    if (Author.selectionMediaObject.firstPlay && (wmpObject.controls.currentPositionString != "") && (Math.abs(wmpObject.controls.currentPosition - parseFloat(Author.selectionMediaObject.startPosition)) < 0.4)) {
                        // alert(wmpObject.controls.currentPosition+","+wmpObject.controls.currentPositionString+","+Math.abs(wmpObject.controls.currentPosition - parseFloat(Author.selectionMediaObject.startPosition)));
                        if (Author.selectionMediaObject.autoStart == "true") {
                            wmpObject.controls.play();
                        }
                        Author.selectionMediaObject.firstPlay = false;
                    }
                    //   else {
                    Author.selectionMediaObject.selectionTimer = setTimeout(Author.selectionMediaObject.checkSelection, 100);
                    //  }
                } 
                catch (err) {
                    //   alert(err.description);
                }
            }
            Author.selectionMediaObject = this.mediaObject;
            
            Author.waitingMedia = true;
            Author.mediaList.add(this.id, this);
            return;
        }
        else {
            Author.mediaList.eachKey(function(key, object){
                if (object.objectType == "MEDIAOBJECT") {
                    try {
                        object.mediaObject.dom.children[0].controls.stop();
                        object.mediaObject.dom.children[0].settings.mute = true;
                    } 
                    catch (err) {
                    }
                }
                if (object.objectType == "SOUNDOBJECT") {
                    object.stop();
                }
            });
            
            this.mediaObject = bgObject.createChild({
                tag: "OBJECT",
                style: "position:absolute;left:" + this.left + "px;top:" + this.top + "px;width:" + this.width + "px;height:" + this.height + "px",
                children: [{
                    tag: "embed",
                    height: this.height + "px",
                    width: this.width + "px",
                    name: "plugin",
                    src: this.url,
                    uiMode: this.uiMode,
                    autoStart: this.autoStart,
                    SendPlayStateChangeEvents: "true",
                    type: "application/x-ms-wmp"
                }]
            });
            this.mediaObject.checkStatus = function(object){
                var wmpObject = object.dom.children[0];
                
                switch (wmpObject.playState) {
                    case 1:
                        Author.pause = null;
                        window.clearTimeout(Author.actionTimer);
                        showList();
                        break;
                    case 3:
                        var duration = wmpObject.currentMedia.duration;
                        var timeEclipsed = wmpObject.controls.currentPosition;
                        var countDown = (duration - timeEclipsed) * 1000;
                        window.clearTimeout(Author.actionTimer);
                        Author.pause = {
                            cancelType: 1,
                            startTime: new Date(),
                            id: 0,
                            key1: "none",
                            key2: "none"
                        }
                        Author.pause.countDown = countDown;
                        Author.actionTimer = setTimeout(showList, countDown);
                        object.mediaTimer = setTimeout(object.checkStatus, 200, object);
                        break;
                        
                    case 8:
                        Author.pause = null;
                        window.clearTimeout(Author.actionTimer);
                        showList();
                        break;
                    default:
                        object.mediaTimer = setTimeout(object.checkStatus, 200, object);
                        break;
                }
            }
            this.mediaObject.autoStart = this.autoStart;
            this.mediaObject.startPosition = this.startPos;
            this.mediaObject.endPosition = this.endPos;
            this.mediaObject.playSelection = this.playSelection;
            this.mediaObject.checkSelection = function(theobject){
                //alert(theobject.playSelection);
                if (!theobject.playSelection) {
                    //alert("why you are here "+Author.selectionMediaObject.playSelection);
                    return;
                }
                try {
                    var wmpObject = theobject.dom.children[0];
                    
                    // alert(wmpObject.controls.currentPosition +", " +theobject.startPosition+", "+theobject.endPosition+", "+wmpObject.controls.currentPositionString);
                    if (wmpObject.controls.currentPosition < theobject.startPosition) {
                        if ((wmpObject.controls.currentPositionString != "")) {
                            wmpObject.controls.pause();
                        }
                        wmpObject.controls.currentPosition = theobject.startPosition;
                        
                    }
                    
                    if (wmpObject.controls.currentPosition > theobject.endPosition) {
                        // wmpObject.controls.currentPosition = theobject.startPosition;
                        wmpObject.controls.pause();
                    }
                    
                    if (theobject.firstPlay && (wmpObject.controls.currentPositionString != "") && (Math.abs(wmpObject.controls.currentPosition - parseFloat(theobject.startPosition)) < 0.4)) {
                        // alert(wmpObject.controls.currentPosition+","+wmpObject.controls.currentPositionString+","+Math.abs(wmpObject.controls.currentPosition - parseFloat(Author.selectionMediaObject.startPosition)));
                        //alert(theobject.autoStart);
                        if (theobject.autoStart == "true") {
                            wmpObject.controls.play();
                        }
                        theobject.firstPlay = false;
                    }
                    //   else {
                    theobject.selectionTimer = setTimeout(theobject.checkSelection, 100, theobject);
                    //  }
                } 
                catch (err) {
                    alert(err.description);
                    
                }
            }
            Author.mediaList.add(this.id, this);
            return;
        }
    }
}

MediaClass.prototype.readConfig = function(cfgXML){

    this.waitUntilComplete = trim(cfgXML.getElementsByTagName("waitUntilComplete")[0].childNodes[0].nodeValue).toLowerCase();
    this.cancelType = parseInt(trim(cfgXML.getElementsByTagName("cancelType")[0].childNodes[0].nodeValue));
    this.duration = parseFloat(trim(cfgXML.getElementsByTagName("duration")[0].childNodes[0].nodeValue));
    
    if (this.waitUntilComplete == "true") {
        if (Ext.isMac) {
            Author.current.currentPlayingWMPObject = this.mediaObject;
            if (this.uiMode == "none") 
                this.mediaObject.mediaTimer = setTimeout(this.mediaObject.checkStatus, 1000, this.mediaObject);
            return 3600 * 24 * 1000;
        }
        else {
            if (Ext.isIE) {
            
                if (this.uiMode.toLowerCase() == "none") {
                    Ext.getBody().setStyle("cursor", "wait");
                    
                    var pageXY = Author.backgroundObject.content.getXY();
                    var xy = this.mediaObject.getOffsetsTo(Author.backgroundObject.content);
                    var t = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue)) + xy[1] + pageXY[1] + 20;
                    var l = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue)) / 2 + +xy[0] + pageXY[0];
                    var VE = Ext.get("videoLoading");
                    VE.setVisible(true);
                    VE.setLocation(t, l);
                }
                Author.current.currentPlayingWMPObject = this.mediaObject.dom.object;
                this.mediaObject.dom.attachEvent("playStateChange", function(status){
                    var mediaObj = Author.current.currentPlayingWMPObject;
                    
                    try {
                        var duration = mediaObj.controls.currentItem.duration;
                        var timeEclipsed = mediaObj.controls.currentPosition;
                        var countDown = (duration - timeEclipsed) * 1000;
                        if (status == 3) {
                            mediaObj.controls.currentPosition = 2.5;
                            Ext.getBody().setStyle("cursor", "default");
                            Ext.get("videoLoading").setVisible(false);
                            window.clearTimeout(Author.actionTimer);
                            Author.pause = {
                                cancelType: 1,
                                startTime: new Date(),
                                id: 0,
                                key1: "none",
                                key2: "none"
                            }
                            Author.pause.countDown = countDown;
                            Author.actionTimer = setTimeout(showList, countDown);
                        }
                    } 
                    catch (err) {
                    
                    }
                });
                
                if (this.autoStart == "true") {
                    this.mediaObject.dom.object.controls.play();
                }
                if (this.playSelection) {
                    this.mediaObject.selectionTimer = setTimeout(this.mediaObject.checkSelection, 100);
                    this.mediaObject.dom.object.controls.play();
                    Author.selectionMediaObject.firstPlay = true;
                }
                return 3600 * 24 * 1000;
            }
            else {
            
                Author.current.currentPlayingWMPObject = this.mediaObject.dom.children[0];
                if (this.autoStart == "true") {
                    Author.current.currentPlayingWMPObject.controls.play();
                }
                this.mediaObject.mediaTimer = setTimeout(this.mediaObject.checkStatus, 200, this.mediaObject);
                if (this.playSelection) {
                    this.mediaObject.selectionTimer = setTimeout(this.mediaObject.checkSelection, 100, this.mediaObject);
                    Author.current.currentPlayingWMPObject.controls.play();
                    this.mediaObject.firstPlay = true;
                }
                return 3600 * 24 * 1000;
            }
        }
    }
    else {
        //  alert(this.playSelection);
        if (Ext.isMac) {
        
        }
        else 
            if (Ext.isIE) {
            
                Author.current.currentPlayingWMPObject = this.mediaObject.dom.object;
                
                if (this.autoStart == "true") {
                    this.mediaObject.dom.object.controls.play();
                }
                if (this.playSelection) {
                
                    this.mediaObject.selectionTimer = setTimeout(this.mediaObject.checkSelection, 100);
                    //  this.mediaObject.dom.object.controls.currentPosition =this.mediaObject.startPosition;
                    this.mediaObject.dom.object.controls.play();
                    //  this.mediaObject.dom.object.controls.currentPosition =this.mediaObject.startPosition;
                    Author.selectionMediaObject.firstPlay = true;
                }
            }
            else {
                Author.current.currentPlayingWMPObject = this.mediaObject.dom.children[0];
                if (this.autoStart == "true") {
                    Author.current.currentPlayingWMPObject.controls.play();
                }
                if (this.playSelection) {
                    this.mediaObject.selectionTimer = setTimeout(this.mediaObject.checkSelection, 100, this.mediaObject);
                    Author.current.currentPlayingWMPObject.controls.play();
                    this.mediaObject.firstPlay = true;
                }
            }
        return 300;
    }
    
}
MediaClass.prototype.setVisible = function(visible){
    this.visible = visible
    this.mediaObject.setVisible(visible);
    
}
MediaClass.prototype.setStyle = function(CSSStyle){
    this.mediaObject.applyStyles(CSSStyle);
}
MediaClass.prototype.remove = function(){
    if (Ext.isMac) {
        if (this.uiMode != "none") {
            this.controller.remove();
        }
    }
    else {
        if (Ext.isIE) {
            this.mediaObject.dom.object.controls.stop();
        }
        else {
            try {
                this.mediaObject.dom.children[0].controls.stop();
            } 
            catch (err) {
            }
        }
    }
    //  alert("remove Media");
    this.mediaObject.remove();
}
MediaController = function(body, left, width, height, qtObject, autoPlay){
    this.width = Math.max(150, width);
    this.left = left;
    this.volumeBarWidth = Math.min(80, this.width / 3);
    this.container = body.createChild({
        tag: "div",
        style: "position:absolute;left:" + this.left + "px;top:" + height + "px;width:" + this.width + "px;height:65px;z-index:30;background-color:#000",
        children: [{
            tag: "img",
            style: "position:absolute;left:0px;top:0px;width:1px;height:65px",
            src: "lib/images/controllerBorder.jpg"
        }, {
            tag: "img",
            style: "position:absolute;left:1px;top:0px;width:" + (this.width - 2) + "px;height:65px",
            src: "lib/images/controllerbg.jpg"
        }, {
            tag: "img",
            style: "position:absolute;left:" + (this.width - 1) + "px;top:0px;width:1px;height:65px",
            src: "lib/images/controllerBorder.jpg"
        }]
    });
    this.container.qtObject = qtObject;
    if (!autoPlay) {
        this.container.playing = false;
        this.container.stopped = true;
    }
    else {
        this.container.playing = true;
        this.container.stopped = false;
    }
    this.container.value = 0;
    this.container.mute = qtObject.GetMute() == "true";
    this.container.volume = parseInt(qtObject.GetVolume() * 100 / 256);
    this.container.on("mousedown", function(e){
        e.stopEvent();
    })
    this.container.statusSpan = this.container.createChild({
        tag: "span",
        style: "position:absolute;left:14px;top:2px;width:" + (this.width * 2 / 3) + "px;height:18px;font-family:Courier New;color:#84C5FF;font-size:12px;z-index:30;background-color:#000",
        html: (autoPlay ? "Playing" : "Ready")
    })
    this.container.timeSpan = this.container.createChild({
        tag: "span",
        style: "position:absolute;width:35px;top:2px;left:" + (this.width - 40) + "px;height:18px;text-align:center;font-family:Courier New;color:#84C5FF;font-size:12px;z-index:30;background-color:#000",
        html: "00:00"
    })
    this.container.playBtn = this.container.createChild({
        tag: "img",
        style: "position:absolute;left:4px;top:33px;width:29px;height:29px",
        src: "lib/images/" + (this.container.playing ? "pauseBtnNormal.jpg" : "playBtnNormal.jpg")
    })
    this.container.playBtn.on("mouseover", function(){
        this.dom.src = "lib/images/" + (this.parent().playing ? "pauseBtnMouseOver.jpg" : "playBtnMouseOver.jpg");
    })
    this.container.playBtn.on("mouseout", function(){
        this.dom.src = "lib/images/" + (this.parent().playing ? "pauseBtnNormal.jpg" : "playBtnNormal.jpg");
    })
    this.container.playBtn.on("click", function(e){
        e.stopEvent();
        this.parent().stopped = false;
        this.parent().playing = !this.parent().playing;
        this.parent().stopBtn.dom.src = "lib/images/" + (this.parent().stopped ? "stopBtnStopped.jpg" : "stopBtnNormal.jpg");
        this.dom.src = "lib/images/" + (this.parent().playing ? "pauseBtnNormal.jpg" : "playBtnNormal.jpg");
        if (this.parent().playing) {
            this.parent().qtObject.Play();
            this.parent().statusSpan.dom.innerHTML = "Playing";
            this.parent().timer = setTimeout(this.parent().updateBtnState, 200, this.parent());
        }
        else {
            this.parent().qtObject.Stop();
            this.parent().statusSpan.dom.innerHTML = "Paused";
        }
    })
    this.container.playBtn.on("mousedown", function(e){
        e.stopEvent();
        this.dom.src = "lib/images/" + (this.parent().playing ? "pauseBtnMouseDown.jpg" : "playBtnMouseDown.jpg");
    })
    this.container.playBtn.on("mouseup", function(e){
        e.stopEvent();
    })
    this.container.stopBtn = this.container.createChild({
        tag: "img",
        style: "position:absolute;left:35px;top:38px;width:19px;height:20px",
        src: "lib/images/" + (this.container.stopped ? "stopBtnStopped.jpg" : "stopBtnNormal.jpg")
    })
    this.container.stopBtn.on("click", function(e){
        e.stopEvent();
    })
    this.container.stopBtn.on("mouseover", function(){
        this.dom.src = "lib/images/" + (this.parent().stopped ? "stopBtnStopped.jpg" : "stopBtnMouseOver.jpg");
    })
    this.container.stopBtn.on("mouseout", function(){
        this.dom.src = "lib/images/" + (this.parent().stopped ? "stopBtnStopped.jpg" : "stopBtnNormal.jpg");
    })
    this.container.stopBtn.on("mousedown", function(e){
        e.stopEvent();
        this.parent().qtObject.Stop();
        this.parent().stopped = true;
        this.parent().playing = false;
        this.dom.src = "lib/images/" + (this.parent().stopped ? "stopBtnStopped.jpg" : "stopBtnMouseDown.jpg");
        this.parent().playBtn.dom.src = "lib/images/" + (this.parent().playing ? "pauseBtnNormal.jpg" : "playBtnNormal.jpg");
        this.parent().statusSpan.dom.innerHTML = "Stopped";
    })
    this.container.stopBtn.on("mouseup", function(e){
        e.stopEvent();
        this.dom.src = "lib/images/" + (this.parent().stopped ? "stopBtnStopped.jpg" : "stopBtnNormal.jpg");
    })
    this.container.muteBtn = this.container.createChild({
        tag: "img",
        style: "position:absolute;left:64px;top:38px;width:20px;height:20px",
        src: "lib/images/" + (this.container.mute ? "muteBtnMuted.jpg" : "muteBtnNormal.jpg")
    })
    this.container.muteBtn.on("mouseover", function(){
        this.dom.src = "lib/images/" + (this.parent().mute ? "muteBtnMuted.jpg" : "muteBtnMouseOver.jpg");
    })
    this.container.muteBtn.on("mouseout", function(){
        this.dom.src = "lib/images/" + (this.parent().mute ? "muteBtnMuted.jpg" : "muteBtnNormal.jpg");
    })
    this.container.muteBtn.on("mousedown", function(e){
        e.stopEvent();
    })
    this.container.muteBtn.on("mouseup", function(){
        this.dom.src = "lib/images/" + (this.parent().mute ? "muteBtnMuted.jpg" : "muteBtnMouseOver.jpg");
    })
    this.container.muteBtn.on("click", function(e){
        e.stopEvent();
        this.parent().qtObject.SetMute(!eval(this.parent().qtObject.GetMute()));
        this.parent().mute = eval(this.parent().qtObject.GetMute());
        this.dom.src = "lib/images/" + (this.parent().mute ? "muteBtnMuted.jpg" : "muteBtnMouseOver.jpg");
    })
    this.container.tracker = this.container.createChild({
        tag: "div",
        style: "position:absolute;left:14px;top:21px;width:" + (this.width - 28) + "px;height:10px;cursor:pointer;cursor:hand",
        children: [{
            tag: "img",
            style: "position:absolute;left:0px;top:0px;width:1px;height:10px",
            src: "lib/images/pBorder.jpg"
        }, {
            tag: "img",
            style: "position:absolute;left:1px;top:0px;width:" + (this.width - 28 - 2) + "px;height:10px",
            src: "lib/images/pBg.jpg"
        }, {
            tag: "img",
            style: "position:absolute;left:" + (this.width - 28 - 1) + "px;top:0px;width:1px;height:10px",
            src: "lib/images/pBorder.jpg"
        }]
    })
    this.container.tracker.fill = this.container.tracker.createChild({
        tag: "img",
        style: "position:absolute;left:1px;top:0px;width:" + ((this.width - 28 - 2) * this.container.value / 100) + "px;height:10px",
        src: "lib/images/pFill.jpg"
    })
    this.container.tracker.fill.setValue = function(value){
        this.setStyle("width", parseInt((this.parent().getWidth() - 2) * value / 100) + "px");
    }
    this.container.tracker.on("click", function(e){
        e.stopEvent();
        tracker = Ext.get(e.getTarget()).parent();
        var value = parseInt((e.getPageX() - tracker.getLeft()) * 100 / (tracker.getWidth() - 2));
        this.fill.setValue(value);
        var duration = this.parent().qtObject.GetDuration();
        this.parent().qtObject.SetTime(value / 100 * duration);
        this.parent().value = value;
    })
    this.container.tracker.on("mousedown", function(e){
        e.stopEvent();
    })
    this.container.volumeBar = this.container.createChild({
        tag: "div",
        style: "position:absolute;left:88px;top:43px;width:" + (this.volumeBarWidth) + "px;height:10px;cursor:pointer;cursor:hand",
        children: [{
            tag: "img",
            style: "position:absolute;left:0px;top:0px;width:1px;height:10px",
            src: "lib/images/vBorder.jpg"
        }, {
            tag: "img",
            style: "position:absolute;left:1px;top:0px;width:" + (this.volumeBarWidth - 2) + "px;height:10px",
            src: "lib/images/vBg.jpg"
        }, {
            tag: "img",
            style: "position:absolute;left:" + (this.volumeBarWidth - 1) + "px;top:0px;width:1px;height:10px",
            src: "lib/images/vBorder.jpg"
        }]
    })
    this.container.volumeBar.fill = this.container.volumeBar.createChild({
        tag: "img",
        style: "position:absolute;left:1px;top:0px;width:" + ((this.volumeBarWidth - 2) * this.container.volume / 100) + "px;height:10px",
        src: "lib/images/vFill.jpg"
    })
    this.container.volumeBar.fill.setValue = function(value){
        this.setStyle("width", ((this.parent().getWidth() - 2) * value / 100) + "px");
    }
    this.container.volumeBar.on("click", function(e){
        e.stopEvent();
        volume = Ext.get(e.getTarget()).parent();
        var value = parseInt((e.getPageX() - volume.getLeft()) * 100 / (volume.getWidth() - 2));
        this.fill.setValue(value);
        this.parent().qtObject.SetVolume(value * 256 / 100);
    })
    this.container.volumeBar.on("mousedown", function(e){
        e.stopEvent();
    })
    this.container.formatTime = function(milisecond){
        if (typeof(milisecond) == 'undefined') 
            milisecond = 0;
        var second = parseInt(milisecond / 1000);
        var minutes = Math.floor(second / 60);
        second = second - minutes * 60;
        return (minutes < 10 ? "0" : "") + minutes + ":" + (second < 10 ? "0" : "") + second;
    }
    this.container.updateBtnState = function(container){
        try {
            container.value = parseInt(container.qtObject.GetTime() * 100 / container.qtObject.GetDuration());
            container.volume = parseInt(container.qtObject.GetVolume() * 100 / 256);
            container.tracker.fill.setValue(container.value);
            container.volumeBar.fill.setValue(container.volume);
            container.timeSpan.dom.innerHTML = container.formatTime(container.qtObject.GetTime() * 1000 / container.qtObject.GetTimeScale());
        } 
        catch (err) {
        }
        container.timer = setTimeout(container.updateBtnState, 200, container);
    }
    if (autoPlay) 
        this.container.timer = setTimeout(this.container.updateBtnState, 200, this.container);
}

MediaController.prototype.remove = function(){
    this.container.remove();
}
/**
 * SoundClass
 * @param {Object} documentBody
 */
function SoundClass(bgObject, cfgXML){
    Author.waitAudioFinish = false;
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.objectType = "SOUNDOBJECT";
    this.url = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("url")[0].childNodes[0].nodeValue))).toLowerCase();
    this.playCount = trim(cfgXML.getElementsByTagName("playCount")[0].childNodes[0].nodeValue);
    if (Author.mediaList.containsKey(this.id)) {
        //alert("contains this id "+ this.id);
        this.mediaID = Author.mediaList.get(this.id).mediaID;
        this.content = Author.mediaList.get(this.id).content;
        this.mediaObject = Author.mediaList.get(this.id).mediaObject;
        
        return;
    }
    this.content = bgObject.createChild({
        tag: "div",
        style: "position:absolute;top:-2000px;" + ((Ext.isIE) ? "display:none" : "")
    });
    this.mediaID = this.content.dom.id + "-Media";
    if (Ext.isIE) {
        Author.mediaList.eachKey(function(key, object){
            if (object.objectType == "SOUNDOBJECT") {
                object.mediaObject.dom.controls.stop();
                object.mediaObject.dom.settings.mute = true;
            }
        });
        this.mediaObject = this.content.createChild({
            tag: "OBJECT",
            CLASSID: "CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6",
            type: "application/x-oleobject",
            children: [{
                tag: "PARAM",
                NAME: "URL",
                VALUE: this.url
            }, {
                tag: "PARAM",
                NAME: "autoStart",
                VALUE: "False"
            }, {
                tag: "PARAM",
                NAME: "uiMode",
                VALUE: "none"
            }, {
                tag: "PARAM",
                NAME: "PlayCount",
                VALUE: this.playCount
            }, {
                tag: "PARAM",
                NAME: "SendPlayStateChangeEvents",
                VALUE: "True"
            }]
        });
        
        
        this.mediaObject.dom.settings.mute = false;
        Author.mediaList.add(this.id, this);
    }
    else {
        this.mediaObject = this.content.createChild({
            tag: "OBJECT",
            classid: "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
            id: this.mediaID,
            codebase: "http://download.macromedia.com/pub/shockwave /cabs/flash/swflash.cab#version=9,0,115,0",
            width: "1px",
            height: "1px",
            align: "",
            children: [{
                tag: "PARAM",
                NAME: "movie",
                VALUE: "lib/media/myJSPlayer.swf"
            }, {
                tag: "embed",
                src: "lib/media/myJSPlayer.swf",
                name: this.mediaID,
                type: "application/x-shockwave-flash",
                swLiveConnect: "true",
                pluginspage: "http://www.macromedia.com/go/getflashplayer"
            }]
        });
        //alert("before add: "+Author.mediaList.getCount())
        Author.mediaList.add(this.id, this);
        //alert("afterAdd: "+Author.mediaList.getCount())
    }
}

function onPlay(id){
    var mp3Object = Author.mediaList.get(id);
    window.clearTimeout(Author.actionTimer);
    if (mp3Object.waitUntilComplete == "true") {
        Author.pause = {
            cancelType: 0,
            startTime: new Date(),
            id: 0,
            key1: "none",
            key2: "none"
        }
        Author.pause.countDown = mp3Object.duration * 1000;
        //alert("set sound countDown: " + mp3Object.duration  + " secs.\nWait until finish: " + mp3Object.waitUntilComplete);
        Author.actionTimer = setTimeout(showList, parseFloat(mp3Object.duration) * 1000);
    }
    else {
        Author.actionTimer = setTimeout(showList, 10);
    }
    //alert("Playing: " + mp3Object.url + "\nWait until finished: " + mp3Object.waitUntilComplete + "\nDuration: " + mp3Object.duration);
}

SoundClass.prototype.readConfig = function(cfgXML){
    this.waitUntilComplete = trim(cfgXML.getElementsByTagName("waitUntilComplete")[0].childNodes[0].nodeValue).toLowerCase();
    this.duration = parseFloat(trim(cfgXML.getElementsByTagName("duration")[0].childNodes[0].nodeValue));
    
    if (!Ext.isIE) {
        this.flashObj = this.getFlashObj();
        if (this.flashObj == null) {
            return 300;
        }
        if ((typeof(this.flashObj) == "undefined") || (this.flashObj.PercentLoaded() != 100)) {
            Author.current.currentActionPosition--;
            Author.removeDup = false;
            return 500;
        }
        
        this.registerEvent('onPlay', "onPlay(\'" + this.id + "\')");
        this.loadAndPlay(this.url);
        Author.removeDup = false;
        return 3600 * 24 * 1000;
    }
    else 
        if (Ext.isIE) {
            Author.listStarted = false;
            Author.current.currentPlayingWMPObject = this.mediaObject;
            Author.waitAudioFinish = (this.waitUntilComplete == "true");
            this.mediaObject.dom.attachEvent("playStateChange", function(status){
                var mediaObj = Author.current.currentPlayingWMPObject.dom.object;
                var duration = mediaObj.controls.currentItem.duration;
                var timeEclipsed = mediaObj.controls.currentPosition;
                var countDown = (duration - timeEclipsed) * 1000;
                if (status == 3) {
                    if (Author.waitAudioFinish) {
                        window.clearTimeout(Author.actionTimer);
                        Author.pause = {
                            cancelType: 0,
                            startTime: new Date(),
                            id: 0,
                            key1: "none",
                            key2: "none"
                        }
                        Author.pause.countDown = countDown;
                        //alert("set sound countDown: " + countDown / 1000 + " secs.\nWait until finish: " + Author.waitAudioFinish);
                        Author.actionTimer = setTimeout(showList, countDown);
                    }
                    else {
                        if (!Author.listStarted) {
                            Author.listStarted = true;
                            window.clearTimeout(Author.actionTimer);
                            Author.actionTimer = setTimeout(showList, 10);
                        }
                    }
                }
            });
            this.mediaObject.dom.controls.play();
            return 3600 * 24 * 1000;
        }
}
SoundClass.prototype.getFlashObj = function(){
    if (Ext.isIE) 
        return Ext.getDom(this.mediaID);
    else {
        try {
            return Ext.getDom(this.mediaID).children[1];
        } 
        catch (err) {
        
            return null;
        }
        
    }
}
SoundClass.prototype.play = function(){
    this.flashObj.TCallLabel('/', 'play');
};

SoundClass.prototype.stop = function(){
    this.flashObj.TCallLabel('/', 'stop');
};

SoundClass.prototype.pause = function(){
    this.flashObj.TCallLabel('/', 'pause');
};

SoundClass.prototype.reset = function(){
    this.flashObj.TCallLabel('/', 'reset');
};

SoundClass.prototype.load = function(url){
    this.flashObj.SetVariable('currentSong', url);
    this.flashObj.TCallLabel('/', 'load');
};

SoundClass.prototype.loadAndPlay = function(url){
    this.load(url);
    this.play();
};

SoundClass.prototype.registerEvent = function(eventName, action){
    this.flashObj.SetVariable(eventName, action);
};

SoundClass.prototype.remove = function(){
    if (Ext.isIE) 
        this.mediaObject.dom.controls.stop();
    //alert("before remove: "+Author.mediaList.getCount())
    //this.stop();
    Author.mediaList.removeKey(this.id);
    //alert("after remove: "+Author.mediaList.getCount())
    this.content.remove();
}
function TXTextClass(bgObject, cfgXML){
    this.objectType = "TXTEXTOBJECT";
    this.addToBackground = (trim(cfgXML.getElementsByTagName("addToBackground")[0].childNodes[0].nodeValue) == "True");
    this.hide = trim(cfgXML.getElementsByTagName("hide")[0].childNodes[0].nodeValue).toLowerCase();
    try {
        this.imageSrc = trim(cfgXML.getElementsByTagName("picture")[0].childNodes[0].nodeValue).toLowerCase();
        var img = new Image();
        img.src = Author.resourcePath + this.imageSrc;
        this.imageX = parseInt(trim(cfgXML.getElementsByTagName("pictureX")[0].childNodes[0].nodeValue));
        this.imageY = parseInt(trim(cfgXML.getElementsByTagName("pictureY")[0].childNodes[0].nodeValue));
        this.imageVisible = trim(cfgXML.getElementsByTagName("pictureVisible")[0].childNodes[0].nodeValue).toLowerCase();
    } 
    catch (err) {
        this.imageSrc = "";
    }
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue));
    this.changeAction = trim(cfgXML.getElementsByTagName("changeAction")[0].childNodes[0].nodeValue).toLowerCase();
    
    if (this.changeAction == "true") {
        this.originalID = trim(cfgXML.getElementsByTagName("originalID")[0].childNodes[0].nodeValue);
        this.changeID = trim(cfgXML.getElementsByTagName("changeID")[0].childNodes[0].nodeValue);
        try {
            this.addToBackground = Author.current.currentList.item(this.changeID).addToBackground;
        } 
        catch (err) {
            this.addToBackground = false;
        }
    }
    this.content = bgObject.createChild({
        tag: "div",
        style: "position:absolute;overflow:hidden"
    
    });
    if (this.imageSrc != "" && this.imageVisible == "true") {
        this.image = this.content.createChild({
            tag: "img",
            style: "position:absolute;alt:''"
        });
        this.image.dom.src = Author.resourcePath + this.imageSrc;
        this.fixPng();
    }
    var scroll = "visible";
    if (cfgXML.getElementsByTagName("scrollBar")[0].childNodes[0].nodeValue.toLowerCase() == "true") 
        scroll = "scroll";
    scroll = "overflow:visible;overflow-x:visible;overflow-y:" + scroll;
    this.text = this.content.createChild({
        tag: "div",
        style: "position:absolute;left:0px;top:0px;width:" + this.width + "px;height:" + this.height + "px;"
    });
    try {
        this.textStr = (cfgXML.getElementsByTagName("html")[0].childNodes[0].nodeValue);
    } 
    catch (err) {
        this.textStr = "";
    }
    
    this.p = this.text.createChild({
        tag: "div",
        style: "position:absolute;left:0px;top:0px;width:" + this.width + "px;height:" + this.height + "px;" + scroll + ";padding:1px 1px 1px 1px",
        html: replaceVariableNameWithValue(this.textStr)
    });
}

TXTextClass.prototype.setFx = function(cfgXML){
    this.fxEffect = 0;
    try {
        this.fxEffect = parseInt(trim(cfgXML.getElementsByTagName("FxEffect")[0].childNodes[0].nodeValue));
        this.fxDuration = parseInt(trim(cfgXML.getElementsByTagName("FxDuration")[0].childNodes[0].nodeValue)) / 1000;
        return setFxToElement(this, this.fxEffect, this.fxDuration);
    } 
    catch (err) {
        return 0;
    }
}

TXTextClass.prototype.toFront = function(){
    this.content.setStyle("z-index", 80);
}
TXTextClass.prototype.fixPng = function(){
    var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
    var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
    if (Ext.isIE && (ie55 || ie6) && (this.imageSrc.indexOf(".png") >= 0)) {
        this.image.setStyle("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + Author.resourcePath + this.imageSrc + "',sizingMethod='scale')");
        this.image.dom.src = "lib/images/blank.gif";
    }
}
TXTextClass.prototype.change = function(cfgXML){
    Author.current.currentList.item(this.changeID).changeByID = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.setProperties(cfgXML);
    this.addToBackground = Author.current.currentList.item(this.changeID).addToBackground;
    if (this.addToBackground) {
        this.addToBackgroundAtElementPosition = Author.current.currentList.item(this.changeID).addToBackgroundAtElementPosition;
        this.orginalListID = Author.current.currentListXML.attributes[1].nodeValue;
        Author.backgroundList.list.add(this.id, this);
    }
    this.setFx(cfgXML); //1.2 seconds
    return 0;
}
TXTextClass.prototype.setProperties = function(cfgXML){
    this.setTop(parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue)));
    this.setLeft(parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)));
    this.setWidth(this.width);
    this.setHeight(this.height);
    this.borderWidth = parseInt(trim(cfgXML.getElementsByTagName("borderWidth")[0].childNodes[0].nodeValue));
    // this.content.setStyle("border-width", this.borderWidth);
    // this.content.setStyle("border-color", trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue));
    //  this.content.setStyle("border-style", trim(cfgXML.getElementsByTagName("borderStyle")[0].childNodes[0].nodeValue));
    //  this.content.applyStyles("position: absolute; width: " + (this.width - this.borderWidth * 2) + "px; height: " + (this.height - this.borderWidth * 2) + "px");
    this.text.applyStyles("position: absolute; width: " + (this.width - this.borderWidth * 2) + "px; height: " + (this.height - this.borderWidth * 2) + "px");
    try {
        if (this.imageSrc != "" && this.imageVisible == "true") 
            this.setImagePosition(parseInt(trim(cfgXML.getElementsByTagName("pictureAlign")[0].childNodes[0].nodeValue)));
    } 
    catch (err) {
        alert("TXTextClass:" + err);
    }
    this.setBackground(cfgXML);
    /*
     try {
     this.setHTML(cfgXML.getElementsByTagName("html")[0].childNodes[0].nodeValue);
     }
     catch (err) {
     displayError("TXTCLASSOBJECT[id:" + this.id + "] doesn't have any text, please check it in the orginal lesson.");
     }
     */
}
TXTextClass.prototype.backgroundFadein = function(duration){
    this.bg.attr({
        opacity: 0
    })
    this.bg.animate({
        opacity: 1
    }, duration);
}
TXTextClass.prototype.setBackground = function(cfgXML){
    var backStyle = parseInt(trim(cfgXML.getElementsByTagName("backStyle")[0].childNodes[0].nodeValue));
    var bgColorStr = trim(cfgXML.getElementsByTagName("backgroundColor")[0].childNodes[0].nodeValue);
    var gradientType = parseInt(trim(cfgXML.getElementsByTagName("gradientType")[0].childNodes[0].nodeValue));
    var startColorStr = trim(cfgXML.getElementsByTagName("startColorStr")[0].childNodes[0].nodeValue);
    var endColorStr = trim(cfgXML.getElementsByTagName("endColorStr")[0].childNodes[0].nodeValue);
    var bgContainer = Raphael(this.content.dom, this.width, this.height);
    //  alert("backStyle: "+backStyle+"\ngradientType: "+gradientType);
    var roundCorner = trim(cfgXML.getElementsByTagName("roundCorner")[0].childNodes[0].nodeValue).toLowerCase() == "true";
    var r = roundCorner ? Math.min(this.width, this.height) / 10 : 0;
    this.bg = bgContainer.rect(0, 0, this.width - 1, this.height - 1, r);
    // this.bg = bgContainer.rect(0, 0, this.width - 1, this.height - 1, 0);
    
    switch (backStyle) {
        case 1:
        case 2:
            this.bg.attr({
                "fill": bgColorStr
            })
            if (backStyle == 2) {
                this.bg.attr({
                    opacity: .5
                })
            }
            break;
        case 3: //Gradient
        case 4:
            switch (gradientType) {
                case 1: // Right to Left
                    this.bg.attr({
                        gradient: "180-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 2: // Top to bottom
                    this.bg.attr({
                        gradient: "270-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 3: // Bottom to Top
                    this.bg.attr({
                        gradient: "90-" + startColorStr + "-" + endColorStr
                    })
                    break;
                    
                case 6: // tl-br
                    this.bg.attr({
                        gradient: "315-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 7: // br-tl
                    this.bg.attr({
                        gradient: "135-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 8: //tr-bl
                    this.bg.attr({
                        gradient: "225-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 9: //bl-tr
                    this.bg.attr({
                        gradient: "45-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 10: //tl br c
                    this.bg.attr({
                        gradient: "315-" + startColorStr + "-" + endColorStr + ":50" + "-" + startColorStr
                    })
                    break;
                case 11: //tl br c
                    this.bg.attr({
                        gradient: "315-" + endColorStr + "-" + startColorStr + ":50" + "-" + endColorStr
                    })
                    break;
                case 12: //tl br c
                    this.bg.attr({
                        gradient: "225-" + startColorStr + "-" + endColorStr + ":50" + "-" + startColorStr
                    })
                    break;
                case 13: //tl br c
                    this.bg.attr({
                        gradient: "225-" + endColorStr + "-" + startColorStr + ":50" + "-" + endColorStr
                    })
                    break;
                case 16: //tl br c
                    this.bg.attr({
                        gradient: "0-" + startColorStr + "-" + endColorStr + ":50" + "-" + startColorStr
                    })
                    break;
                case 17: //tl br c
                    this.bg.attr({
                        gradient: "0-" + endColorStr + "-" + startColorStr + ":50" + "-" + endColorStr
                    })
                    break;
                case 18: //tl br c
                    this.bg.attr({
                        gradient: "90-" + startColorStr + "-" + endColorStr + ":50" + "-" + startColorStr
                    })
                    break;
                case 19: //tl br c
                    this.bg.attr({
                        gradient: "90-" + endColorStr + "-" + startColorStr + ":50" + "-" + endColorStr
                    })
                    break;
                default:
                    this.bg.attr({
                        gradient: "0-" + startColorStr + "-" + endColorStr
                    })
                    break;
            }
            if (backStyle == 4) {
                this.bg.attr({
                    opacity: .5
                })
            }
            break;
        default:
    }
    //alert("borderColor: " + trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue) + "\nWidth: " + this.borderWidth);
    this.bg.attr({
        stroke: trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue),
        "stroke-width": this.borderWidth
    })
    // this.content.setStyle("border-width", this.borderWidth + "px");
    // this.content.setStyle("border-color", trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue));
    // this.content.setStyle("border-style", trim(cfgXML.getElementsByTagName("borderStyle")[0].childNodes[0].nodeValue));
}
TXTextClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.changeByID = null;
    if (this.changeAction == "true") {
        Author.current.currentList.item(this.changeID).setVisible(false);
        return this.change(cfgXML);
    }
    this.setProperties(cfgXML);
    this.addToBackground = (trim(cfgXML.getElementsByTagName("addToBackground")[0].childNodes[0].nodeValue).toLowerCase() == "true");
    if (this.addToBackground) {
        this.orginalListID = Author.current.currentListXML.attributes[1].nodeValue;
        Author.backgroundList.list.add(this.id, this);
        this.addToBackgroundAtElementPosition = Author.current.currentElementPosition;
    }
    this.setFx(cfgXML); //1.2 seconds
    return 0;
}
TXTextClass.prototype.setImagePosition = function(index){
    var imageWidth = this.image.getWidth();
    var imageHeight = this.image.getHeight();
    var bgWidth = this.content.getWidth();
    var bgHeight = this.content.getHeight();
    switch (index) {
        case 0:
            this.image.setLeft(this.imageX);
            this.image.setTop(this.imageY);
            break;
        case 1:
            this.image.setLeft(this.imageX);
            this.image.setTop(this.imageY + (bgHeight - imageHeight) / 2);
            break;
        case 2:
            this.image.setLeft(this.imageX);
            this.image.setTop(this.imageY + (bgHeight - imageHeight));
            break;
        case 3:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth));
            this.image.setTop(this.imageY);
            break;
        case 4:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth));
            this.image.setTop(this.imageY + (bgHeight - imageHeight) / 2);
            break;
        case 5:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth));
            this.image.setTop(this.imageY + (bgHeight - imageHeight));
            break;
        case 6:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth) / 2);
            this.image.setTop(this.imageY);
            break;
            break;
        case 7:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth) / 2);
            this.image.setTop(this.imageY + (bgHeight - imageHeight) / 2);
            break;
        case 8:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth) / 2);
            this.image.setTop(this.imageY + (bgHeight - imageHeight));
            break;
    }
}
TXTextClass.prototype.setHTML = function(htmlContent){
    this.p.dom.innerHTML = replaceVariableNameWithValue(htmlContent);
}
TXTextClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
TXTextClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
TXTextClass.prototype.setWidth = function(width){
    this.width = width;
    this.content.setWidth(width);
}
TXTextClass.prototype.setHeight = function(height){
    this.height = height;
    this.content.setHeight(height);
}
TXTextClass.prototype.setVisible = function(visible){
    this.visible = visible;
    if (this.changeByID != null) {
        Author.current.currentList.item(this.changeByID).setVisible(visible);
    }
    else {
        this.content.setVisible(visible);
    }
}
TXTextClass.prototype.remove = function(){
    try {
        if (this.changeAction == "true") {
            Author.current.currentList.item(this.originalID).changeByID = null;
        }
        this.content.remove();
    } 
    catch (err) {
    }
}

TXTextClass.prototype.setStyle = function(CSSStyle){
    this.content.applyStyles(CSSStyle);
}
/**
 * TextClass
 * @param {Object} bgObject
 */
function TextClass(bgObject, cfgXML){
    this.objectType = "TEXTOBJECT";
    this.imageVisible = "false";
    this.changeByID = null;
    this.hide = trim(cfgXML.getElementsByTagName("hide")[0].childNodes[0].nodeValue).toLowerCase();
    this.addToBackground = (trim(cfgXML.getElementsByTagName("addToBackground")[0].childNodes[0].nodeValue) == "True");
    try {
        this.imageSrc = trim(cfgXML.getElementsByTagName("picture")[0].childNodes[0].nodeValue).toLowerCase();
        var img = new Image();
        img.src = Author.resourcePath + this.imageSrc;
        this.imageX = parseInt(trim(cfgXML.getElementsByTagName("pictureX")[0].childNodes[0].nodeValue));
        this.imageY = parseInt(trim(cfgXML.getElementsByTagName("pictureY")[0].childNodes[0].nodeValue));
        this.imageVisible = trim(cfgXML.getElementsByTagName("pictureVisible")[0].childNodes[0].nodeValue).toLowerCase();
    } 
    catch (err) {
        this.imageSrc = "";
    }
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue));
    this.textX = parseInt(trim(cfgXML.getElementsByTagName("textX")[0].childNodes[0].nodeValue));
    this.textY = parseInt(trim(cfgXML.getElementsByTagName("textY")[0].childNodes[0].nodeValue));
    this.textPosition = parseInt(trim(cfgXML.getElementsByTagName("textPosition")[0].childNodes[0].nodeValue));
    
    this.changeAction = trim(cfgXML.getElementsByTagName("changeAction")[0].childNodes[0].nodeValue).toLowerCase();
    if (this.changeAction == "true") {
        this.originalID = trim(cfgXML.getElementsByTagName("originalID")[0].childNodes[0].nodeValue);
        this.changeID = trim(cfgXML.getElementsByTagName("changeID")[0].childNodes[0].nodeValue);
        try {
            this.addToBackground = Author.current.currentList.item(this.changeID).addToBackground;
        } 
        catch (err) {
            this.addToBackground = false;
        }
    }
    this.content = bgObject.createChild({
        tag: "div",
        style: "overflow:hidden;position:absolute"
    });
    
    
    if (this.imageSrc != "" && this.imageVisible == "true") {
        var iWidth = parseInt(cfgXML.getElementsByTagName("picture")[0].attributes[0].nodeValue);
        var iHeight = parseInt(cfgXML.getElementsByTagName("picture")[0].attributes[1].nodeValue);
        this.image = this.content.createChild({
            tag: "img",
            width: iWidth,
            height: iHeight,
            style: "position:absolute;alt:''"
        });
        this.image.dom.src = Author.resourcePath + this.imageSrc;
        this.fixPng();
    };
    this.text = this.content.createChild({
        tag: "div",
        style: "position:absolute"
    });
    var textStyle = "font-family:" + trim(cfgXML.getElementsByTagName("font-family")[0].childNodes[0].nodeValue) + ";";
    textStyle = textStyle + "font-size:" + trim(cfgXML.getElementsByTagName("font-size")[0].childNodes[0].nodeValue) + "pt;";
    textStyle = textStyle + "font-style:" + trim(cfgXML.getElementsByTagName("font-style")[0].childNodes[0].nodeValue) + ";";
    textStyle = textStyle + "font-weight:" + trim(cfgXML.getElementsByTagName("font-weight")[0].childNodes[0].nodeValue) + ";";
    textStyle = textStyle + "text-decoration:" + trim(cfgXML.getElementsByTagName("text-decoration")[0].childNodes[0].nodeValue) + ";";
    textStyle = textStyle + "color:" + trim(cfgXML.getElementsByTagName("color")[0].childNodes[0].nodeValue);// + ";padding:1px 1px 1px 1px";
    try {
        this.textStr = (cfgXML.getElementsByTagName("text")[0].childNodes[0].nodeValue);
    } 
    catch (err) {
        this.textStr = "";
    }
    this.textStr = this.textStr.replace(/\&\&/g, "_*_");
    this.textStr = this.textStr.replace(/\&/g, "");
    this.textStr = this.textStr.replace(/_\*_/g, "&");
    // this.textStr =this.textStr.replace(/ /g, "&nbsp;");
    /*
     this.textStr = this.textStr.replace(/( {2,})/g, function(name, variableName){
     return name.replace(/ /g, "&nbsp;");
     });
     */
    this.p = this.text.createChild({
        tag: "div",
        style: "position:absolute;" + textStyle,
        html: replaceVariableNameWithValue(this.textStr)
    });
    this.visible = true;
}

TextClass.prototype.toFront = function(){
    this.content.setStyle("z-index", 80);
}

TextClass.prototype.setFx = function(cfgXML){
    this.fxEffect = 0;
    try {
        this.fxEffect = parseInt(trim(cfgXML.getElementsByTagName("FxEffect")[0].childNodes[0].nodeValue));
        this.fxDuration = parseInt(trim(cfgXML.getElementsByTagName("FxDuration")[0].childNodes[0].nodeValue)) / 1000;
        return setFxToElement(this, this.fxEffect, this.fxDuration);
    } 
    catch (err) {
        return 0;
    }
}
TextClass.prototype.fixPng = function(){
    var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
    var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
    if (Ext.isIE && (ie55 || ie6) && (this.imageSrc.indexOf(".png") >= 0)) {
        this.image.setStyle("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + Author.resourcePath + this.imageSrc + "',sizingMethod='scale')");
        this.image.dom.src = "lib/images/blank.gif";
    }
}
TextClass.prototype.change = function(cfgXML){
    Author.current.currentList.item(this.changeID).changeByID = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.setProperties(cfgXML);
    this.addToBackground = Author.current.currentList.item(this.changeID).addToBackground;
    if (this.addToBackground) {
        this.addToBackgroundAtElementPosition = Author.current.currentList.item(this.changeID).addToBackgroundAtElementPosition;
        this.orginalListID = Author.current.currentListXML.attributes[1].nodeValue;
        Author.backgroundList.list.add(this.id, this);
    }
    this.setFx(cfgXML); //1.2 seconds
    // alert("changed text");
    return 0;
}
TextClass.prototype.setProperties = function(cfgXML){
    this.top = parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue));
    this.left = parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue));
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue));
    this.borderWidth = parseInt(trim(cfgXML.getElementsByTagName("borderWidth")[0].childNodes[0].nodeValue));
    this.content.setStyle("border-width", "0px");
    // this.content.setStyle("border-color", trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue));
    // this.content.setStyle("border-style", trim(cfgXML.getElementsByTagName("borderStyle")[0].childNodes[0].nodeValue));
    this.setTop(this.top);
    this.setLeft(this.left);
    this.setWidth(this.width);
    this.setHeight(this.height);
    try {
        this.text.applyStyles("position: absolute; width: " + (this.width - this.borderWidth * 2) + "px; height: " + (this.height - this.borderWidth * 2) + "px");
    } 
    catch (err) {
    }
    try {
        this.setTextPosition(parseInt(trim(cfgXML.getElementsByTagName("textPosition")[0].childNodes[0].nodeValue)));
        if (this.imageSrc != "" && this.imageVisible == "true") 
            this.setImagePosition(parseInt(trim(cfgXML.getElementsByTagName("pictureAlign")[0].childNodes[0].nodeValue)));
    } 
    catch (err) {
        alert("TextClass:" + err);
    }
    
    try {
        this.font3d = parseInt(trim(cfgXML.getElementsByTagName("font3d")[0].childNodes[0].nodeValue));
        this.f3dSize = parseInt(trim(cfgXML.getElementsByTagName("fontBlockSize")[0].childNodes[0].nodeValue));
        
        switch (this.font3d) {
            case 0:
                break;
            default:
                this.p.setStyle("filter", "Dropshadow(offx=1,offy=0,color=black)Dropshadow(offx=0,offy=1,color=black)Dropshadow(offx=0,offy=-1,color=black) Dropshadow(offx=-1,offy=0,color=black)");
                break;
        }
    } 
    catch (err) {
        alert("Error in draw text edge at LINE 951\n" + err.description);
    }
    
    this.setBackground(cfgXML);
}
TextClass.prototype.backgroundFadein = function(duration){
    this.bg.attr({
        opacity: 0
    })
    this.bg.animate({
        opacity: 1
    }, duration);
}
TextClass.prototype.setBackground = function(cfgXML){
    var backStyle = parseInt(trim(cfgXML.getElementsByTagName("backStyle")[0].childNodes[0].nodeValue));
    var shape = parseInt(trim(cfgXML.getElementsByTagName("shape")[0].childNodes[0].nodeValue));
    var bgColorStr = trim(cfgXML.getElementsByTagName("backgroundColor")[0].childNodes[0].nodeValue);
    var gradientType = parseInt(trim(cfgXML.getElementsByTagName("gradientType")[0].childNodes[0].nodeValue));
    var startColorStr = trim(cfgXML.getElementsByTagName("startColorStr")[0].childNodes[0].nodeValue);
    var endColorStr = trim(cfgXML.getElementsByTagName("endColorStr")[0].childNodes[0].nodeValue);
    var bgContainer = Raphael(this.content.dom, this.width, this.height);
    //  alert("backStyle: "+backStyle+"\nshape: "+shape+"\ngradientType: "+gradientType);
    //bgContainer.safari();
    switch (shape) {
        case 1://square
            var l = Math.min(this.width, this.height);
            this.bg = bgContainer.rect((this.width - l) / 2, (this.height - l) / 2, l - 1, l - 1, 0);
            break;
        case 2://Oval
            this.bg = bgContainer.ellipse((this.width) / 2, (this.height) / 2, (this.width) / 2 - 1, (this.height) / 2 - 1);
            break;
        case 3://circle
            var l = Math.min(this.width, this.height);
            this.bg = bgContainer.circle((this.width) / 2, (this.height) / 2, l / 2 - 1);
            break;
        case 4://Rounded Rect
            var r = Math.min(this.width, this.height) / 10;
            this.bg = bgContainer.rect(0, 0, this.width - 1, this.height - 1, r);
            break;
        case 5: //Rounded Square
            var l = Math.min(this.width, this.height);
            this.bg = bgContainer.rect((this.width - l) / 2, (this.height - l) / 2, l - 1, l - 1, l / 10);
            break;
        case 6://Octagon
            var l = Math.min(this.width, this.height) / 2;
            var cx = (this.width) / 2;
            var cy = (this.height) / 2;
            var pathStr = "M" + (cx + l * ccos(45 - 22.5)) + " " + (cy + l * ssin(45 - 22.5));
            pathStr += "L" + (cx + l * ccos(45 * 2 - 22.5)) + " " + (cy + l * ssin(45 * 2 - 22.5));
            pathStr += "L" + (cx + l * ccos(45 * 3 - 22.5)) + " " + (cy + l * ssin(45 * 3 - 22.5));
            pathStr += "L" + (cx + l * ccos(45 * 4 - 22.5)) + " " + (cy + l * ssin(45 * 4 - 22.5));
            pathStr += "L" + (cx + l * ccos(45 * 5 - 22.5)) + " " + (cy + l * ssin(45 * 5 - 22.5));
            pathStr += "L" + (cx + l * ccos(45 * 6 - 22.5)) + " " + (cy + l * ssin(45 * 6 - 22.5));
            pathStr += "L" + (cx + l * ccos(45 * 7 - 22.5)) + " " + (cy + l * ssin(45 * 7 - 22.5));
            pathStr += "L" + (cx + l * ccos(45 * 8 - 22.5)) + " " + (cy + l * ssin(45 * 8 - 22.5));
            pathStr += " Z";
            this.bg = bgContainer.path(pathStr);
            break;
        case 7://Star
            var l = Math.min(this.width, this.height) / 2;
            var r = l * 0.618 / 1.618;
            var cx = (this.width) / 2;
            var cy = (this.height) / 2;
            var pathStr = "M" + (cx) + " " + (cy - l);
            pathStr += "L" + (cx + r * ccos(-54)) + " " + (cy + r * ssin(-54));
            pathStr += "L" + (cx + l * ccos(72 * 1 - 90)) + " " + (cy + l * ssin(72 * 1 - 90));
            pathStr += "L" + (cx + r * ccos(72 * 1 - 54)) + " " + (cy + r * ssin(72 * 1 - 54));
            pathStr += "L" + (cx + l * ccos(72 * 2 - 90)) + " " + (cy + l * ssin(72 * 2 - 90));
            pathStr += "L" + (cx + r * ccos(72 * 2 - 54)) + " " + (cy + r * ssin(72 * 2 - 54));
            pathStr += "L" + (cx + l * ccos(72 * 3 - 90)) + " " + (cy + l * ssin(72 * 3 - 90));
            pathStr += "L" + (cx + r * ccos(72 * 3 - 54)) + " " + (cy + r * ssin(72 * 3 - 54));
            pathStr += "L" + (cx + l * ccos(72 * 4 - 90)) + " " + (cy + l * ssin(72 * 4 - 90));
            pathStr += "L" + (cx + r * ccos(72 * 4 - 54)) + " " + (cy + r * ssin(72 * 4 - 54));
            pathStr += " Z";
            this.bg = bgContainer.path(pathStr);
            break;
        case 8://Equilateral Trangle
            var l = Math.min(this.width, this.height) / 2;
            var ll = 1.732 / 2 * l;
            var cx = (this.width) / 2;
            var cy = (this.height) / 2;
            var pathStr = "M" + (cx) + " " + (cy - l);
            pathStr += "L" + (cx - ll) + " " + (cy + l / 2);
            pathStr += "L" + (cx + ll) + " " + (cy + l / 2);
            pathStr += " Z";
            this.bg = bgContainer.path(pathStr);
            break;
        case 9://Triangle-Right
            this.bg = bgContainer.path("M0 0L" + (this.width - 1) + " " + this.height / 2 + "L0 " + this.height + " Z");
            break;
        case 10://Triangle-Up
            this.bg = bgContainer.path("M" + (this.width) / 2 + " 0L" + (this.width - 1) + " " + (this.height - 1) + "L0 " + (this.height - 1) + " Z");
            break;
        case 11://Triangle-Left
            this.bg = bgContainer.path("M0 " + (this.height) / 2 + "L" + (this.width - 1) + " 0L" + (this.width - 1) + " " + (this.height - 1) + " Z");
            break;
        case 12://Triangle-Down
            this.bg = bgContainer.path("M0 0L" + (this.width - 1) + " 0L" + (this.width / 2) + " " + (this.height - 1) + " Z");
            break;
        case 13://Diamond
            var l = Math.min(this.width, this.height) / 2;
            var cx = (this.width) / 2;
            var cy = (this.height) / 2;
            this.bg = bgContainer.path("M" + cx + " " + (cy - l) + "L" + (cx + l) + " " + (cy) + "L" + (cx) + " " + (cy + l) + "L" + (cx - l) + " " + (cy) + " Z");
            break;
        case 14://Pentagon
            var l = Math.min(this.width, this.height) / 2;
            var cx = (this.width) / 2;
            var cy = (this.height) / 2;
            var pathStr = "M" + (cx) + " " + (cy - l);
            pathStr += "L" + (cx + l * ccos(72 - 90)) + " " + (cy + l * ssin(72 - 90));
            pathStr += "L" + (cx + l * ccos(72 * 2 - 90)) + " " + (cy + l * ssin(72 * 2 - 90));
            pathStr += "L" + (cx + l * ccos(72 * 3 - 90)) + " " + (cy + l * ssin(72 * 3 - 90));
            pathStr += "L" + (cx + l * ccos(72 * 4 - 90)) + " " + (cy + l * ssin(72 * 4 - 90));
            pathStr += " Z";
            this.bg = bgContainer.path(pathStr);
            break;
        case 15://Hexagon
            var l = Math.min(this.width, this.height) / 2;
            var ll = 1.732 / 2 * l;
            var cx = (this.width) / 2;
            var cy = (this.height) / 2;
            var pathStr = "M" + (cx - l) + " " + cy;
            pathStr += "L" + (cx - l / 2) + " " + (cy - ll);
            pathStr += "L" + (cx + l / 2) + " " + (cy - ll);
            pathStr += "L" + (cx + l) + " " + (cy);
            pathStr += "L" + (cx + l / 2) + " " + (cy + ll);
            pathStr += "L" + (cx - l / 2) + " " + (cy + ll);
            pathStr += " Z";
            this.bg = bgContainer.path(pathStr);
            break;
        default://Rect
            this.bg = bgContainer.rect(0, 0, this.width - 1, this.height - 1, 0);
            break;
    }
    this.bg.attr({
        stroke: trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue),
        "stroke-width": this.borderWidth
    })
    switch (backStyle) {
        case 1:
        case 2:
            this.bg.attr({
                "fill": bgColorStr
            })
            if (backStyle == 2) {
                this.bg.attr({
                    opacity: .5
                })
            }
            break;
        case 3: //Gradient
        case 4:
            switch (gradientType) {
                case 1: // Right to Left
                    this.bg.attr({
                        gradient: "180-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 2: // Top to bottom
                    this.bg.attr({
                        gradient: "270-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 3: // Bottom to Top
                    this.bg.attr({
                        gradient: "90-" + startColorStr + "-" + endColorStr
                    })
                    break;
                    
                case 6: // tl-br
                    this.bg.attr({
                        gradient: "315-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 7: // br-tl
                    this.bg.attr({
                        gradient: "135-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 8: //tr-bl
                    this.bg.attr({
                        gradient: "225-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 9: //bl-tr
                    this.bg.attr({
                        gradient: "45-" + startColorStr + "-" + endColorStr
                    })
                    break;
                case 10: //tl br c
                    this.bg.attr({
                        gradient: "315-" + startColorStr + "-" + endColorStr + ":50" + "-" + startColorStr
                    })
                    break;
                case 11: //tl br c
                    this.bg.attr({
                        gradient: "315-" + endColorStr + "-" + startColorStr + ":50" + "-" + endColorStr
                    })
                    break;
                case 12: //tl br c
                    this.bg.attr({
                        gradient: "225-" + startColorStr + "-" + endColorStr + ":50" + "-" + startColorStr
                    })
                    break;
                case 13: //tl br c
                    this.bg.attr({
                        gradient: "225-" + endColorStr + "-" + startColorStr + ":50" + "-" + endColorStr
                    })
                    break;
                case 16: //tl br c
                    this.bg.attr({
                        gradient: "0-" + startColorStr + "-" + endColorStr + ":50" + "-" + startColorStr
                    })
                    break;
                case 17: //tl br c
                    this.bg.attr({
                        gradient: "0-" + endColorStr + "-" + startColorStr + ":50" + "-" + endColorStr
                    })
                    break;
                case 18: //tl br c
                    this.bg.attr({
                        gradient: "90-" + startColorStr + "-" + endColorStr + ":50" + "-" + startColorStr
                    })
                    break;
                case 19: //tl br c
                    this.bg.attr({
                        gradient: "90-" + endColorStr + "-" + startColorStr + ":50" + "-" + endColorStr
                    })
                    break;
                default:
                    this.bg.attr({
                        gradient: "0-" + startColorStr + "-" + endColorStr
                    })
                    break;
            }
            if (backStyle == 4) {
                this.bg.attr({
                    opacity: .5
                })
            }
            break;
        default:
    }
    //alert("borderColor: " + trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue) + "\nWidth: " + this.borderWidth);

    // this.content.setStyle("border-width", this.borderWidth + "px");
    // this.content.setStyle("border-color", trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue));
    // this.content.setStyle("border-style", trim(cfgXML.getElementsByTagName("borderStyle")[0].childNodes[0].nodeValue));
}
TextClass.prototype.setTextPosition = function(index){
    //start tochange..
    switch (index) {
        case 0: //left
            this.text.setLeft(this.textX);
            this.text.setTop(this.textY);
            //this.text.setLeft(0);
            //this.text.setTop(0);
            this.p.setStyle("text-align", "left");
            this.text.setWidth(this.content.getWidth() - (this.text.getLeft() - this.content.getLeft()));
            this.text.setHeight(this.content.getHeight() - (this.text.getTop() - this.content.getTop()));
            this.p.setWidth(this.text.getWidth() - (this.text.getLeft() - this.content.getLeft() - this.textX));
            this.p.setTop(0);
            this.p.setLeft(0);
            break;
        case 1:
            this.text.setLeft(this.textX);
            this.text.setTop(this.textY);
            this.p.setStyle("text-align", "left");
            this.text.setWidth(this.content.getWidth() - (this.text.getLeft() - this.content.getLeft()));
            this.text.setHeight(this.content.getHeight() - (this.text.getTop() - this.content.getTop()));
            this.p.setWidth(this.text.getWidth() - (this.text.getLeft() - this.content.getLeft() - this.textX));
            this.p.setTop((this.text.getHeight() - this.p.getHeight()) / 2);
            this.p.setLeft(0);
            break;
        case 2:
            this.text.setLeft(this.textX);
            this.text.setTop(this.textY);
            this.p.setStyle("text-align", "left");
            this.text.setWidth(this.content.getWidth() - (this.text.getLeft() - this.content.getLeft()));
            this.text.setHeight(this.content.getHeight() - (this.text.getTop() - this.content.getTop()));
            this.p.setWidth(this.text.getWidth() - (this.text.getLeft() - this.content.getLeft() - this.textX));
            this.p.setTop((this.text.getHeight() - this.p.getHeight()));
            this.p.setLeft(0);
            break;
        case 3: //right
            this.text.setLeft(this.textX);
            this.text.setTop(this.textY);
            //this.text.setLeft(0);
            // this.text.setTop(0);
            this.p.setStyle("text-align", "right");
            
            this.text.setWidth(this.content.getWidth() - (this.text.getLeft() - this.content.getLeft()));
            this.text.setHeight(this.content.getHeight() - (this.text.getTop() - this.content.getTop()));
            this.p.setWidth(this.text.getWidth() - (this.text.getLeft() - this.content.getLeft() - this.textX));
            this.p.setTop(0);
            // this.p.setLeft(this.text.getWidth() - this.p.getWidth());
            this.p.setLeft(0);
            break;
        case 4:
            this.text.setLeft(this.textX);
            this.text.setTop(this.textY);
            this.p.setStyle("text-align", "right");
            this.text.setWidth(this.content.getWidth() - (this.text.getLeft() - this.content.getLeft()));
            this.text.setHeight(this.content.getHeight() - (this.text.getTop() - this.content.getTop()));
            this.p.setWidth(this.text.getWidth() - (this.text.getLeft() - this.content.getLeft() - this.textX));
            this.p.setTop((this.text.getHeight() - this.p.getHeight()) / 2);
            // this.p.setLeft(this.text.getWidth() - this.p.getWidth());
            this.p.setLeft(0);
            break;
        case 5:
            this.text.setLeft(this.textX);
            this.text.setTop(this.textY);
            this.p.setStyle("text-align", "right");
            this.text.setWidth(this.content.getWidth() - (this.text.getLeft() - this.content.getLeft()));
            this.text.setHeight(this.content.getHeight() - (this.text.getTop() - this.content.getTop()));
            this.p.setWidth(this.text.getWidth() - (this.text.getLeft() - this.content.getLeft() - this.textX));
            this.p.setTop((this.text.getHeight() - this.p.getHeight()));
            // this.p.setLeft(this.text.getWidth() - this.p.getWidth());
            this.p.setLeft(0);
            break;
        case 6://center
            this.text.setLeft(this.textX);
            this.text.setTop(this.textY);
            // this.text.setLeft(0);
            // this.text.setTop(0);
            this.p.setStyle("text-align", "center");
            this.text.setWidth(this.content.getWidth() - (this.text.getLeft() - this.content.getLeft()));
            this.text.setHeight(this.content.getHeight() - (this.text.getTop() - this.content.getTop()));
            this.p.setWidth(this.text.getWidth() - (this.text.getLeft() - this.content.getLeft() - this.textX));
            this.p.setTop(0);
            //this.p.setLeft((this.text.getWidth() - this.p.getWidth()) / 2);
            this.p.setLeft(0);
            
            break;
        case 7:
            this.text.setLeft(this.textX);
            this.text.setTop(this.textY);
            this.p.setStyle("text-align", "center");
            this.text.setWidth(this.content.getWidth() - (this.text.getLeft() - this.content.getLeft()));
            this.text.setHeight(this.content.getHeight() - (this.text.getTop() - this.content.getTop()));
            this.p.setWidth(this.text.getWidth() - (this.text.getLeft() - this.content.getLeft() - this.textX));
            this.p.setTop((this.text.getHeight() - this.p.getHeight()) / 2);
            // this.p.setLeft((this.text.getWidth() - this.p.getWidth()) / 2);
            this.p.setLeft(0);
            break;
        case 8:
            this.text.setLeft(this.textX);
            this.text.setTop(this.textY);
            this.p.setStyle("text-align", "center");
            
            this.text.setWidth(this.content.getWidth() - (this.text.getLeft() - this.content.getLeft()));
            this.text.setHeight(this.content.getHeight() - (this.text.getTop() - this.content.getTop()));
            this.p.setWidth(this.text.getWidth() - (this.text.getLeft() - this.content.getLeft() - this.textX));
            this.p.setTop((this.text.getHeight() - this.p.getHeight()));
            //this.p.setLeft((this.text.getWidth() - this.p.getWidth()) / 2);
            this.p.setLeft(0);
            break;
    }
    /*
     this.p.setStyle("text-align", "left");
     this.p.setHeight(this.p.getHeight());
     
     this.text.setWidth(this.content.getWidth() - (this.text.getLeft() - this.content.getLeft()));
     this.p.setWidth(this.text.getWidth() - (this.text.getLeft() - this.content.getLeft()));
     */
    //  this.text.applyStyles("width:100%;height:100%");
    //this.p.applyStyles("width:100%;height:100%");
}
TextClass.prototype.setImagePosition = function(index){
    var imageWidth = this.image.getWidth();
    var imageHeight = this.image.getHeight();
    var bgWidth = this.content.getWidth();
    var bgHeight = this.content.getHeight();
    switch (index) {
        case 0:
            this.image.setLeft(this.imageX);
            this.image.setTop(this.imageY);
            break;
        case 1:
            this.image.setLeft(this.imageX);
            this.image.setTop(this.imageY + (bgHeight - imageHeight) / 2);
            break;
        case 2:
            this.image.setLeft(this.imageX);
            this.image.setTop(this.imageY + (bgHeight - imageHeight));
            break;
        case 3:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth));
            this.image.setTop(this.imageY);
            break;
        case 4:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth));
            this.image.setTop(this.imageY + (bgHeight - imageHeight) / 2);
            break;
        case 5:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth));
            this.image.setTop(this.imageY + (bgHeight - imageHeight));
            break;
        case 6:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth) / 2);
            this.image.setTop(this.imageY);
            break;
            break;
        case 7:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth) / 2);
            this.image.setTop(this.imageY + (bgHeight - imageHeight) / 2);
            break;
        case 8:
            this.image.setLeft(this.imageX + (bgWidth - imageWidth) / 2);
            this.image.setTop(this.imageY + (bgHeight - imageHeight));
            break;
    }
}
TextClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    if (this.changeAction == "true") {
        Author.current.currentList.item(this.changeID).setVisible(false);
        return this.change(cfgXML);
    }
    this.setProperties(cfgXML);
    this.addToBackground = (trim(cfgXML.getElementsByTagName("addToBackground")[0].childNodes[0].nodeValue).toLowerCase() == "true");
    
    if (this.addToBackground) {
    
        this.orginalListID = Author.current.currentListXML.attributes[1].nodeValue;
        Author.backgroundList.list.add(this.id, this);
        
        this.addToBackgroundAtElementPosition = Author.current.currentElementPosition;
    }
    this.setFx(cfgXML); //1.2 seconds
    return 0;
}

TextClass.prototype.setText = function(textHTML){
    this.p.dom.innerText = replaceVariableNameWithValue(textHTML);
}
TextClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
TextClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
TextClass.prototype.setWidth = function(width){
    this.content.setWidth(width);
}
TextClass.prototype.setHeight = function(height){
    this.content.setHeight(height);
}
TextClass.prototype.setVisible = function(visible){
    this.visible = visible;
    if (this.changeByID != null) {
        Author.current.currentList.item(this.changeByID).setVisible(visible);
    }
    else {
        this.content.setVisible(visible);
    }
}


TextClass.prototype.setStyle = function(CSSStyle){
    this.content.applyStyles(CSSStyle);
}
TextClass.prototype.remove = function(){
    try {
        if (this.changeAction == "true") {
            Author.current.currentList.item(this.originalID).changeByID = null;
        }
        if (this.fxEffect != 0) 
            this.content.stopFx();
        this.content.remove();
    } 
    catch (err) {
    }
}
function ImageButtonClass(bgObject, cfgXML){
    this.addToForeground = false;
    this.changedByVisibleAction = false;
    this.isPrecedent = false;
    this.objectType = "IMAGEBUTTONOBJECT";
    this.buttonType = trim(cfgXML.getElementsByTagName("buttonType")[0].childNodes[0].nodeValue);
    this.name = trim(cfgXML.getElementsByTagName("name")[0].childNodes[0].nodeValue);
    this.value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
    this.top = parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue));
    this.left = parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue));
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue));
    this.toggleBtn = false;
    this.mouseOutImage = trim(cfgXML.getElementsByTagName("mouseOutImage")[0].childNodes[0].nodeValue).toLowerCase();
    try {
        this.mouseOverImage = trim(cfgXML.getElementsByTagName("mouseOverImage")[0].childNodes[0].nodeValue).toLowerCase();
    } 
    catch (err) {
        this.mouseOverImage = this.mouseOutImage;
    }
    this.type = "unknow";
    this.click = "unknow";
    try {
        this.click = trim(cfgXML.getElementsByTagName("click")[0].childNodes[0].nodeValue);
    } 
    catch (err) {
    }
    this.buttonType = parseInt(trim(cfgXML.getElementsByTagName("buttonClickType")[0].childNodes[0].nodeValue).toLowerCase());
    this.toggleBtn = (this.buttonType == 1);
    this.content = bgObject.createChild({
        tag: "div",
        style: "position:absolute;overflow:hidden"
    });
    var img = new Image();
    img.src = Author.resourcePath + eval(Ext.encode(this.mouseOutImage));
    img.src = Author.resourcePath + eval(Ext.encode(this.mouseOverImage));
    
    this.image = this.content.createChild({
        tag: "img",
        style: "position:absolute;",
        src: Author.resourcePath + eval(Ext.encode(this.mouseOutImage)),
        width: this.width,
        height: this.height,
        containerID: this.content.id
    });
    this.content.set({
        "imageID": this.image.id
    });
    
    this.hasMouseOverResponse = trim(cfgXML.getElementsByTagName("hasMouseOverResponse")[0].childNodes[0].nodeValue).toLowerCase();
    this.mouseOverResponseValue = trim(cfgXML.getElementsByTagName("mouseOverResponseValue")[0].childNodes[0].nodeValue);
    
    this.content.set({
    
        "containerID": this.content.id,
        "toggleBtn": this.toggleBtn,
        "toggled": false,
        "name": this.name.toLowerCase(),
        "value": this.value,
        "mouseOverResponse": this.hasMouseOverResponse,
        "mouseOverResponseValue": this.mouseOverResponseValue
    });
    
    this.visible = true;
}

ImageButtonClass.prototype.zorder = function(index){
    this.content.setStyle("z-index", index);
}
ImageButtonClass.prototype.checkPrecedence = function(){
    var listType = Author.current.currentListXML.attributes[0].nodeValue;
    if (listType == "INTERACTION") {
        Author.current.precedentObject = this.objectType;
        this.isPrecedent = true;
    }
}
ImageButtonClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.content.setStyle("cursor", "pointer");
    this.setTop(parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue)));
    this.setLeft(parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)));
    this.setWidth(parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue)));
    this.setHeight(parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue)));
    this.hide = trim(cfgXML.getElementsByTagName("hide")[0].childNodes[0].nodeValue).toLowerCase();
    try {
        this.addToForeground = trim(cfgXML.getElementsByTagName("addToForeground")[0].childNodes[0].nodeValue).toLowerCase() == "true";
    } 
    catch (err) {
        this.addToForeground = false;
    }
    this.setMouseDownEvent(function(e){
        e.stopEvent();
        var target = Ext.get(e.getTarget());
        var container = Ext.get(target.dom.containerID);
        if (container.dom.getAttribute("toggleBtn").toString() == true) {
            if (container.dom.getAttribute("toggled").toString() == true) {
                container.dom.setAttribute("toggled", false);
                try {
                    var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
                    if (elementType == "MULTIPLECHOICE") {
                        Author.answers.multipleChoice.removeKey(container.dom.getAttribute("value").toString());
                    }
                } 
                catch (err) {
                    alert("mouseDown::toggle=false::" + err);
                }
                try {
                    container.setStyle("color", trim(cfgXML.getElementsByTagName("mouseOutColor")[0].childNodes[0].nodeValue));
                } 
                catch (err) {
                }
                try {
                    var img = new Image();
                    img.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOutImage")[0].childNodes[0].nodeValue).toLowerCase()));
                    Ext.get(container.dom.getAttribute("imageID").toString()).dom.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOutImage")[0].childNodes[0].nodeValue).toLowerCase()));
                } 
                catch (err) {
                }
            }
            else {
                container.dom.setAttribute("toggled", true);
                try {
                    var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
                    Author.variables.get(variableName('ANSWER')).setValue("ANSWER");
                    if (elementType == "MULTIPLECHOICE") {
                        Author.answers.multipleChoice.add(container.dom.getAttribute("value").toUpperCase(), container.dom.getAttribute("toggled").toString());
                    }
                } 
                catch (err) {
                    alert("mouseDown::toggle=true::" + err);
                }
                try {
                    container.setStyle("color", trim(cfgXML.getElementsByTagName("mouseOverColor")[0].childNodes[0].nodeValue));
                } 
                catch (err) {
                }
                try {
                    var img = new Image();
                    img.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOverImage")[0].childNodes[0].nodeValue).toLowerCase()));
                    
                    Ext.get(container.dom.getAttribute("imageID")).dom.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOverImage")[0].childNodes[0].nodeValue).toLowerCase()));
                } 
                catch (err) {
                }
            }
        }
        
    });
    this.setMouseOverEvent(function(e){
        e.stopEvent();
        var target = Ext.get(e.getTarget());
        try {
            var container = Ext.get(target.dom.getAttribute("containerID").toString());
            if (container.dom.getAttribute("toggleBtn").toString() == "false") 
                Ext.get(container.dom.getAttribute("textID")).setStyle("color", trim(cfgXML.getElementsByTagName("mouseOverColor")[0].childNodes[0].nodeValue));
        } 
        catch (err) {
        }
        try {
            if (container.dom.getAttribute("toggleBtn").toString() == "false") {
                var img = new Image();
                img.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOverImage")[0].childNodes[0].nodeValue).toLowerCase()));
                
                Ext.get(container.dom.getAttribute("imageID")).dom.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOverImage")[0].childNodes[0].nodeValue).toLowerCase()));
            }
        } 
        catch (err) {
        }
        if (container.dom.getAttribute("mouseOverResponse").toString() == "true") {
        
            Author.variables.get(variableName('ANSWER')).setValue(container.dom.getAttribute("mouseOverResponseValue"));
            
            checkResponse();
        }
    });
    this.setMouseOutEvent(function(e){
        e.stopEvent();
        var target = Ext.get(e.getTarget());
        var container = Ext.get(target.dom.getAttribute("containerID"));
        try {
            if (container.dom.getAttribute("toggleBtn").toString() == "false") 
                Ext.get(container.dom.getAttribute("textID")).setStyle("color", trim(cfgXML.getElementsByTagName("mouseOutColor")[0].childNodes[0].nodeValue));
        } 
        catch (err) {
        }
        try {
            if (container.dom.getAttribute("toggleBtn").toString() == "false") {
                var img = new Image();
                img.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOutImage")[0].childNodes[0].nodeValue).toLowerCase()));
                Ext.get(container.dom.getAttribute("imageID")).dom.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOutImage")[0].childNodes[0].nodeValue).toLowerCase()));
            }
            
        } 
        catch (err) {
        }
    });
    if (this.click == "GOTOMENUOPTION") {
        this.setOnClickEvent(function(e){
            e.stopEvent();
            // alert("GOTOMENUOPTION Clicked");
            Author.current.currentNode = Author.lessonNodes.nodes.get(trim(cfgXML.getElementsByTagName("nextLessonNode")[0].childNodes[0].nodeValue));
            Author.current.currentElementXML = null;
            Author.current.currentElementType = "";
            Author.current.currentElementResponses.clear();
            Author.current.currentElementPosition = -1;
            Author.current.currentListPosition = 0;
            Author.response.clear();
            Author.current.randomOptionsCollection.clear();
            Author.current.currentElementResponses.clear();
            Author.clearBackgroundObjects = true;
            showLessonNode();
        })
    }
    if (this.click == "SKIP") {
        this.setOnClickEvent(function(e){
            e.stopEvent();
            Author.variables.get(variableName('SELECTEDVALUE')).setValue("SKIP");
            Author.variables.get(variableName('SELECTEDNAME')).setValue("SKIP");
            if (Author.pause != null && Author.pause.cancelType != 0) {
                Author.pause = null;
                pauseVideoes();
                window.clearTimeout(Author.actionTimer);
            }
            var listType = Author.current.currentListXML.attributes[0].nodeValue;
            if (listType == "INTRODUCTION") {
                var actions = Author.current.currentListXML.getElementsByTagName("action");
                Author.current.currentActionPosition = actions.length;
                showList();
                return;
            }
            else {
                if (Author.current.currentNode.type != "MENU") {
                    Author.current.currentElementXML = null;
                    Author.current.currentElementType = "";
                    Author.current.currentElementResponses.clear();
                    Author.current.currentElementPosition++;
                    Author.response.clear();
                    showLessonNode();
                    return;
                }
            }
        })
    }
    if (this.click == "TOUPPERMENU") {
        this.setOnClickEvent(function(e){
            // if (Author.waitingMedia) 
            // return;
            e.stopEvent();
            // alert("TOUPPERMENU Clicked");
            Author.variables.get(variableName('SELECTEDVALUE')).setValue("TOUPPERMENU");
            Author.variables.get(variableName('SELECTEDNAME')).setValue("TOUPPERMENU");
            while (Author.current.currentBgStack.getCount() > 0) {
                var bgObject = Author.current.currentBgStack.last();
                Author.current.currentBgStack.remove(bgObject);
                if (Author.current.currentBgStack.getCount() == 0) {
                    Author.backgroundObject.setBg(bgObject);
                }
            }
            //  Author.backgroundObject.setOriginal();
            
            Author.current.currentNode = Author.lessonNodes.nodes.get(getParentNode());
            Author.current.currentElementXML = null;
            Author.current.currentElementType = "";
            Author.current.currentElementResponses.clear();
            Author.current.currentElementPosition = -1;
            Author.current.currentListPosition = 0;
            Author.response.clear();
            Author.current.currentElementResponses.clear();
            Author.clearBackgroundObjects = true;
            Author.current.randomOptionsCollection.clear();
            Author.backToMenu = true;
            showLessonNode();
        })
    }
    if (this.click == "TOMAINMENU") {
        this.setOnClickEvent(function(e){
            //   if (Author.waitingMedia) 
            //  return;
            e.stopEvent();
            //  alert("TOMAINMENU Clicked");
            Author.variables.get(variableName('SELECTEDVALUE')).setValue("TOMAINMENU");
            Author.variables.get(variableName('SELECTEDNAME')).setValue("TOMAINMENU");
            Author.backgroundObject.setOriginal();
            do {
                Author.current.currentNode = Author.lessonNodes.nodes.get(getParentNode());
            }
            while (Author.current.currentNode.parent != 0)
            Author.current.currentElementXML = null;
            Author.current.currentElementType = "";
            Author.current.currentElementResponses.clear();
            Author.current.currentElementPosition = -1;
            Author.current.currentListPosition = 0;
            Author.response.clear();
            Author.current.currentElementResponses.clear();
            Author.clearBackgroundObjects = true;
            Author.backToMenu = true;
            Author.current.randomOptionsCollection.clear();
            showLessonNode();
        })
    }
    if (this.click == "NEXT") {
        this.setOnClickEvent(function(e){
            if (Author.lessonFinished) {
                return;
            }
            // if (Author.waitingMedia) 
            //  return;
            e.stopEvent();
            Author.variables.get(variableName('SELECTEDVALUE')).setValue("NEXT");
            Author.variables.get(variableName('SELECTEDNAME')).setValue("NEXT");
            //  alert("Next Clicked");
            if (Author.pause != null && Author.pause.cancelType != 0) {
                Author.pause = null;
                pauseVideoes();
                window.clearTimeout(Author.actionTimer);
                showList();
            }
            else 
                if (Author.responseEnd && Author.lessonFlow == "continue") {
                    Author.responseEnd = false;
                    showLessonNode();
                }
                else 
                    if (Author.current.currentListXML.attributes[0].nodeValue == "INTERACTION" || Author.lessonFlow == "repeat") {
                        makeAnswerVariable();
                        if (Author.variables.get(variableName('ANSWER')).getValue() == null || Author.variables.get(variableName('ANSWER')).getValue() == "") 
                            Author.variables.get(variableName('ANSWER')).setValue("NEXT");
                        checkResponse();
                    }
        })
    }
    if (this.click == "BACK") {
        this.setOnClickEvent(function(e){
            // if (Author.waitingMedia) 
            //  return;
            e.stopEvent();
            //  alert("BACK Clicked");
            Author.variables.get(variableName('SELECTEDVALUE')).setValue("BACK");
            Author.variables.get(variableName('SELECTEDNAME')).setValue("BACK");
            if (Author.pause != null && Author.pause.cancelType != 0) {
                Author.pause = null;
                window.clearTimeout(Author.actionTimer);
            }
            if (Author.current.currentElementXML != null) {
                Author.current.currentElementPosition -= 1
                Author.current.currentElementXML = null;
                if (Author.current.currentElementPosition < 0) {
                    Author.current.currentNode = Author.lessonNodes.nodes.get(getParentNode());
                    while (Author.current.currentBgStack.getCount() > 0) {
                        var bgObject = Author.current.currentBgStack.last();
                        Author.current.currentBgStack.remove(bgObject);
                        if (Author.current.currentBgStack.getCount() == 0) {
                            Author.backgroundObject.setBg(bgObject);
                        }
                    }
                    // Author.backgroundObject.setOriginal();
                    Author.current.currentElementXML = null;
                    Author.current.currentElementType = "";
                    Author.current.currentElementResponses.clear();
                    Author.current.currentElementPosition = -1;
                    Author.current.currentListPosition = 0;
                    Author.clearBackgroundObjects = true;
                    Author.backToMenu = true;
                    Author.current.randomOptionsCollection.clear();
                }
            }
            else {
                Author.current.currentListPosition -= 1;
                if (Author.current.currentListPosition < 0) {
                    if (getParentNode() == 0) 
                        return;
                    Author.current.currentNode = Author.lessonNodes.nodes.get(getParentNode());
                    Author.current.currentListPosition = 0;
                    Author.clearBackgroundObjects = true;
                    Author.current.currentElementResponses.clear();
                }
            }
            Author.responseEnd = true;
            Author.inResponse = false;
            Author.response.clear();
            
            showLessonNode();
            return;
        })
    }
    if (this.click == "EXITLESSON") {
        this.setOnClickEvent(function(e){
            e.stopEvent();
            if (Author.pause != null && Author.pause.cancelType != 0) {
                Author.pause = null;
                window.clearTimeout(Author.actionTimer);
            }
            
            if (confirm("Do you want to exit?", "Exit this AUTHOR eLearning?")) {
                endLesson();
            }
        })
    }
    if (this.click == "CHECKRESPONSE" && this.toggleBtn == false) {
        this.setOnClickEvent(function(e){
            //  if (Author.waitingMedia) 
            //   return;
            if (Author.inResponse || Author.lessonFinished) 
                return;
            e.stopEvent();
            var target = Ext.get(e.getTarget());
            var container = Ext.get(target.dom.getAttribute("containerID"));
            var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
            
            
            Author.variables.get(variableName('SELECTEDVALUE')).setValue(value);
            Author.variables.get(variableName('SELECTEDNAME')).setValue(container.dom.getAttribute("name"));
            try {
                var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
                if (elementType == "MULTIPLECHOICE") {
                    //   var target = Ext.get(e.getTarget());
                    //  var container = Ext.get(target.dom.containerID);
                    //  var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
                    
                    Author.variables.get(variableName('ANSWER')).setValue(value);
                    var regex = /^[A|B|C|D|E|F|G|H]{1}$/;
                    var answer = container.dom.getAttribute("value").toUpperCase();
                    if (regex.test(answer) == true) {
                        Author.answers.multipleChoice.add(container.dom.getAttribute("value").toUpperCase(), container.dom.getAttribute("toggled"));
                    }
                    checkResponse();
                }
                else 
                    if (elementType == "YESNO") {
                        //  var target = Ext.get(e.getTarget());
                        //   var container = Ext.get(target.dom.containerID);
                        //  var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
                        Author.variables.get(variableName('ANSWER')).setValue(value);
                        Author.answers.yesNo = value.toLowerCase();
                        checkResponse();
                    }
                    else 
                        if (elementType == "TRUEFALSE") {
                            Author.variables.get(variableName('ANSWER')).setValue(value);
                            Author.answers.trueFalse = value.toLowerCase();
                            checkResponse();
                        }
                        else {
                            // var variable = trim(cfgXML.getElementsByTagName("variable")[0].childNodes[0].nodeValue);
                            //  var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
                            Author.variables.get(variableName('ANSWER')).setValue(value);
                            checkResponse();
                        }
                return;
            } 
            catch (err) {
                alert("mouseDown::toggle=true::" + err);
            }
            
            var variable = trim(cfgXML.getElementsByTagName("variable")[0].childNodes[0].nodeValue);
            var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
            Author.variables.get(variableName('ANSWER')).setValue(value);
            checkResponse();
            return;
        })
    }
    if (this.addToForeground == false && this.toggleBtn) 
        this.checkPrecedence();
    if (this.addToForeground == true) {
        this.setVisible(this.hide == "false");
        Author.foregroundList.list.add(this.id, this);
        this.addToForegroundAtElementPosition = Author.current.currentElementPosition;
        this.zorder(100);
    }
    this.key1 = "none";
    this.key2 = "none";
    try {
        this.key1 = trim(cfgXML.getElementsByTagName("key1")[0].childNodes[0].nodeValue);
        this.key2 = trim(cfgXML.getElementsByTagName("key2")[0].childNodes[0].nodeValue);
        if (this.key1 != "none") 
            Author.actionKeyMap.add(this.key1, this);
        if (this.key2 != "none") 
            Author.actionKeyMap.add(this.key2, this);
    } 
    catch (err) {
    }
    return 0;
}
ImageButtonClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
ImageButtonClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
ImageButtonClass.prototype.setWidth = function(width){
    this.width = width;
    this.content.setWidth(width);
}
ImageButtonClass.prototype.setHeight = function(height){
    this.height = height;
    this.content.setHeight(height);
}
ImageButtonClass.prototype.setVisible = function(visible){
    this.visible = visible;
    this.content.setVisible(visible);
    
}
ImageButtonClass.prototype.setStyle = function(CSSStyle){
    this.content.applyStyles(CSSStyle);
}
ImageButtonClass.prototype.setMouseDownEvent = function(mouseDownEventHandler){
    this.content.on("mousedown", eval(mouseDownEventHandler));
}
ImageButtonClass.prototype.setMouseUpEvent = function(mouseUpEventHandler){
    this.content.on("mouseup", eval(mouseUpEventHandler));
}
ImageButtonClass.prototype.setMouseOverEvent = function(mouseOverEventHandler){
    this.content.on("mouseover", eval(mouseOverEventHandler));
}
ImageButtonClass.prototype.setMouseOutEvent = function(mouseOutEventHandler){
    this.content.on("mouseout", eval(mouseOutEventHandler));
}
ImageButtonClass.prototype.setOnClickEvent = function(onClickEventHandler){
    this.content.on("click", eval(onClickEventHandler));
}
ImageButtonClass.prototype.remove = function(){
    if (this.key1 != "none") 
        Author.actionKeyMap.removeKey(this.key1);
    if (this.key2 != "none") 
        Author.actionKeyMap.removeKey(this.key2);
    this.content.remove();
}
/**
 * CustomButtonClass
 * @param {Object} bgObject
 */
function CustomButtonClass(bgObject, cfgXML){

    this.changedByVisibleAction = false;
    this.isPrecedent = false;
    this.textPosition = trim(cfgXML.getElementsByTagName("textPosition")[0].childNodes[0].nodeValue);
    this.objectType = "CUSTOMBUTTONOBJECT";
    this.buttonType = trim(cfgXML.getElementsByTagName("buttonType")[0].childNodes[0].nodeValue);
    this.name = trim(cfgXML.getElementsByTagName("name")[0].childNodes[0].nodeValue);
    this.value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
    this.borderWidth = 0;
    this.top = parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue));
    this.left = parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue));
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue));
    this.toggleBtn = false;
    this.cycle = trim(cfgXML.getElementsByTagName("cycle")[0].childNodes[0].nodeValue);
    this.textX = trim(cfgXML.getElementsByTagName("textX")[0].childNodes[0].nodeValue);
    this.textY = trim(cfgXML.getElementsByTagName("textY")[0].childNodes[0].nodeValue);
    this.responseToClick = trim(cfgXML.getElementsByTagName("responseToClick")[0].childNodes[0].nodeValue).toLowerCase() == "true";
    try {
        this.tickColor = trim(cfgXML.getElementsByTagName("tickColor")[0].childNodes[0].nodeValue).toLowerCase();
        
        if (this.tickColor == "none") {
            this.tickColor = trim(cfgXML.getElementsByTagName("mouseOutColor")[0].childNodes[0].nodeValue);
        }
    } 
    catch (err) {
    
        this.tickColor = trim(cfgXML.getElementsByTagName("mouseOutColor")[0].childNodes[0].nodeValue);
    }
    
    
    this.pictureDrawMode = trim(cfgXML.getElementsByTagName("pictureDrawMode")[0].childNodes[0].nodeValue);
    this.pictureX = trim(cfgXML.getElementsByTagName("pictureX")[0].childNodes[0].nodeValue);
    this.pictureY = trim(cfgXML.getElementsByTagName("pictureY")[0].childNodes[0].nodeValue);
    
    this.textMoveX = trim(cfgXML.getElementsByTagName("textMoveX")[0].childNodes[0].nodeValue);
    this.textMoveY = trim(cfgXML.getElementsByTagName("textMoveY")[0].childNodes[0].nodeValue);
    this.imageMoveX = trim(cfgXML.getElementsByTagName("imageMoveX")[0].childNodes[0].nodeValue);
    this.imageMoveY = trim(cfgXML.getElementsByTagName("imageMoveY")[0].childNodes[0].nodeValue);
    
    this.framesCount = cfgXML.getElementsByTagName("frames")[0].childNodes.length;
    this.frames = new Array(this.framesCount);
    this.iWidthes = new Array(this.framesCount);
    this.iHeights = new Array(this.framesCount);
    for (var i = 0; i < this.framesCount; i++) {
        this.frames[i] = trim(cfgXML.getElementsByTagName("frames")[0].childNodes[i].childNodes[0].nodeValue).toLowerCase();
        this.iWidthes[i] = parseInt(trim(cfgXML.getElementsByTagName("frames")[0].childNodes[i].attributes[0].nodeValue).toLowerCase());
        this.iHeights[i] = parseInt(trim(cfgXML.getElementsByTagName("frames")[0].childNodes[i].attributes[1].nodeValue).toLowerCase());
    }
    
    this.type = "unknow";
    this.click = "unknow";
    try {
        this.click = trim(cfgXML.getElementsByTagName("click")[0].childNodes[0].nodeValue);
    } 
    catch (err) {
    }
    
    this.nextOptionID = null;
    this.theOptionFinished = false;
    if (this.click == "GOTOMENUOPTION") {
    
        try {
            this.nextOptionID = parseInt(trim(cfgXML.getElementsByTagName("nextLessonNode")[0].childNodes[0].nodeValue));
            var theOption = Author.lessonNodes.nodes.get(this.nextOptionID);
            if (theOption.children.getCount() == 0) {
                this.theOptionFinished = theOption.finished;
            }
            else {
                this.theOptionFinished = true;
                for (var index = 0; index < theOption.children.getCount(); index++) {
                    this.theOptionFinished &= theOption.children.itemAt(index).finished;
                }
                theOption.finished = (this.theOptionFinished == 1);
                this.theOptionFinished = (this.theOptionFinished == 1);
                //alert( theOption.finished);
            }
        } 
        catch (err) {
        }
    }
    //alert(this.name + ", "+ this.theOptionFinished);
    if (this.cycle == "6" || this.cycle == "7") {
        this.toggleBtn = true;
    }
    this.content = bgObject.createChild({
        tag: "div",
        style: "position:absolute;overflow:hidden;"
    });
    // alert(this.pictureDrawMode+"\n"+this.width+" X "+this.height);
    if (this.framesCount > 0) {
        var img = new Image();
        img.src = Author.resourcePath + this.frames[0];
        var imageName = Author.resourcePath + this.frames[0];
        
        var menuTickImage = "none";
        try {
            menuTickImage = trim(cfgXML.getElementsByTagName("menuTickImage")[0].childNodes[0].nodeValue).toLowerCase();
        } 
        catch (err) {
        }
        if (this.theOptionFinished && menuTickImage != "none") {
            imageName = Author.resourcePath + menuTickImage;
        }
        
        this.image = this.content.createChild({
            tag: "img",
            style: "position:absolute;alt:''",
            width: (this.pictureDrawMode == "2") ? this.width : this.iWidthes[0],
            height: (this.pictureDrawMode == "2") ? this.height : this.iHeights[0],
            src: imageName,
            containerID: this.content.id
        });
        this.image.dom.src = imageName;
        if (this.pictureDrawMode == "2") 
            this.setImagePosition(this.width, this.height);
        else 
            this.setImagePosition(this.iWidthes[0], this.iHeights[0]);
        this.content.set({
            "imageID": this.image.id
        });
    }
    //  else {
    try {
        this.backColor = trim(cfgXML.getElementsByTagName("backColor")[0].childNodes[0].nodeValue);
        this.borderWidth = parseInt(trim(cfgXML.getElementsByTagName("borderWidth")[0].childNodes[0].nodeValue));
    } 
    catch (err) {
        this.backColor = "#ccc";
        this.borderWidth = 0;
    }
    this.content.setStyle("background-color", this.backColor);
    this.content.setStyle("border-width", this.borderWidth + "px");
    this.content.setStyle("border-color", this.backColor);
    this.content.setStyle("border-style", "outset");
    // }
    
    var x, y;
    var width = this.width;
    var height = this.height;
    var textStyle = "font-family:" + trim(cfgXML.getElementsByTagName("font-family")[0].childNodes[0].nodeValue) + ";";
    textStyle = textStyle + "font-size:" + trim(cfgXML.getElementsByTagName("font-size")[0].childNodes[0].nodeValue) + "pt;";
    textStyle = textStyle + "font-style:" + trim(cfgXML.getElementsByTagName("font-style")[0].childNodes[0].nodeValue) + ";";
    textStyle = textStyle + "font-weight:" + trim(cfgXML.getElementsByTagName("font-weight")[0].childNodes[0].nodeValue) + ";";
    textStyle = textStyle + "color:" + (this.theOptionFinished ? this.tickColor : trim(cfgXML.getElementsByTagName("mouseOutColor")[0].childNodes[0].nodeValue)) + ";";
    textStyle = textStyle + "text-align:" + "left" + ";";
    //  alert(textStyle);
    switch (this.textPosition) {
        case "left":
            width = this.width - this.iWidthes[0];
            height = this.height;
            x = 0;
            y = 0;
            break;
        case "right":
            width = this.width - this.iWidthes[0];
            height = this.height;
            x = this.iWidthes[0];
            y = 0;
            break;
        case "top":
            x = 0;
            y = 0;
            width = this.width;
            height = this.height - this.iHeights[0];
            break;
        case "down":
            y = this.iHeights[0];
            x = 0;
            width = this.width;
            height = this.height - this.iHeights[0];
            break;
        case "center":
            y = 0;
            x = 0;
            width = this.width;
            height = this.height;
            break;
    }
    width = width - this.borderWidth * 2;
    height = height - this.borderWidth * 2;
    this.text = this.content.createChild({
        tag: "div",
        style: "position:absolute;left:" + x + "px;top:" + y + "px;width:" + (width) + "px;height:" + (height) + "px;",
        containerID: this.content.id
    });
    
    try {
        this.textStr = (cfgXML.getElementsByTagName("text")[0].childNodes[0].nodeValue);
    } 
    catch (err) {
        this.textStr = "";
    }
    
    this.textStr = this.textStr.replace(/\&\&/g, "_*_");
    this.textStr = this.textStr.replace(/\&(.){1}/g, function(name, variableName){
        return "<font style='text-decoration: underline' [#CONTAINERID#]>" + variableName + "</font>";
    });
    this.textStr = this.textStr.replace("[#CONTAINERID#]", "containerID='" + this.content.id + "'");
    this.textStr = this.textStr.replace(/_\*_/g, "&");
    //  this.textStr = this.textStr.replace(/ /g, " &nbsp;");
    /*
     this.textStr = this.textStr.replace(/( {2,})/g, function(name, variableName){
     return name.replace(/ /g, "&nbsp;");
     });
     */
    this.p = this.text.createChild({
        tag: "div",
        style: "position:absolute;" + textStyle + ";",
        html: this.textStr,
        containerID: this.content.id
    });
    this.p.setLeft((width - this.p.getWidth()) * this.textX / 100);
    this.p.setTop((height - this.p.getHeight()) * this.textY / 100);
    this.p.setHeight(this.p.getHeight());
    this.p.setWidth(this.width);
    
    this.hasMouseOverResponse = trim(cfgXML.getElementsByTagName("hasMouseOverResponse")[0].childNodes[0].nodeValue).toLowerCase();
    this.mouseOverResponseValue = trim(cfgXML.getElementsByTagName("mouseOverResponseValue")[0].childNodes[0].nodeValue);
    try {
        this.resetStr = trim(cfgXML.getElementsByTagName("reset")[0].childNodes[0].nodeValue);
    } 
    catch (err) {
        this.resetStr = "[NULL]";
    }
    this.content.set({
        "textID": this.p.id,
        "imageID": (this.framesCount > 0 ? this.image.id : 0),
        "containerID": this.content.id,
        "toggleBtn": this.toggleBtn.toString(),
        "toggled": "false",
        "name": this.name.toLowerCase(),
        "value": this.value,
        "mouseOverResponse": this.hasMouseOverResponse,
        "mouseOverResponseValue": this.mouseOverResponseValue,
        "optionFinished": this.theOptionFinished,
        "resetStr": this.resetStr,
        "textMoveX": this.textMoveX,
        "textMoveY": this.textMoveY,
        "imageMoveX": this.imageMoveX,
        "imageMoveY": this.imageMoveY,
        "responseToClick": this.responseToClick,
        "clickHandler": this.click
    });
    
    try {
        this.feedBackText = trim(cfgXML.getElementsByTagName("feedBackText")[0].childNodes[0].nodeValue);
    } 
    catch (err) {
        this.feedBackText = "NOTOOLTIP";
        this.feedBackDelay = 0;
    }
    if (this.feedBackText != "NOTOOLTIP") {
        this.feedBackDelay = parseFloat(trim(cfgXML.getElementsByTagName("feedBackDelay")[0].childNodes[0].nodeValue));
        this.toolTip = new Ext.ToolTip({
            target: this.content.dom.id,
            shadow: 'drop',
            showDelay: this.feedBackDelay * 1000,
            mouseOffset: [0, -15],
            trackMouse: true,
            //  width: 80,
            bodyStyle: "text-align:center",
            html: this.feedBackText
        });
    }
    //  alert(this.name + ", "+ this.theOptionFinished);
    this.visible = true;
}


CustomButtonClass.prototype.setImagePosition = function(iWidth, iHeight){
    var x = (this.width - iWidth) * this.pictureX / 100;
    var y = (this.height - iHeight) * this.pictureY / 100;
    switch (this.textPosition) {
        case "left":
            x = this.width - iWidth;
            break;
        case "right":
            x = 0;
            break;
        case "top":
            y = this.height - iHeight;
            break;
        case "down":
            y = 0;
            break;
    }
    this.image.setLeft(x);
    this.image.setTop(y);
}
CustomButtonClass.prototype.zorder = function(index){
    this.content.setStyle("z-index", index);
}
CustomButtonClass.prototype.checkPrecedence = function(){
    var listType = Author.current.currentListXML.attributes[0].nodeValue;
    if (listType == "INTERACTION") {
        Author.current.precedentObject = this.objectType;
        this.isPrecedent = true;
    }
}
CustomButtonClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.content.setStyle("cursor", "pointer");
    this.setTop(parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue)));
    this.setLeft(parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)));
    this.setWidth(parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue)));
    this.setHeight(parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue)));
    this.hide = trim(cfgXML.getElementsByTagName("hide")[0].childNodes[0].nodeValue).toLowerCase();
    
    try {
        this.addToForeground = trim(cfgXML.getElementsByTagName("addToForeground")[0].childNodes[0].nodeValue).toLowerCase() == "true";
    } 
    catch (err) {
        this.addToForeground = false;
    }
    this.setMouseDownEvent(function(e){
        e.stopEvent();
        var target = Ext.get(e.getTarget());
        
        var container = Ext.get(target.dom.getAttribute("containerID"));
        var imageTagID = container.dom.getAttribute("imageID");
        if (imageTagID.toString() != "0") {
            var imageDiv = Ext.get(imageTagID);
            var imX = parseInt(container.dom.getAttribute("imageMoveX"));
            var imY = parseInt(container.dom.getAttribute("imageMoveY"));
            imageDiv.applyStyles("margin-left:" + imX + "px;margin-top:" + imY + "px");
        }
        var textDiv = Ext.get(container.dom.getAttribute("textID"));
        var tmX = parseInt(container.dom.getAttribute("textMoveX"));
        var tmY = parseInt(container.dom.getAttribute("textMoveY"));
        
        
        textDiv.applyStyles("margin-left:" + tmX + "px;margin-top:" + tmY + "px");
        if (container.dom.getAttribute("toggleBtn").toString() == "true") {
            if (container.dom.getAttribute("toggled").toString() == "true") {
                container.dom.setAttribute("toggled", "false");
                try {
                    var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
                    if (elementType == "MULTIPLECHOICE") {
                        Author.answers.multipleChoice.removeKey(container.dom.getAttribute("value"));
                    }
                } 
                catch (err) {
                    alert("mouseDown::toggle=false::" + err);
                }
                try {
                    container.setStyle("color", trim(cfgXML.getElementsByTagName("mouseOutColor")[0].childNodes[0].nodeValue));
                } 
                catch (err) {
                }
                try {
                    var img = new Image();
                    img.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOutImage")[0].childNodes[0].nodeValue).toLowerCase()));
                    Ext.get(container.dom.getAttribute("imageID")).dom.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOutImage")[0].childNodes[0].nodeValue).toLowerCase()));
                } 
                catch (err) {
                }
            }
            else {
                if (container.dom.getAttribute("resetStr") != "[NULL]") {
                    for (var index = Author.interactionList.startIndex; index <= Author.interactionList.endIndex; index++) {
                        var action = Author.current.currentList.itemAt(index);
                        if (action.objectType == "CUSTOMBUTTONOBJECT") {
                            //alert(action.name + " VS " + container.dom.getAttribute("resetStr") + " : " + (action.name.indexOf(container.dom.getAttribute("resetStr")) >= 0));
                            
                            if (action.name.toLowerCase().indexOf(container.dom.getAttribute("resetStr").toLowerCase()) >= 0) {
                                action.content.dom.setAttribute("toggled", "false");
                                try {
                                    action.image.dom.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOutImage")[0].childNodes[0].nodeValue).toLowerCase()));
                                } 
                                catch (err) {
                                }
                                if (elementType == "MULTIPLECHOICE") {
                                    Author.answers.multipleChoice.removeKey(action.container.dom.getAttribute("value"));
                                }
                            }
                        }
                        
                    }
                }
                container.dom.setAttribute("toggled", "true");
                try {
                    var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
                    
                    Author.variables.get(variableName('ANSWER')).setValue("ANSWER");
                    
                    if (elementType == "MULTIPLECHOICE") {
                        Author.answers.multipleChoice.add(container.dom.getAttribute("value").toUpperCase(), container.dom.getAttribute("toggled"));
                    }
                } 
                catch (err) {
                    alert("mouseDown::toggle=true::" + err);
                }
                try {
                    container.setStyle("color", trim(cfgXML.getElementsByTagName("mouseOverColor")[0].childNodes[0].nodeValue));
                } 
                catch (err) {
                }
                try {
                    var img = new Image();
                    img.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOverImage")[0].childNodes[0].nodeValue).toLowerCase()));
                    
                    Ext.get(container.dom.getAttribute("imageID")).dom.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOverImage")[0].childNodes[0].nodeValue).toLowerCase()));
                } 
                catch (err) {
                }
            }
            var clickHdl = container.dom.getAttribute("clickHandler")
            var responseToClick = container.dom.getAttribute("responseToClick")
            
            if (clickHdl == "CHECKRESPONSE" && responseToClick) {
            
                var value = container.dom.getAttribute("value");
                
                
                Author.variables.get(variableName('SELECTEDVALUE')).setValue(value);
                Author.variables.get(variableName('SELECTEDNAME')).setValue(container.dom.getAttribute("name"));
                try {
                    var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
                    if (elementType == "MULTIPLECHOICE") {
                        //   var target = Ext.get(e.getTarget());
                        //  var container = Ext.get(target.dom.containerID);
                        //  var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
                        
                        Author.variables.get(variableName('ANSWER')).setValue(value);
                        var regex = /^[A|B|C|D|E|F|G|H]{1}$/;
                        var answer = container.dom.getAttribute("value").toUpperCase();
                        if (regex.test(answer) == true) {
                            Author.answers.multipleChoice.add(container.dom.getAttribute("value").toUpperCase(), container.dom.getAttribute("toggled"));
                        }
                        checkResponse();
                    }
                    else 
                        if (elementType == "YESNO") {
                            //  var target = Ext.get(e.getTarget());
                            //   var container = Ext.get(target.dom.containerID);
                            //  var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
                            Author.variables.get(variableName('ANSWER')).setValue(value);
                            Author.answers.yesNo = value.toLowerCase();
                            checkResponse();
                        }
                        else 
                            if (elementType == "TRUEFALSE") {
                                Author.variables.get(variableName('ANSWER')).setValue(value);
                                Author.answers.trueFalse = value.toLowerCase();
                                checkResponse();
                            }
                            else {
                                // var variable = trim(cfgXML.getElementsByTagName("variable")[0].childNodes[0].nodeValue);
                                //  var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
                                Author.variables.get(variableName('ANSWER')).setValue(value);
                                checkResponse();
                            }
                    return;
                } 
                catch (err) {
                    alert("mouseDown::toggle=true::" + err);
                }
                
                var variable = trim(cfgXML.getElementsByTagName("variable")[0].childNodes[0].nodeValue);
                var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
                Author.variables.get(variableName('ANSWER')).setValue(value);
                checkResponse();
                return;
            }
        }
        
    });
    
    this.setMouseUpEvent(function(e){
        e.preventDefault();
        var target = Ext.get(e.getTarget());
        var container = Ext.get(target.dom.containerID);
        var textDiv = Ext.get(container.dom.getAttribute("textID"));
        textDiv.applyStyles("margin-left:" + 0 + "px;margin-top:" + 0 + "px");
        var imageTagID = container.dom.getAttribute("imageID");
        if (imageTagID.toString() != "0") {
            var imageDiv = Ext.get(imageTagID);
            imageDiv.applyStyles("margin-left:" + 0 + "px;margin-top:" + 0 + "px");
        }
    });
    
    this.setMouseOverEvent(function(e){
    
        e.stopEvent();
        var target = Ext.get(e.getTarget());
        try {
            var container = Ext.get(target.dom.getAttribute("containerID"));
            if (container.dom.getAttribute("toggleBtn") == "false") 
                Ext.get(container.dom.getAttribute("textID")).setStyle("color", trim(cfgXML.getElementsByTagName("mouseOverColor")[0].childNodes[0].nodeValue));
        } 
        catch (err) {
            //alert(err.description);
        }
        try {
            if (container.dom.getAttribute("toggleBtn") == "false") {
                var img = new Image();
                img.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOverImage")[0].childNodes[0].nodeValue).toLowerCase()));
                
                Ext.get(container.dom.getAttribute("imageID")).dom.src = eval(Ext.encode(Author.resourcePath + trim(cfgXML.getElementsByTagName("mouseOverImage")[0].childNodes[0].nodeValue).toLowerCase()));
            }
        } 
        catch (err) {
            //alert(err.description);
        }
        try {
            if (container.dom.getAttribute("mouseOverResponse") == "true") {
            
                Author.variables.get(variableName('ANSWER')).setValue(container.dom.getAttribute("mouseOverResponseValue"));
                
                checkResponse();
            }
        } 
        catch (err) {
            //alert(err.description);
        }
    });
    this.setMouseOutEvent(function(e){
        e.stopEvent();
        var target = Ext.get(e.getTarget());
        var container = Ext.get(target.dom.getAttribute("containerID"));
        
        
        //alert(container.dom.id+", "+container.dom.getAttribute("containerID")+", "+container.dom.getAttribute("optionFinished"));
        var optionFinished = container.dom.getAttribute("optionFinished").toString() == "true";
        //alert(container.dom.getAttribute("optionFinished").toString());
        // var optionFinished = container.dom.getAttribute("optionFinished") == "true";
        var tickColor = "#000";
        
        try {
            tickColor = trim(cfgXML.getElementsByTagName("tickColor")[0].childNodes[0].nodeValue).toLowerCase();
            if (tickColor == "none") {
                tickColor = trim(cfgXML.getElementsByTagName("mouseOutColor")[0].childNodes[0].nodeValue);
            }
        } 
        catch (err) {
            tickColor = trim(cfgXML.getElementsByTagName("mouseOutColor")[0].childNodes[0].nodeValue);
        }
        
        try {
            if (container.dom.getAttribute("toggleBtn") == "false") {
                Ext.get(container.dom.getAttribute("textID")).setStyle("color", (optionFinished ? tickColor : trim(cfgXML.getElementsByTagName("mouseOutColor")[0].childNodes[0].nodeValue)));
            }
        } 
        catch (err) {
            //alert(err.description);
        }
        try {
            if (container.dom.getAttribute("toggleBtn") == "false") {
                var menuTickImage = "none";
                try {
                    menuTickImage = trim(cfgXML.getElementsByTagName("menuTickImage")[0].childNodes[0].nodeValue).toLowerCase();
                } 
                catch (err) {
                }
                var imgSrc = trim(cfgXML.getElementsByTagName("mouseOutImage")[0].childNodes[0].nodeValue).toLowerCase();
                if (optionFinished && menuTickImage != "none") {
                    imgSrc = menuTickImage;
                }
                //alert(imgSrc);
                Ext.get(container.dom.getAttribute("imageID")).dom.src = eval(Ext.encode(Author.resourcePath + imgSrc));
            }
            
        } 
        catch (err) {
            //alert(err.description);
        }
    });
    if (this.click == "GOTOMENUOPTION") {
        this.setOnClickEvent(function(e){
            // if (Author.waitingMedia) 
            //  return;
            Author.Test.startAtRandom = false;
            e.stopEvent();
            // alert("GOTOMENUOPTION Clicked");
            var nextOptionID = parseInt(trim(cfgXML.getElementsByTagName("nextLessonNode")[0].childNodes[0].nodeValue));
            //alert("nextOptionID: "+nextOptionID);
            Author.current.currentNode = Author.lessonNodes.nodes.get(nextOptionID);
            Author.current.currentElementXML = null;
            Author.current.currentElementType = "";
            Author.current.currentElementResponses.clear();
            Author.current.currentElementPosition = -1;
            Author.current.currentListPosition = 0;
            Author.response.clear();
            //  Author.current.currentElementResponses.clear();
            //Author.clearBackgroundObjects = true;
            showLessonNode();
        })
    }
    if (this.click == "TORESPONSE") {
        this.setOnClickEvent(function(e){
            if (Author.inResponse || Author.lessonFinished) 
                return;
            
            e.stopEvent();
            // alert("toResponse");
            var target = Ext.get(e.getTarget());
            var container = Ext.get(target.dom.getAttribute("containerID"));
            var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
            Author.variables.get(variableName('SELECTEDVALUE')).setValue(value);
            Author.variables.get(variableName('SELECTEDNAME')).setValue(container.dom.getAttribute("name"));
            //alert(value+", "+ container.dom.getAttribute("name"));
            //var variable = trim(cfgXML.getElementsByTagName("variable")[0].childNodes[0].nodeValue);
            //var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
            Author.variables.get(variableName('ANSWER')).setValue(value);
            checkResponse();
            return;
        })
    }
    if (this.click == "SKIP") {
        this.setOnClickEvent(function(e){
            e.stopEvent();
            Author.variables.get(variableName('SELECTEDVALUE')).setValue("SKIP");
            Author.variables.get(variableName('SELECTEDNAME')).setValue("SKIP");
            if (Author.pause != null && Author.pause.cancelType != 0) {
                Author.pause = null;
                pauseVideoes();
                window.clearTimeout(Author.actionTimer);
            }
            var listType = Author.current.currentListXML.attributes[0].nodeValue;
            if (listType == "INTRODUCTION") {
                var actions = Author.current.currentListXML.getElementsByTagName("action");
                Author.current.currentActionPosition = actions.length;
                showList();
                return;
            }
            else {
                if (Author.current.currentNode.type != "MENU") {
                
                    Author.current.currentElementXML = null;
                    Author.current.currentElementType = "";
                    Author.current.currentElementResponses.clear();
                    Author.response.clear();
                    Author.current.currentElementPosition++;
                    showLessonNode();
                    return;
                }
            }
        })
    }
    if (this.click == "TOUPPERMENU") {
        this.setOnClickEvent(function(e){
            // if (Author.waitingMedia) 
            // return;
            Author.Test.startAtRandom = false;
            e.stopEvent();
            // alert("TOUPPERMENU Clicked");
            Author.variables.get(variableName('SELECTEDVALUE')).setValue("TOUPPERMENU");
            Author.variables.get(variableName('SELECTEDNAME')).setValue("TOUPPERMENU");
            
            if (getParentNode() == 0) 
                return;
            
            
            while (Author.current.currentBgStack.getCount() > 0) {
                var bgObject = Author.current.currentBgStack.last();
                Author.current.currentBgStack.remove(bgObject);
                if (Author.current.currentBgStack.getCount() == 0) {
                    Author.backgroundObject.setBg(bgObject);
                }
            }
            
            
            //  Author.backgroundObject.setOriginal();
            Author.current.currentNode = Author.lessonNodes.nodes.get(getParentNode());
            Author.current.currentElementXML = null;
            Author.current.currentElementType = "";
            Author.current.currentElementResponses.clear();
            Author.current.currentElementPosition = -1;
            Author.current.currentListPosition = 0;
            Author.response.clear();
            Author.current.currentElementResponses.clear();
            Author.clearBackgroundObjects = true;
            Author.backToMenu = true;
            showLessonNode();
        })
    }
    if (this.click == "TOMAINMENU") {
        this.setOnClickEvent(function(e){
            //   if (Author.waitingMedia) 
            //  return;
            Author.Test.startAtRandom = false;
            e.stopEvent();
            // alert("TOMAINMENU Clicked");
            
            Author.variables.get(variableName('SELECTEDVALUE')).setValue("TOMAINMENU");
            Author.variables.get(variableName('SELECTEDNAME')).setValue("TOMAINMENU");
            Author.backgroundObject.setOriginal();
            if (Author.current.currentNode.parent != 0) {
                do {
                    Author.current.currentNode = Author.lessonNodes.nodes.get(getParentNode());
                }
                while (Author.current.currentNode.parent != 0)
            }
            else {
                showLessonNode();
            }
            Author.current.currentElementXML = null;
            Author.current.currentElementType = "";
            Author.current.currentElementResponses.clear();
            Author.current.currentElementPosition = -1;
            Author.current.currentListPosition = 0;
            Author.response.clear();
            Author.current.currentElementResponses.clear();
            Author.clearBackgroundObjects = true;
            Author.backToMenu = true;
            showLessonNode();
        })
    }
    if (this.click == "NEXT") {
        this.setOnClickEvent(function(e){
            if (Author.lessonFinished) {
                return;
            }
            
            e.stopEvent();
            Author.variables.get(variableName('SELECTEDVALUE')).setValue("NEXT");
            Author.variables.get(variableName('SELECTEDNAME')).setValue("NEXT");
            
            if (Author.pause != null && Author.pause.cancelType != 0) {
                Author.pause = null;
                
                pauseVideoes();
                window.clearTimeout(Author.actionTimer);
                
                showList();
            }
            else {
            
                if (Author.enableNextBtn == false) 
                    return;
                //alert("Next: "+ Author.variables.get(variableName('ANSWER')).value);
                if (Author.current.currentListXML.attributes[0].nodeValue == "INTERACTION" || Author.lessonFlow == "repeat") {
                    makeAnswerVariable();
                }
                //alert("Next2: "+ Author.variables.get(variableName('ANSWER')).value);
                if (Author.variables.get(variableName('ANSWER')).getValue() == null || Author.variables.get(variableName('ANSWER')).getValue() == "") 
                    Author.variables.get(variableName('ANSWER')).setValue("NEXT");
                //  alert("Next CLicked inner");
                checkResponse();
            }
            //alert("Next CLicked");
        })
    }
    if (this.click == "BACK") {
        this.setOnClickEvent(function(e){
            // if (Author.waitingMedia) 
            //  return;
            e.stopEvent();
            //  alert("BACK Clicked");
            Author.variables.get(variableName('SELECTEDVALUE')).setValue("BACK");
            Author.variables.get(variableName('SELECTEDNAME')).setValue("BACK");
            if (Author.pause != null && Author.pause.cancelType != 0) {
                Author.pause = null;
                window.clearTimeout(Author.actionTimer);
            }
            if (Author.current.currentElementXML != null) {
                Author.current.currentElementPosition -= 1
                Author.current.currentElementXML = null;
                if (Author.current.currentElementPosition < 0) {
                    Author.Test.startAtRandom = false;
                    if (getParentNode() == 0) 
                        return;
                    Author.current.currentNode = Author.lessonNodes.nodes.get(getParentNode());
                    while (Author.current.currentBgStack.getCount() > 0) {
                        var bgObject = Author.current.currentBgStack.last();
                        Author.current.currentBgStack.remove(bgObject);
                        if (Author.current.currentBgStack.getCount() == 0) {
                            Author.backgroundObject.setBg(bgObject);
                        }
                    }
                    //  Author.backgroundObject.setOriginal();
                    Author.current.currentElementXML = null;
                    Author.current.currentElementType = "";
                    Author.current.currentElementResponses.clear();
                    Author.current.currentElementPosition = -1;
                    Author.current.currentListPosition = 0;
                    Author.clearBackgroundObjects = true;
                    Author.backToMenu = true;
                }
            }
            else {
                Author.current.currentListPosition -= 1;
                if (Author.current.currentListPosition < 0) {
                    Author.current.currentNode = Author.lessonNodes.nodes.get(getParentNode());
                    Author.current.currentListPosition = 0;
                    Author.clearBackgroundObjects = true;
                }
            }
            Author.responseEnd = true;
            Author.inResponse = false;
            Author.response.clear();
            Author.current.currentElementResponses.clear();
            showLessonNode();
            return;
        })
    }
    if (this.click == "EXITLESSON") {
        this.setOnClickEvent(function(e){
            e.stopEvent();
            if (Author.pause != null && Author.pause.cancelType != 0) {
                Author.pause = null;
                window.clearTimeout(Author.actionTimer);
            }
            Author.mediaList.eachKey(function(key, object){
                if (Ext.isIE) {
                    object.mediaObject.dom.controls.stop();
                    object.mediaObject.dom.settings.mute = true;
                }
            });
            
            Ext.MessageBox.confirm('Exit the lesson', 'Do you really want to exit this lesson?', function(btn){
                if (btn == "yes") {
                    endLesson();
                }
            });
        })
    }
    if ((this.click == "CHECKRESPONSE" && this.toggleBtn == false)) {
        this.setOnClickEvent(function(e){
            //  if (Author.waitingMedia) 
            //   return;
            if (Author.inResponse || Author.lessonFinished) 
                return;
            e.stopEvent();
            var target = Ext.get(e.getTarget());
            var container = Ext.get(target.dom.getAttribute("containerID"));
            var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
            Author.variables.get(variableName('SELECTEDVALUE')).setValue(value);
            Author.variables.get(variableName('SELECTEDNAME')).setValue(container.dom.getAttribute("name"));
            //  alert("ResponseToClick: " + container.dom.getAttribute("responseToClick"));
            try {
                var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
                if (elementType == "MULTIPLECHOICE") {
                    //   var target = Ext.get(e.getTarget());
                    //  var container = Ext.get(target.dom.containerID);
                    //  var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
                    
                    Author.variables.get(variableName('ANSWER')).setValue(value);
                    var regex = /^[A|B|C|D|E|F|G|H]{1}$/;
                    var answer = container.dom.getAttribute("name").toUpperCase();
                    if (regex.test(answer) == true) {
                        Author.answers.multipleChoice.add(container.dom.getAttribute("value").toUpperCase(), container.dom.getAttribute("toggled"));
                    }
                    checkResponse();
                }
                else 
                    if (elementType == "YESNO") {
                        //  var target = Ext.get(e.getTarget());
                        //   var container = Ext.get(target.dom.containerID);
                        //  var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
                        Author.variables.get(variableName('ANSWER')).setValue(value);
                        Author.answers.yesNo = value.toLowerCase();
                        checkResponse();
                    }
                    else 
                        if (elementType == "TRUEFALSE") {
                            Author.variables.get(variableName('ANSWER')).setValue(value);
                            Author.answers.trueFalse = value.toLowerCase();
                            checkResponse();
                        }
                        else {
                            // var variable = trim(cfgXML.getElementsByTagName("variable")[0].childNodes[0].nodeValue);
                            //  var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
                            
                            Author.variables.get(variableName('ANSWER')).setValue(value);
                            checkResponse();
                        }
                
                return;
            } 
            catch (err) {
                alert("MouseClick::" + err.description);
            }
            
            var variable = trim(cfgXML.getElementsByTagName("variable")[0].childNodes[0].nodeValue);
            var value = trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue);
            Author.variables.get(variableName('ANSWER')).setValue(value);
            checkResponse();
            return;
        })
    }
    if (this.addToForeground == false && this.toggleBtn) 
        this.checkPrecedence();
    //this.addToForeground=true;
    if (this.addToForeground == true) {
        this.setVisible(this.hide == "false");
        Author.foregroundList.list.add(this.id, this);
        this.addToForegroundAtElementPosition = Author.current.currentElementPosition;
        this.zorder(100);
    }
    this.key1 = "none";
    this.key2 = "none";
    try {
        this.key1 = trim(cfgXML.getElementsByTagName("key1")[0].childNodes[0].nodeValue);
        this.key2 = trim(cfgXML.getElementsByTagName("key2")[0].childNodes[0].nodeValue);
        
        if (this.key1 != "none") 
            Author.actionKeyMap.add(this.key1, this);
        if (this.key2 != "none") 
            Author.actionKeyMap.add(this.key2, this);
    } 
    catch (err) {
    }
    return 0;
}


CustomButtonClass.prototype.setText = function(textHTML){
    if (this.textPosition != "center") {
        this.p.dom.innerText = textHTML;
    }
    else {
        this.p.dom.innerText = textHTML;
    }
    
}
CustomButtonClass.prototype.setImage = function(url){

    if (this.textPosition != "center") {
        this.image.dom.src = eval(Ext.encode(url));
        
    }
    else {
        this.content.setStyle("background-image", "url(" + Ext.encode(url.toLowerCase()) + ")");
    }
    
}
CustomButtonClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
CustomButtonClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
CustomButtonClass.prototype.setWidth = function(width){
    this.width = width;
    this.content.setWidth(width);
}
CustomButtonClass.prototype.setHeight = function(height){
    this.height = height;
    this.content.setHeight(height);
}
CustomButtonClass.prototype.setVisible = function(visible){
    this.visible = visible;
    this.content.setVisible(visible);
    
}
CustomButtonClass.prototype.setAlignmentH = function(alignment){
    this.content.setStyle("text-align", alignment);
}
CustomButtonClass.prototype.setStyle = function(CSSStyle){
    this.content.applyStyles(CSSStyle);
}
CustomButtonClass.prototype.setMouseDownEvent = function(mouseDownEventHandler){
    this.content.on("mousedown", eval(mouseDownEventHandler));
}
CustomButtonClass.prototype.setMouseUpEvent = function(mouseUpEventHandler){
    this.content.on("mouseup", eval(mouseUpEventHandler));
}
CustomButtonClass.prototype.setMouseOverEvent = function(mouseOverEventHandler){
    this.content.on("mouseover", eval(mouseOverEventHandler));
}
CustomButtonClass.prototype.setMouseOutEvent = function(mouseOutEventHandler){
    this.content.on("mouseout", eval(mouseOutEventHandler));
}
CustomButtonClass.prototype.setOnClickEvent = function(onClickEventHandler){
    this.content.on("click", eval(onClickEventHandler));
}
CustomButtonClass.prototype.remove = function(){
    if (this.key1 != "none") 
        Author.actionKeyMap.removeKey(this.key1);
    if (this.key2 != "none") 
        Author.actionKeyMap.removeKey(this.key2);
    this.content.remove();
}
function VariableClass(){

}


VariableClass.prototype.readConfig = function(cfgXML){

    this.objectType = "VariableClass"
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    //alert("Variable :"+this.id);
    var expressions = cfgXML.getElementsByTagName("expressions")[0].childNodes;
    this.numExpressions = expressions.length;
    for (var i = 0; i < this.numExpressions; i++) {
        var expression = new String(expressions[i].childNodes[0].nodeValue);
        var equPos = expression.indexOf("=");
        var vID = trim(expression.substring(1, equPos - 2));
        var valueExpression = expression.substring(equPos + 1, expression.length);
        //  alert(valueExpression);
        if (Author.variables.containsKey(vID)) {
        
            valueExpression = replaceVariableNameWithValue(valueExpression);
            var thisVar = Author.variables.get(vID);
            if (thisVar.variableType == 0) {
                //alert(valueExpression +" >> "+evalExpression(valueExpression));
                thisVar.setValue(eval(evalExpression(valueExpression)));
                //alert(eval(valueExpression));
            }
            else {
                //     alert(valueExpression +" >> "+evalExpression(valueExpression));
                thisVar.setValue(evalExpression(valueExpression));
                //alert(valueExpression);
            }
        }
        else {
            //  alert(vID + " doesn't exist!");
        }
    }
    return 0;
}

VariableClass.prototype.remove = function(){
}
VariableClass.prototype.setVisible = function(visible){
}


function PauseClass(){
    this.objectType = "PAUSEOBJECT";
};
PauseClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    var pauseType = trim(cfgXML.getElementsByTagName("type")[0].childNodes[0].nodeValue);
    var cancel = parseInt((trim(cfgXML.getElementsByTagName("cancelType")[0].childNodes[0].nodeValue)));
    this.key1 = "none";
    this.key2 = "none";
    try {
        this.key1 = trim(cfgXML.getElementsByTagName("key1")[0].childNodes[0].nodeValue);
        this.key2 = trim(cfgXML.getElementsByTagName("key2")[0].childNodes[0].nodeValue);
    } 
    catch (err) {
    }
    Author.pause = {
        cancelType: cancel,
        startTime: new Date(),
        id: this.id,
        key1: this.key1,
        key2: this.key2
    }
    if (pauseType == "time") {
        var countDown = eval((trim(cfgXML.getElementsByTagName("time")[0].childNodes[0].nodeValue)) * 1000);
        Author.pause.countDown = countDown;
        return countDown;
    }
    if (pauseType == "waitForUser") {
        return 3600 * 24 * 1000;
    }
}
PauseClass.prototype.remove = function(){
}
PauseClass.prototype.setVisible = function(visible){
}

function DividerClass(){
    this.objectType = "DIVIDER";
}

DividerClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.backMarker = trim(cfgXML.getElementsByTagName("backMarker")[0].childNodes[0].nodeValue).toLowerCase();
    this.listPosition = Author.current.currentListPosition - 1;
    this.actionPosition = Author.current.currentActionPosition - 1;
    this.currentListPosition = Author.current.currentList.getCount();
    if (this.backMarker == "true") {
        Author.dividers.add(this.id, this);
    }
}
DividerClass.prototype.setVisible = function(visible){
}
DividerClass.prototype.remove = function(){
}
function VisibleClass(){
    this.objectType = "VISIBLEOBJECT";
}

VisibleClass.prototype.readConfig = function(cfgXML, travelling){
    if (typeof(travelling) == 'undefined') {
        travelling = false;
    }
    else {
        travelling = travelling === true;
    }
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    var show, hide, index;
    var currentList = cfgXML.getElementsByTagName("currentList")[0];
    if (currentList.childNodes.length > 0) {
        show = currentList.getElementsByTagName("show");
        for (index = 0; index < show.length; index++) {
        
            try {
                // alert("Show: " + show[index].childNodes[0].nodeValue);
                var action = Author.current.currentList.item(show[index].childNodes[0].nodeValue);
                var effect = parseInt(show[index].attributes[0].nodeValue);
                var duration = parseFloat(show[index].attributes[1].nodeValue);
                //alert("Show:\neffect: "+effect +", duration: "+duration);
                if (typeof(action) == 'undefined') 
                    continue;
                if (action.objectType == "CUSTOMBUTTONOBJECT") 
                    action.changedByVisibleAction = true;
                action.setVisible(true);
                if (!travelling) 
                    setFxToElement(action, effect, duration);
            } 
            catch (err) {
                alert("Line 2308 in class.js\n" + err.description);
            }
        }
        hide = currentList.getElementsByTagName("hide");
        
        for (index = 0; index < hide.length; index++) {
            try {
                //  alert("hide: " + hide[index].childNodes[0].nodeValue);
                var action = Author.current.currentList.item(hide[index].childNodes[0].nodeValue);
                var effect = parseInt(hide[index].attributes[0].nodeValue);
                var duration = parseFloat(hide[index].attributes[1].nodeValue);
                // alert("Hide:\neffect: "+effect +", duration: "+duration);
                
                if (action.objectType == "CUSTOMBUTTONOBJECT") 
                    action.changedByVisibleAction = true;
                if (travelling) 
                    action.setVisible(false);
                else 
                    setHideFxToElement(action, effect, duration);
            } 
            catch (err) {
                //   if (!travelling) 
                //      displayError("Visible Action:\nVisible Action seems to trying to hide an action that doesn't exist.\nActionID: " + this.id + "\nObjectID: " + hide[index].childNodes[0].nodeValue);
            }
        }
    }
    return 0;
}
VisibleClass.prototype.setVisible = function(visible){
}
VisibleClass.prototype.remove = function(){
}
/**
 * TextFieldClass
 * @param {Object} bgObject
 * @param {Object} cfgXML
 */
function TextFieldClass(bgObject, cfgXML){
    this.multiline = trim(cfgXML.getElementsByTagName("multiline")[0].childNodes[0].nodeValue).toLowerCase();
    this.objectType = "TEXTFIELDOBJECT";
    this.isPrecedent = false;
    this.name = trim(cfgXML.getElementsByTagName("name")[0].childNodes[0].nodeValue);
    this.content = bgObject.createChild({
        objectType: "TEXTFIELDOBJECT",
        tag: (this.multiline == "true") ? "textarea" : "input",
        name: this.name,
        type: (this.multiline == "true") ? "" : "text",
        style: "position:absolute;"
    });
    this.visible = true;
}

TextFieldClass.prototype.checkPrecedence = function(){
    var listType = Author.current.currentListXML.attributes[0].nodeValue;
    if (listType == "INTERACTION") {
        Author.current.precedentObject = this.objectType;
        this.isPrecedent = true;
    }
}
TextFieldClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.setAlignmentH(trim(cfgXML.getElementsByTagName("textAlignmentH")[0].childNodes[0].nodeValue));
    this.content.setStyle("border-width", trim(cfgXML.getElementsByTagName("borderWidth")[0].childNodes[0].nodeValue));
    this.content.setStyle("border-color", trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue));
    this.content.setStyle("border-style", trim(cfgXML.getElementsByTagName("borderStyle")[0].childNodes[0].nodeValue));
    
    this.setTop(parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue)));
    this.setLeft(parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)));
    this.setWidth(parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue)));
    this.setHeight(parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue)));
    this.content.setStyle("font-family", trim(cfgXML.getElementsByTagName("font-family")[0].childNodes[0].nodeValue));
    this.content.setStyle("font-size", trim(cfgXML.getElementsByTagName("font-size")[0].childNodes[0].nodeValue) + "pt");
    this.content.setStyle("font-style", trim(cfgXML.getElementsByTagName("font-style")[0].childNodes[0].nodeValue));
    this.content.setStyle("font-weight", trim(cfgXML.getElementsByTagName("font-weight")[0].childNodes[0].nodeValue));
    this.content.setStyle("color", trim(cfgXML.getElementsByTagName("color")[0].childNodes[0].nodeValue));
    this.content.setStyle("background-color", trim(cfgXML.getElementsByTagName("backColor")[0].childNodes[0].nodeValue));
    this.content.on("change", function(e){
        if (Author.inResponse || Author.lessonFinished) 
            return;
        var target = Ext.get(e.getTarget());
        try {
            var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
            if (elementType == "SHORTANSWER") {
                Author.answers.shortAnswer = target.dom.value.toLowerCase();
                //alert(Author.answers.shortAnswer);
            }
        } 
        catch (err) {
        
        }
        //this.focus();
        // checkInstantResponse("var " + target.dom.name + " = \"" + target.dom.value + "\";");
        return;
    });
    this.content.on("focus", function(e){
        Author.doingInteraction = true;
        var target = Ext.get(e.getTarget());
        target.dom.select();
        return;
    });
    this.content.on("blur", function(e){
        Author.doingInteraction = false;
        try {
            var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
            if (elementType == "SHORTANSWER") {
                Author.answers.shortAnswer = target.dom.value.toLowerCase();
            }
        } 
        catch (err) {
        
        }
        //	this.focus();
        return;
    });
    this.checkPrecedence();
    //	this.content.focus();
    return 0;
}
TextFieldClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
TextFieldClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
TextFieldClass.prototype.setWidth = function(width){
    this.content.setWidth(width);
}
TextFieldClass.prototype.setHeight = function(height){
    this.content.setHeight(height);
}
TextFieldClass.prototype.setVisible = function(visible){
    this.visible = visible;
    this.content.setVisible(visible);
}

TextFieldClass.prototype.setBackgroundColor = function(color){
    this.content.setStyle("background-color", color);
}
TextFieldClass.prototype.setForegroundColor = function(color){
    this.content.setStyle("color", color);
}
TextFieldClass.prototype.setAlignmentH = function(alignment){
    //center,left,right
    this.content.setStyle("text-align", alignment);
}
TextFieldClass.prototype.setStyle = function(CSSStyle){
    this.content.applyStyles(CSSStyle);
}
TextFieldClass.prototype.remove = function(){

    this.content.remove();
}
/**
 * RadioButtonClass
 * @param {Object} bgObject
 * @param {Object} cfgXML
 */
function RadioButtonClass(bgObject, cfgXML){
    this.objectType = "RADIOBUTTONOBJECT";
    this.text = null;
    this.isPrecedent = false;
    this.name = trim(cfgXML.getElementsByTagName("name")[0].childNodes[0].nodeValue);
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue));
    
    this.content = bgObject.createChild({
        tag: "div",
        style: "position:absolute"
    });
    this.setTop(parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue)));
    this.setLeft(parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)));
    this.setWidth(this.width);
    this.setHeight(this.height);
    this.button = this.content.createChild({
        objectType: "RADIOBUTTONOBJECT",
        tag: "input",
        name: this.name,
        value: trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue),
        type: "radio",
        style: "position:absolute;top:" + (this.height - 12) / 2 + "px"
    });
    
    this.visible = true;
}

RadioButtonClass.prototype.checkPrecedence = function(){
    var listType = Author.current.currentListXML.attributes[0].nodeValue;
    if (listType == "INTERACTION") {
        Author.current.precedentObject = this.objectType;
        this.isPrecedent = true;
    }
}
RadioButtonClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.textStr = "";
    try {
        this.textStr = trim(cfgXML.getElementsByTagName("text")[0].childNodes[0].nodeValue);
    } 
    catch (err) {
    
    }
    this.setText(this.textStr);
    
    this.setAlignmentH(trim(cfgXML.getElementsByTagName("textAlignmentH")[0].childNodes[0].nodeValue));
    
    
    this.content.setStyle("font-family", trim(cfgXML.getElementsByTagName("font-family")[0].childNodes[0].nodeValue));
    this.content.setStyle("font-size", trim(cfgXML.getElementsByTagName("font-size")[0].childNodes[0].nodeValue) + "pt");
    this.content.setStyle("font-style", trim(cfgXML.getElementsByTagName("font-style")[0].childNodes[0].nodeValue));
    this.content.setStyle("font-weight", trim(cfgXML.getElementsByTagName("font-weight")[0].childNodes[0].nodeValue));
    this.content.setStyle("color", trim(cfgXML.getElementsByTagName("color")[0].childNodes[0].nodeValue));
    this.button.on("click", function(e){
    
        var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
        Author.current.currentList.each(function(item, index, length){
            if (item.objectType == "RADIOBUTTONOBJECT") {
                item.button.dom.checked = false;
                if (elementType == "MULTIPLECHOICE") {
                    Author.answers.multipleChoice.removeKey(item.button.dom.getAttribute("name"));
                }
            }
        });
        var target = Ext.get(e.getTarget());
        target.dom.checked = true;
        if (Author.inResponse || Author.lessonFinished) 
            return;
        e.stopPropagation();
        Author.variables.get(variableName('ANSWER')).setValue("ANSWER");
        if (elementType == "MULTIPLECHOICE") {
            Author.answers.multipleChoice.add(target.dom.getAttribute("name").toUpperCase(), target.dom.checked);
        }
        return;
    });
    this.checkPrecedence();
    return 0;
}
RadioButtonClass.prototype.setText = function(text){
    text = text.replace(/\&\&/g, "_*_");
    text = text.replace(/\&(.){1}/g, function(name, variableName){
        return "<font style='text-decoration: underline' [#CONTAINERID#]>" + variableName + "</font>";
    });
    text = text.replace("[#CONTAINERID#]", "containerID='" + this.content.id + "'");
    text = text.replace(/_\*_/g, "&");
    if (this.text == null) {
        this.text = this.content.createChild({
            tag: "label",
            'for': this.button.id,
            html: text,
            style: "position:absolute;left:20px;padding-left:2px"
        });
        this.text.setStyle("top", (this.height - this.text.getHeight()) / 2 + "px");
        this.text.on("click", function(e){
            if (Author.inResponse || Author.lessonFinished) 
                return;
            e.stopPropagation();
        });
    }
    /*
     if (this.text == null) {
     this.text = this.content.createChild({
     tag: "label",
     'for': this.button.id
     });
     this.text.on("click", function(e){
     if (Author.inResponse)
     return;
     e.stopPropagation();
     });
     }
     */
    // this.text.dom.innerHTML = "&nbsp;" + text;
}
RadioButtonClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
RadioButtonClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
RadioButtonClass.prototype.setWidth = function(width){
    this.content.setWidth(width);
}
RadioButtonClass.prototype.setHeight = function(height){
    this.content.setHeight(height);
}
RadioButtonClass.prototype.setVisible = function(visible){
    this.visible = visible;
    this.content.setVisible(visible);
}

RadioButtonClass.prototype.setBackgroundColor = function(color){
    this.content.setStyle("background-color", color);
}
RadioButtonClass.prototype.setForegroundColor = function(color){
    this.content.setStyle("color", color);
}
RadioButtonClass.prototype.setAlignmentH = function(alignment){
    //center,left,right
    this.text.setStyle("text-align", alignment);
}
RadioButtonClass.prototype.setStyle = function(CSSStyle){
    this.content.applyStyles(CSSStyle);
}
RadioButtonClass.prototype.remove = function(){

    this.content.remove();
}
/**
 * CheckButtonClass
 * @param {Object} bgObject
 * @param {Object} cfgXML
 */
function CheckboxClass(bgObject, cfgXML){
    this.objectType = "CHECKBOXOBJECT";
    this.text = null;
    this.name = trim(cfgXML.getElementsByTagName("name")[0].childNodes[0].nodeValue);
    this.isPrecedent = false;
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue));
    this.top = parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue));
    this.left = parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue));
    this.generateResponse = trim(cfgXML.getElementsByTagName("generateResponse")[0].childNodes[0].nodeValue).toLowerCase();
    this.content = bgObject.createChild({
        tag: "div",
        style: "position:absolute;left:" + (this.left) + "px;top:" + (this.top) + "px;width:" + this.width + "px;height:" + this.height + "px"
    });
    
    this.setWidth(this.width);
    this.setHeight(this.height);
    this.button = this.content.createChild({
        objectType: "CHECKBOXOBJECT",
        tag: "input",
        name: this.name,
        value: trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue),
        type: "checkbox",
        style: "position:absolute;top:" + (this.height - 12 - (Ext.isIE ? 8 : 0)) / 2 + "px"
    });
    this.visible = true;
}

CheckboxClass.prototype.checkPrecedence = function(){
    var listType = Author.current.currentListXML.attributes[0].nodeValue;
    if (listType == "INTERACTION") {
        //alert("checkRrecedent");
        // if (this.generateResponse == "true") {
        Author.current.precedentObject = this.objectType;
        //alert("checkRrecedent");
        this.isPrecedent = true;
        //   }
    }
}
CheckboxClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    
    
    this.content.setStyle("font-family", trim(cfgXML.getElementsByTagName("font-family")[0].childNodes[0].nodeValue));
    this.content.setStyle("font-size", trim(cfgXML.getElementsByTagName("font-size")[0].childNodes[0].nodeValue) + "pt");
    this.content.setStyle("font-style", trim(cfgXML.getElementsByTagName("font-style")[0].childNodes[0].nodeValue));
    this.content.setStyle("font-weight", trim(cfgXML.getElementsByTagName("font-weight")[0].childNodes[0].nodeValue));
    this.content.setStyle("color", trim(cfgXML.getElementsByTagName("color")[0].childNodes[0].nodeValue));
    try {
        this.setText(trim(cfgXML.getElementsByTagName("text")[0].childNodes[0].nodeValue));
        this.setAlignmentH(trim(cfgXML.getElementsByTagName("textAlignmentH")[0].childNodes[0].nodeValue));
        
    } 
    catch (err) {
    }
    
    var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
    
    this.button.on("click", function(e){
        if (Author.inResponse || Author.lessonFinished) 
            return;
        e.stopPropagation();
        var target = Ext.get(e.getTarget());
        var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
        if (target.dom.checked) {
            Author.variables.get(variableName('ANSWER')).setValue("ANSWER");
            //alert( Author.variables.get(variableName('ANSWER')).value);
            if (elementType == "MULTIPLECHOICE") {
            
                Author.answers.multipleChoice.add(target.dom.getAttribute("name").toUpperCase(), target.dom.checked);
            }
        }
        else {
            if (elementType == "MULTIPLECHOICE") {
                Author.answers.multipleChoice.removeKey(target.dom.getAttribute("name").toLowerCase());
            }
        }
        return;
    });
    this.checkPrecedence();
    return 0;
}
CheckboxClass.prototype.setText = function(text){
    text = text.replace(/\&\&/g, "_*_");
    text = text.replace(/\&(.){1}/g, function(name, variableName){
        return "<font style='text-decoration: underline' [#CONTAINERID#]>" + variableName + "</font>";
    });
    text = text.replace("[#CONTAINERID#]", "containerID='" + this.content.id + "'");
    text = text.replace(/_\*_/g, "&");
    if (this.text == null) {
        this.text = this.content.createChild({
            tag: "label",
            'for': this.button.id,
            html: text
        });
        this.text.applyStyles("position:absolute;left:20px;top:" + (this.height - this.text.getHeight()) / 2 + "px;padding-left:2px");
        this.text.on("click", function(e){
            if (Author.inResponse || Author.lessonFinished) 
                return;
            e.stopPropagation();
        });
    }
    
    //this.text.dom.innerHTML = text;
}
CheckboxClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
CheckboxClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
CheckboxClass.prototype.setWidth = function(width){
    this.content.setWidth(width);
}
CheckboxClass.prototype.setHeight = function(height){
    this.content.setHeight(height);
}
CheckboxClass.prototype.setVisible = function(visible){
    this.visible = visible;
    this.content.setVisible(visible);
}

CheckboxClass.prototype.setBackgroundColor = function(color){
    this.content.setStyle("background-color", color);
}
CheckboxClass.prototype.setForegroundColor = function(color){
    this.content.setStyle("color", color);
}
CheckboxClass.prototype.setAlignmentH = function(alignment){
    //center,left,right
    this.text.setStyle("text-align", alignment);
}
CheckboxClass.prototype.setStyle = function(CSSStyle){
    this.content.applyStyles(CSSStyle);
}
CheckboxClass.prototype.remove = function(){
    this.content.remove();
}
/**
 * HotSpotClass
 * @param {Object} bgObject
 * @param {Object} cfgXML
 */
function HotSpotClass(bgObject, cfgXML){
    this.objectType = "HOTSPOTOBJECT";
    this.isPrecedent = false;
    this.buttonType = trim(cfgXML.getElementsByTagName("buttonType")[0].childNodes[0].nodeValue);
    this.name = trim(cfgXML.getElementsByTagName("name")[0].childNodes[0].nodeValue);
    this.ddTarget = trim(cfgXML.getElementsByTagName("DDTarget")[0].childNodes[0].nodeValue).toLowerCase();
    this.responseTrigger = trim(cfgXML.getElementsByTagName("responseTrigger")[0].childNodes[0].nodeValue);
    
    this.respondToDrop = trim(cfgXML.getElementsByTagName("respondToDrop")[0].childNodes[0].nodeValue).toLowerCase();
    this.respondToMouseOver = trim(cfgXML.getElementsByTagName("respondToMouseOver")[0].childNodes[0].nodeValue).toLowerCase();
    this.responseValue = "nothing";
    if (this.respondToMouseOver == "true") 
        this.responseValue = trim(cfgXML.getElementsByTagName("responseValue")[0].childNodes[0].nodeValue);
    
    this.content = bgObject.createChild({
        tag: "div",
        name: this.name,
        orginalValue: trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue),
        value: trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue),
        responseValue: this.responseValue,
        respondToDrop: this.respondToDrop,
        type: "HOTSPOT",
        style: "position:absolute"
    });
    if (this.responseTrigger != "none") 
        this.content.setStyle("cursor", "pointer");
    //  addCondition(this.content.dom.name, this.content.dom.value);
    this.setStyle("position:absolute;display:block;background-color:#0c0;border:none;border-color:#000;opacity:0; filter: alpha(opacity=0);z-index:90");
    this.visible = true;
}

HotSpotClass.prototype.checkPrecedence = function(){
    var listType = Author.current.currentListXML.attributes[0].nodeValue;
    if (listType == "INTERACTION") {
        if (this.ddTarget == "true" && this.respondToDrop == "false" && this.responseTrigger == "none") {
            this.isPrecedent = true;
            Author.current.precedentObject = this.objectType;
        }
    }
}
HotSpotClass.prototype.zorder = function(index){
    this.content.setStyle("z-index", index);
}
HotSpotClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.setTop(parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue)));
    this.setLeft(parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)));
    this.setWidth(parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue)));
    this.setHeight(parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue)));
    try {
        this.addToForeground = trim(cfgXML.getElementsByTagName("addToForeground")[0].childNodes[0].nodeValue).toLowerCase() == "true";
    } 
    catch (err) {
        this.addToForeground = false;
    }
    if (this.responseTrigger != "none") {
        this.content.on(this.responseTrigger, function(e){
            if (Author.inResponse || Author.lessonFinished) 
                return;
            e.stopEvent();
            var target = Ext.get(e.getTarget());
            //   alert(target.dom.name + " : " + target.dom.value);
            
            var variable = target.dom.getAttribute("name");
            var value = target.dom.getAttribute("value");
            // alert(variable+ " : " + value);
            Author.variables.get(variableName('ANSWER')).setValue(value);
            Author.variables.get(variableName('SELECTEDVALUE')).setValue(value);
            Author.variables.get(variableName('SELECTEDNAME')).setValue(variable);
            // alert(Author.current.currentElementType);
            // Author.answers.multipleChoice.add(variable, value);
            var elementType = Author.current.currentElementXML.attributes[0].nodeValue;
            if (elementType == "MULTIPLECHOICE") {
            
                var regex = /^[A|B|C|D|E|F|G|H]{1}$/;
                var answer = value.toUpperCase();
                if (regex.test(answer) == true) {
                    Author.answers.multipleChoice.add(variable.toUpperCase(), answer.toLowerCase());
                }
            }
            else 
                if (elementType == "YESNO") {
                    Author.answers.yesNo = value.toLowerCase();
                }
                else 
                    if (elementType == "TRUEFALSE") {
                        Author.answers.trueFalse = value.toLowerCase();
                    }
            //alert("before hs check response");
            checkResponse();
            
            return;
        });
    }
    if (this.respondToMouseOver == "true") {
        this.content.on("mouseover", function(e){
            if (Author.inResponse || Author.lessonFinished) 
                return;
            e.stopEvent();
            var target = Ext.get(e.getTarget());
            // alert(target.dom.name + " : " + target.dom.value);
            
            var variable = target.dom.getAttribute("name");
            var value = target.dom.getAttribute("responseValue");
            //addCondition("ANSWER", "USERSELECT");
            Author.variables.get(variableName('ANSWER')).setValue(value);
            // alert(Author.current.currentElementType);
            // Author.answers.multipleChoice.add(variable, value);
            //alert("intoResponseFromMouseOver");
            checkResponse();
            
            return;
        });
    }
    
    if (this.ddTarget == "true") {
        this.dropZone = new Ext.dd.DropZone(this.content.id, {
            ddGroup: 'group'
        });
        this.content.set({
            "content": "NOTHING"
        });
    }
    this.checkPrecedence();
    
    if (this.addToForeground == true) {
        this.setVisible(this.hide == "false");
        Author.foregroundList.list.add(this.id, this);
        this.addToForegroundAtElementPosition = Author.current.currentElementPosition;
        this.zorder(100);
    }
    
    this.key1 = "none";
    this.key2 = "none";
    try {
        this.key1 = trim(cfgXML.getElementsByTagName("key1")[0].childNodes[0].nodeValue);
        this.key2 = trim(cfgXML.getElementsByTagName("key2")[0].childNodes[0].nodeValue);
        if (this.key1 != "none") 
            Author.actionKeyMap.add(this.key1, this);
        if (this.key2 != "none") 
            Author.actionKeyMap.add(this.key2, this);
    } 
    catch (err) {
    }
    
    return 0;
}
HotSpotClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
HotSpotClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
HotSpotClass.prototype.setWidth = function(width){
    this.content.setWidth(width);
}
HotSpotClass.prototype.setHeight = function(height){
    this.content.setHeight(height);
}
HotSpotClass.prototype.setVisible = function(visible){
    this.visible = visible;
    this.content.setVisible(visible);
}
HotSpotClass.prototype.setStyle = function(CSSStyle){
    this.content.applyStyles(CSSStyle);
}
HotSpotClass.prototype.remove = function(){
    if (this.key1 != "none") 
        Author.actionKeyMap.removeKey(this.key1);
    if (this.key2 != "none") 
        Author.actionKeyMap.removeKey(this.key2);
    this.content.remove();
}
/**
 * DDButtonClass
 * @param {Object} bgObject
 */
function DDButtonClass(bgObject, cfgXML){
    this.objectType = "DDUTTONOBJECT";
    this.imageName = trim(cfgXML.getElementsByTagName("image")[0].childNodes[0].nodeValue).toLowerCase();
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue));
    this.name = trim(cfgXML.getElementsByTagName("name")[0].childNodes[0].nodeValue);
    this.content = bgObject.createChild({
        tag: "div",
        name: this.name,
        value: trim(cfgXML.getElementsByTagName("value")[0].childNodes[0].nodeValue),
        miss: trim(cfgXML.getElementsByTagName("miss")[0].childNodes[0].nodeValue),
        style: "position:absolute"
    });
    this.content.setStyle("z-index", 90);
    this.image = null;
    this.visible = true;
}

DDButtonClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.setImage(Author.resourcePath + this.imageName);
    this.content.setStyle("cursor", "pointer");
    
    this.setTop(parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue)));
    this.setLeft(parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)));
    this.setWidth(this.width);
    this.setHeight(this.height);
    this.content.set({
        "orginalX": parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)),
        "orginalY": parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue))
    });
    this.content.dd = new Ext.dd.DDProxy(this.content.id, 'group');
    return 0;
}

DDButtonClass.prototype.setImage = function(url){
    if (this.image == null) {
        this.image = this.content.createChild({
            id: "buttonImage",
            tag: "img",
            width: this.width,
            height: this.height,
            style: "alt:''"
        });
    }
    this.image.dom.src = eval(Ext.encode(url));
    this.fixPng();
}
DDButtonClass.prototype.fixPng = function(){
    var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
    var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
    if (Ext.isIE && (ie55 || ie6) && (this.imageName.indexOf(".png") >= 0)) {
        this.image.setStyle("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + Author.resourcePath + this.imageName + "',sizingMethod='scale')");
        this.image.dom.src = "lib/images/blank.gif";
    }
}
DDButtonClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
DDButtonClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
DDButtonClass.prototype.setWidth = function(width){
    this.content.setWidth(width);
}
DDButtonClass.prototype.setHeight = function(height){
    this.content.setHeight(height);
}
DDButtonClass.prototype.setVisible = function(visible){
    this.visible = visible;
    this.content.setVisible(visible);
}
DDButtonClass.prototype.setStyle = function(CSSStyle){
    this.content.applyStyles(CSSStyle);
}
DDButtonClass.prototype.setMouseOverEvent = function(mouseOverEventHandler){
    this.content.on("mouseover", mouseOverEventHandler);
}
DDButtonClass.prototype.setMouseOutEvent = function(mouseOutEventHandler){
    this.content.on("mouseout", eval(mouseOutEventHandler));
}
DDButtonClass.prototype.setOnClickEvent = function(onClickEventHandler){
    this.content.on("click", onClickEventHandler);
}
DDButtonClass.prototype.remove = function(){

    this.content.remove();
}


function FlashClass(bgObject, cfgXML){

    this.objectType = "FLASHOBJECT";
    this.width = parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue));
    this.height = parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue));
    this.url = trim(cfgXML.getElementsByTagName("movie")[0].childNodes[0].nodeValue);
    this.type = trim(cfgXML.getElementsByTagName("type")[0].childNodes[0].nodeValue);
    if (this.type == "WWW") 
        this.url = eval(Ext.encode(this.url.toLowerCase()));
    else {
        this.url = eval(Ext.encode(Author.resourcePath + this.url.toLowerCase()));
    }
    this.content = bgObject.createChild({
        tag: "div",
        style: "position:absolute;background-color:#fff"
    });
    
    try {
        this.flashObject = this.content.createChild({
            tag: "OBJECT",
            classid: "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
            codebase: "http://download.macromedia.com/pub/shockwave /cabs/flash/swflash.cab#version=9,0,115,0",
            width: this.width,
            height: this.height,
            align: "",
            children: [{
                tag: "PARAM",
                NAME: "movie",
                VALUE: this.url
            }, {
                tag: "embed",
                src: this.url,
				width: this.width,
            	height: this.height,
                type: "application/x-shockwave-flash",
                swLiveConnect: "true",
                pluginspage: "http://www.macromedia.com/go/getflashplayer"
            }]
        });
    } 
    catch (err) {
        alert(err.description);
    }
}

FlashClass.prototype.readConfig = function(cfgXML){
    this.id = trim(cfgXML.getElementsByTagName("id")[0].childNodes[0].nodeValue);
    this.content.setStyle("position", "absolute");
    this.setTop(parseInt(trim(cfgXML.getElementsByTagName("top")[0].childNodes[0].nodeValue)));
    this.setLeft(parseInt(trim(cfgXML.getElementsByTagName("left")[0].childNodes[0].nodeValue)));
    this.setWidth(parseInt(trim(cfgXML.getElementsByTagName("width")[0].childNodes[0].nodeValue)));
    this.setHeight(parseInt(trim(cfgXML.getElementsByTagName("height")[0].childNodes[0].nodeValue)));
 
    try {
        this.content.setStyle("border-style", trim(cfgXML.getElementsByTagName("borderStyle")[0].childNodes[0].nodeValue));
        this.content.setStyle("border-width", trim(cfgXML.getElementsByTagName("borderWidth")[0].childNodes[0].nodeValue));
        this.content.setStyle("border-color", trim(cfgXML.getElementsByTagName("borderColor")[0].childNodes[0].nodeValue));
        
    } 
    catch (err) {
        alert("FlashElement:\n" + err.description);
    }
    this.setVisible(true);
    return 0;
}

FlashClass.prototype.toFront = function(){
    this.content.setStyle("z-index", 80);
}

FlashClass.prototype.setTop = function(y){
    this.content.setStyle("top", y + "px");
}
FlashClass.prototype.setLeft = function(x){
    this.content.setStyle("left", x + "px");
}
FlashClass.prototype.setWidth = function(width){
    this.content.setWidth(width);
}
FlashClass.prototype.setHeight = function(height){
    this.content.setHeight(height);
}
FlashClass.prototype.setVisible = function(visible){
    this.visible = visible;
    this.content.setVisible(visible);
}
FlashClass.prototype.remove = function(){

    this.content.remove();
}
