//try
//{
//    wedebug.addLogger("mapController", "AbstractMapController");
//}
//catch(e)
//{
//    alert(e.message);
//}

var AbstractMapController = {
    m_fullScreen : false,
    m_viewOffset : null,
    
    setResizeObserver : function()
    {
        Event.observe( window, "resize", this.fit.bind(this) ); // Resize                
    },
    
    _resizeTimer : null,
    fit : function()
    {
        if( this._resizeTimer != null )
        {
            window.clearTimeout(this._resizeTimer);
        }
        this._resizeTimer = window.setTimeout(this._fit.bind(this), 300);
    },

    toggleFullscreen : function()
    {   
        if(this.m_fullScreen == false){        
            $("mapWrapper").style.position = 'absolute';  
            this.m_fullScreen = true;
            this._fit();
        }
        else if(this.m_fullScreen == true){
            $("mapWrapper").style.position = 'relative';
            this.m_fullScreen = false;
            this._fit();
        }
        return this.m_fullScreen;
    },
    
    internal_setViewOffset : function(t_offset)
    {
        this.m_viewOffset = t_offset;
    },
    
    internal_getViewOffset : function()
    {
        return this.m_viewOffset;
    },
    
    _logTimeout : null,
    logMapRequest : function(t_customerId, t_activeMap)
    {
        if( this._logTimeout != null)
        {
            clearTimeout(this._logTimeout);
        }
        
        this._logTimeout = setTimeout(this._logRequest.bind(this,t_customerId, t_activeMap), 500);
        
		//alert('log!');
    },
    
    _lastSrc : null,
    _logRequest : function(t_customerId, t_activeMap)
    {
        var t_viewport = this.getViewport();
        var img = document.createElement('img');
        var t_src = "http://services.webatlas.no/weblog/Log2.aspx?" +
		       "WMS-REQUEST=BBOX=" + t_viewport.minLon + "," + t_viewport.minLat + "," + t_viewport.maxLon + "," + t_viewport.maxLat +
               "&MAPSTYLE=" + t_activeMap.getMapStyle()+
               "&ZOOMLEVEL=" + t_activeMap.getZoomLevel() +
               "&PROVIDER=" + t_activeMap.getType() +
               "&CUSTOMER=TOLK";
        
        if( t_src != this._lastSrc )
        {
            img.src = t_src;            
		    img = null;
		}
    }
}
