BackgroundTypes = {
    Image:0,
    Color:1
};
BlankImageUrl = "lib/images/spacer.gif";
Ext.define('BackgroundClass15', {
    extend:'DisplayableAction',
    constructor:function (cfgXML, o, actionSequence) {
        this.Type = BackgroundTypes.Color;
        this.RemoveActions = false;
        this.Color = '#ffffff';
        this.Image = null;
        this.BackgroundContainer = null;
        this.BackgroundImageContainer = null;
        this.callParent([ cfgXML, o, actionSequence]);
        this.Image = XmlHelper.tryGetValue(cfgXML, "image", TryGetValueOption.Normal, null);
        this.Color = XmlHelper.getString(cfgXML, "background-color");
        this.Type = XmlHelper.getInteger(cfgXML, "type");
        this.RemoveActions = XmlHelper.getBoolean(cfgXML, "removeActions");
        this.LastX = 0;
        this.LastY = 0;
    },
    initializeDC:function (bg) {
        this.initializeDisplayComponent(bg);
        this.BackgroundImageContainer = this.ContentContainer.createChild({
            tag:'img',
            id:this.ObjectType + "-" + this.id + "-BackgroundImage",
            src:BlankImageUrl,
            tabindex:-1,
            style:'position:absolute;background-repeat:no-repeat;',
            width:this.ContentContainerWidth,
            height:this.ContentContainerHeight,
            onselectstart:"disableSelection();"
        });
        this.BackgroundContainer = this.ContentContainer.createChild({
            tag:"div",
            tabindex:-1,
            id:this.ObjectType + "-" + this.id + "-Container",
            style:"position:absolute;overflow:hidden;width:" + this.Width + "px;height:" + (this.Height) + "px;-moz-user-select:-moz-none;",
            onselectstart:"disableSelection();"
        });
        this.applyBackground(this);
        this.center();
    },
    applyBackground:function (backgroundObject) {
        if (this.IsChangeAction) {
            Author.log("Only the orginal background action have applyBackground!");
            return;
        }
        if (backgroundObject.Type == BackgroundTypes.Color) {
            this.setBackgroundColor(backgroundObject.Color);
        }
        if (backgroundObject.Type == BackgroundTypes.Image) {
            this.setBackgroundImage(Author.resourcePath + backgroundObject.Image);
            this.setBackgroundColor('transparent');
        }
    },
    restoreToAction:function (toAction) {
        this.applyBackground(toAction);
    },
    processAction:function (bg) {
        if (this.IsChangeAction) {
            if (this.RemoveActions) {
                Author.DisplayManager.clearScreen(this);
            }
            Author.DisplayManager.changeAction(this);
            return {MoveOn:true, Interval:0};
        }
        this.initializeDC(bg);
        this.setInitialVisibility();
        this.applyEffect();
        return {MoveOn:true, Interval:0};
    },
    doActionChange:function () {
        Author.DisplayManager.changeBackground(this);
    },
    setBackgroundColor:function (color) {
        this.BackgroundContainer.setStyle("background-color", color);
    },
    setBackgroundImage:function (url) {
        if (url == null) {
            url = BlankImageUrl;
        }
        this.BackgroundImageContainer.dom.src = url;
    },
    getContent:function () {
        return this.BackgroundContainer;
    },
    center:function () {
        var screenWidth = Ext.Element.getViewportWidth();
        var screenHeight = Ext.Element.getViewportHeight();
        var left = 0;
        var top = 0;
        var lessonWidth = Author.LessonManager.AuthorLesson.Width;
        var lessonHeight = Author.LessonManager.AuthorLesson.Height;
        if (screenWidth > lessonWidth) {
            left = (screenWidth - lessonWidth) / 2;
        }
        if (screenHeight > lessonHeight) {
            top = (screenHeight - lessonHeight) / 2;
        }
        if (this.LastX != left || this.LastY != top) {
            this.LastX = left;
            this.LastY = top;
            this.moveTo(left, top);
        }
    }
});


