/*
This js class is used to keep all context properties (such as map view modem etc.)
*/
function Context() {
    this.type = "";
    this.id = 0;
    this.mapMode = "PR";
    this.mainImageElement = null;
    this.infoPanelIndex = 0;
    
    this.contextInfoItems = null; //tabs of information fr InfoPanel
    
    this.onContextChanged = null; //event(context, oldType, oldId) fires when context changed (type or id)
    //this.onContextTypeChanged = null; //event(context, oldType, oldId) fires when context type changed
    this.onModeChanged = null; //event fires when mode changes
    
    this.changeContext = function(type, id) {
        //alert("Requested a context change to "+type+", " +id + ".");
        var changed = false;
        //var typeChanged = false;
        if (this.type != type || this.id != id)
            changed = true;
        /*if (this.type != type)
            typeChanged = true;*/
        
        var oldType = this.type;
        var oldId = this.id;
        
        if (this.type != type) {
            this.infoPanelIndex = 0;
        }
               
        this.type = type;
        this.id = id;
        
        /*if (typeChanged && this.onContextTypeChanged) {
            this.onContextTypeChanged(this, oldType, oldId);
        }*/
        
        if (changed && this.onContextChanged) {
            this.onContextChanged(this, oldType, oldId);
        }
    }
    
    this.changeMode = function(mode) {
        //alert(this.mapMode+", "+mode);
        if (this.mapMode != mode) {
            this.mapMode = mode;
            if (this.onModeChanged) {
                this.onModeChanged(this);
            }
        } else
            this.mapMode = mode;
        
        //alert("Map requested a change of mode to "+mode+". Dynamic template switch is not yet implemented.");
    }
}

