/*
* GEMSS Application Class
*/
// create namespace
Ext.namespace('gemss');

// create application
gemss.app = function() {
    // private variables
    var msgCt; // container for modal status messages
    
    // private functions
    function createBox(t, s) {
        return [
            "<div class=\"msg\">", 
            "<div class=\"x-box-tl\"><div class=\"x-box-tr\"><div class=\"x-box-tc\"></div></div></div>", 
            "<div class=\"x-box-ml\"><div class=\"x-box-mr\"><div class=\"x-box-mc\"><h3>", t, "</h3>", s, 
            "</div></div></div>", "<div class=\"x-box-bl\"><div class=\"x-box-br\"><div class=\"x-box-bc\"></div></div></div>", 
            "</div>"].join("");
    }
    
    // public space
    return {
        // public properties, e.g. strings to translate
 
        // public methods
        msg : function(title, format){
            if(!msgCt){
                msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
            }
            msgCt.alignTo('mapPanel', 't-t');
            var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
            var m = Ext.DomHelper.append(msgCt, {html:createBox(title, s)}, true);
            m.slideIn('t').pause(1.5).ghost("t", {remove:true});
        },
        
        init: function() {
            Ext.QuickTips.init();
            // Ext.useShims = true; // for controls in 3d mode
            
            Ext.state.Manager.setProvider(
                new TNRIS.ASPProfileStateProvider({
                    listeners: {
                        'load': {scope: gemss.app, fn: gemss.app.init_onProfileLoad}
                    }
                }));
            
            Ext.apply(Ext.QuickTips.getQuickTip(), {
                showDelay: 5000,
                dismissDelay: 0
            });
            
            TNRIS.LayerFactory.init();
            TNRIS.SelectionManager.init();
        },
        
        init_onProfileLoad: function() {
            var mapPanel = new TNRIS.MapPanel({
                region: 'center',
                id: 'mapPanel',
                mapEl: 'theMapTop',
				border: false,
				cls: 'mapViewPort'				
            });
           
            var infoPanel = new TNRIS.InfoTabPanel({
                region: 'south',
                id: 'infoPanel',
                title: 'Information',
                collapsible: true,
                height: 200,
                split: true,
                mapPanel: mapPanel
            });

            var centerPanel = new Ext.Panel({
                region: 'center',
                layout: 'border',
                id: 'centerPanel',
                items: [
                    infoPanel,
                    mapPanel
                    ]
            });
			
            var layerPanel = new TNRIS.LayerPalette({
                id: 'layerPanel',
                region: 'east',
                collapsible: true,
                autohide: true,
				autoScroll: false,
                title: 'Available Sources',
                width: 275,
                mapPanel: mapPanel,
                informationPanel: infoPanel
            });
			
            var footerPanel = new Ext.Panel({
                contentEl: 'footerDIV',
                region: 'south',
                border: false,
                height: 20
            });
            
            var TXHisFilterWin = new TNRIS.TxHisCentralFilterWindow({mapPanel:mapPanel});
            
            var layout = new Ext.Viewport({
                layout: 'border',
                items: [
                    centerPanel,
                    layerPanel, 
                    footerPanel
                    ]
            });
        }
    };
}(); // end of app


// ExtJS references
// reference local blank image
Ext.BLANK_IMAGE_URL = '/javascript/extjs/resources/images/default/s.gif';

// ExtJS Initialization
Ext.onReady(gemss.app.init, gemss.app);

if (typeof(Sys) !== "undefined") { Sys.Application.notifyScriptLoaded(); }

