// create namespace, make sure this is the first line to be run, and Constants.js
// is the first include
//var createCompassNS = function(){
Ext.namespace('CompassGis');
//}();

CompassGis.constants = function(){


    var pm = {}; // Public Members
    var webServer = 'http://' + window.location.host; //maps.seai.ie';
    var wmsServer = 'http://wms.sei.ie';
    var wmsServer2 = 'http://137.191.235.74';

    // for map tiles
    pm.mapFile = 'geothermal.map';
    var mapserverURL = "/mapserver/mapserv.exe?map=/ms4w64/apps/seai/";
    var tileCacheURL = "/seaitiles/tilecache.py?MAP="; // MAP is currently case sensitive
    pm.mapServerURL = wmsServer + mapserverURL;
    pm.mapServerURL2 = wmsServer2 + mapserverURL;
    pm.tileCacheURL = wmsServer + tileCacheURL;
    pm.tileCacheURL2 = wmsServer2 + tileCacheURL;
    
    var handlerBasePath = webServer + "/SeaiHandlers/";
    
    pm.handlerBasePath = handlerBasePath;
    
    var wiki = webServer + '/PublicWiki/';
    pm.wiki = wiki;
    pm.wikiHelpRoot = wiki + 'wikiHandler.ashx?Page=';
    
    pm.cntyGazetteerURL = handlerBasePath + "Gazetteers/CountyGazetteer.ashx";
    pm.tlGazetteerURL = handlerBasePath + "Gazetteers/TownlandGazetteer.ashx";
    
    pm.existingBioenergyHandler = handlerBasePath + 'Bioenergy/ExistingBioenergy.ashx';
    pm.infoToolHandler = handlerBasePath + 'infotool/BasicLayerInfo.ashx';
    pm.bioenergyHandler = wmsServer + '/rasterhandling/rasterclip.py';
    pm.rasterQueryHandler = wmsServer + '/rasterquery/rasterquery.py';
    pm.kmlHandler = handlerBasePath + 'Infotool/FeatureKML.ashx?';
    
    // proxy host for cross domain calls
    //pm.proxyHost = "";
    
    pm.mapLegend = 'images/legends/geothermal.png';
    pm.mapHandler = handlerBasePath + 'Geothermal/geothermal.ashx';
    pm.mapHandlerWinTitle = 'Temperature Details';
    pm.infoToolTitle = 'Info: click on the map for geothermal temperature details';
    
    //legend image paths
    pm.imgGrid = "images/layer_types/grid.png";
    pm.imgPolygon = "images/layer_types/polygon.png";
    pm.imgLine = "images/layer_types/line.png";
    pm.imgPoint = "images/layer_types/point.png";
    pm.imgLayer = "images/layer_types/layer.png";
    
    return pm;
}();

CompassGis.geothermal = function(){
    return {
        setUp: function(){
        
            try {
                CompassGis.app.initMap();
                var map = CompassGis.app.map();
                var paneltools = CompassGis.geothermalToolPanel.getPanelTools(map);
                CompassGis.app.initTools(paneltools);
                var toolbar = CompassGis.app.toolbar();
                CompassGis.geothermalToolBar.configureToolbar(toolbar, map);
            } 
            catch (e) {
                console.log(e);
            }
            Ext.get('loading').fadeOut({
                remove: true
            });
        }
    }
}();

// Ext 2.2(.1) loads the page twice if it has an error in the Ext.onReady function.
Ext.onReady(CompassGis.geothermal.setUp, CompassGis.app);

