﻿/*
* Declare MapClient
*/

Parts.MapClient = function(cfg){
    Parts.MapClient.initializeBase(this, [cfg]);
  
    var id = cfg.id;
    var className = cfg.className;
    var config=cfg.config;
    var controls = cfg.controls;
    var dynamicHeight = cfg.dynamicHeight;
  
  
    var _config = config;
    var _mapApi;
    var _mapEngine;
    var _partWindow = null; 
    
    //overriding parent
    this.initialize = function(partWindow){
         //initalize parent
         Parts.MapClient.callBaseMethod(this,"initialize", [partWindow]);
         this._partWindow = partWindow;
         this._mapEngine = config.mapEngine;
         //debugger
         //Create the mapApi, provide the root object of the part
         switch ( this._mapEngine ){
            case 'SGE':
                _mapApi = new MapApiClient.MapApiSGE( partWindow );
            break;
            case 'MG':
                 _mapApi = new MapApiClient.MapApiMG( partWindow );
            break;
            default:
                alert("MapClient :: mapEngine not configured");
            break;
         }
         Global.setMapApi( _mapApi );
         // Do the actual initialization of the map client
         _mapApi.initialize( _config, this.getResources() );
         // Load the map for the first time
         _mapApi.loadMap();
    }  
    
    
    //overrriding parent 
    var prevHeight=-1;
    var prevWidth=-1;
    this.onContainerResized =function(){
        Parts.MapClient.callBaseMethod(this,"onContainerResized");
        //debugger
        if  (this._mapEngine == 'SGE' ){
            var iframeMapClient = $get("iframe" + this.getId());
            var height = iframeMapClient.clientHeight;
            var width = iframeMapClient.clientWidth;
            
            var bVisible = this.isVisible();
            if (_mapApi!=null && bVisible && (height != prevHeight || width != prevWidth)){
               _mapApi.loadMap();
            }
            
            prevHeight=height;
            prevWidth=width;
        }
    }
    
    this.onAction = function(){
        alert(this.getId());
    }
}
Parts.MapClient.registerClass('Parts.MapClient', Parts.Part);

