

var bHome = new Ext.Button({
     icon: 'images/arrow_out.png'
    ,iconCls: 'nav'
    ,tooltip: 'Revenir à la vue de départ'
    ,handler: function(){
        map.zoomToMaxExtent();
    }
});

var bMapInfo = new Ext.Button({
     icon: 'images/table_gear.png'
    ,iconCls: 'nav'
    ,tooltip: 'Voir les informations sur la carte'
    ,handler: function(){
        displayMapInfos();
    }
});

var bPan = new Ext.Button({
    toggleGroup :'tool_grp',
    pressed :tbar_pressed["pan"], // définit dans init.js
    icon :'images/hand.png',
    iconCls :'nav',
    tooltip :'Déplacer la fenêtre',
    handler :function(){
      deactivateControl('all');
      document.body.style.cursor = 'move';
    }
});

var bZoombox = new Ext.Button({
    toggleGroup :'tool_grp',
    pressed :tbar_pressed["zoom"], // définit dans init.js
    icon :'images/zoom_in.png',
    iconCls :'nav',
    tooltip :'Zoomer sur une région: clic simple ou boîte',
    handler :function(){
      activateControl('zoombox');
      document.body.style.cursor = 'crosshair';
    }
});

// Construction du bouton pour l'activation du GetFeatureInfo
var bGetFeatureInfo = new Ext.Button({
    toggleGroup :'tool_grp',
    pressed :tbar_pressed["featureinfo"], // définit dans init.js
    icon :'images/help.png',
    iconCls :'nav',
    tooltip :'Information sur la donnée',
    handler :function(){
      activateControl('featureInfo');
    }
});

//var bMesure = new Ext.Button({
//    toggleGroup :'tool_grp',
//    pressed :false,
//    icon :'images/ruler_pencil.png',
//    iconCls :'nav',
//    tooltip :'Calculer une distance',
//    handler: function() {
//        openMeasure();
//        activateControl('measure');
//    }
//});

var bPrint = new Ext.Button({
     icon: 'images/printer.png'
    ,iconCls: 'nav'
    ,tooltip: 'Imprimer la page'
    ,handler: function(){
        window.print();
    }
});

/*var bLegend = new Ext.Button({
     icon: './images/text_list_bullets.png'
    ,iconCls: 'nav'
    ,tooltip: 'Toggle legend window'
    ,handler: function(){
        displayLegendInfos();
    }
});*/

var bGetZoomToScale = new Ext.Button({
     cls: "x-btn-icon"
    ,icon: "images/arrow_in.png"
    ,tooltip: 'Agrandissement rapide à une échelle'
    ,handler: function(){
        getZoomToScale();
    }
});


// This item renders the scale box information on the top toolbar
var dfScale = new Ext.form.DisplayField({
     id: 'dfScale'
    ,value: ''
    ,width: 120
    ,labelStyle: 'font-weight:bold;font-size:0.8em;color:#909;font-family:Arial,Helvetica,Verdana,Sans-serif;'
});


// These following items manage the Search box rendering and action
var tfSearch = new Ext.form.TextField({
     name: "tfSearch"
    ,id: "tfSearch"
    ,width: 100
});

var bGo = new Ext.Button({
    cls: "x-btn-icon",
    icon: "images/go.png",
    tooltip: { text: 'Chercher!', autoHide:true },
    handler: function(){
        var search = Ext.get('tfSearch').dom.value;
        if(search.length==0){ return; }
        searchAndMove(search);
    }
});

tfSearch.on("specialkey",function(t,e){
  if(e.getKey()==Ext.EventObject.RETURN){
      var search = Ext.get('tfSearch').dom.value;
      if(search.length==0){ return; }
      searchAndMove(search);
  }
});


// Construction du menu déroulant pour gérer les items du menu Aide
var helpMenu =  new Ext.menu.Menu({
    id: 'HelpMenu',
    items: [{
        text: 'Aide',
        handler: function() {
			if (viewport.getComponent('eastPanel').collapsed) {
				viewport.getComponent('eastPanel').expand()
			} else {
				viewport.getComponent('eastPanel').collapse()
			}
/*            wHelp.show();
            Ext.getCmp('tpAide').setActiveTab('tAide');*/
        }
    },{
        text: 'Foire aux questions',
        handler: function() {
			
			wHelp.show();
            Ext.getCmp('tpAide').setActiveTab('tFAQ');
        }
    },{
        text: 'Démos',
        handler: function() {
            wHelp.show();
            Ext.getCmp('tpAide').setActiveTab('tDemos');
        }
    },{
        text: 'Nouveautés',
        handler: function() {
            wHelp.show();
            Ext.getCmp('tpAide').setActiveTab('tNouveautes');
        }
    },{
        text: 'Licences',
        handler: function() {
            wHelp.show();
            Ext.getCmp('tpAide').setActiveTab('tLicences');
        }
    },{
        text: 'Crédits',
        handler: function() {
            wHelp.show();
            Ext.getCmp('tpAide').setActiveTab('tCredits');
        }
    },{
        text: 'À propos...',
        handler: function() {
            wHelp.show();
            Ext.getCmp('tpAide').setActiveTab('tAPropos');
        }
      }]
});

// Construction du bouton Aide qui est affiché dans la barre de menu
var bHelp = new Ext.Button({
     text: 'Aide'
    ,icon: 'images/help.png'
    ,iconCls: 'nav'
    ,tooltip: 'Aide et Informations'
    ,menu: helpMenu
});

// Construire le menu déroulant pour gérer les fonds de carte disponibles
var baseMapsMenu =  new Ext.menu.Menu({
    id: 'baseMapsMenu',
    items: [{
        text: 'Satellite',
        group: 'baseMaps',
        checked: false,
        checkHandler: function() {
			if (getLayerByIdentFromMap("Satellite").visibility == false) {
				getLayerByIdentFromMap("BASSIN_ORDRE1_2").setVisibility(false);
				getLayerByIdentFromMap("BASSIN_ORDRE1_CONTOUR").setVisibility(true);
			}
            displayBaseMap(layerCanimage);
        }
    },{
        text: 'Relief',
        group: 'baseMaps',
        checked: false,
        checkHandler: function() {
			if (getLayerByIdentFromMap("Relief").visibility == false) {
				getLayerByIdentFromMap("BASSIN_ORDRE1_2").setVisibility(false);
				getLayerByIdentFromMap("BASSIN_ORDRE1_CONTOUR").setVisibility(true);
			}
            displayBaseMap(layerElevation);
        }
    },{
        text: 'Aucun',
        group: 'baseMaps',
        checked: true,
        checkHandler: function() {
            displayBaseMap(layerNone);
			if (getLayerByIdentFromMap("Satellite").visibility == false && getLayerByIdentFromMap("Relief").visibility == false) {
				getLayerByIdentFromMap("BASSIN_ORDRE1_2").setVisibility(true);
				getLayerByIdentFromMap("BASSIN_ORDRE1_CONTOUR").setVisibility(false);
			}
        }
      }]
});

var bBaseMaps = new Ext.Button({
     text: 'Fond de carte'
    ,menu: baseMapsMenu
	,tooltip : 'Changer le fond de carte'
});

var tip = new Ext.ux.SliderTip({
    getText: function(slider){
        return String.format('<b>{0}%</b>', slider.getValue());
    }
});

// Slider to manage layer opacity
sLayerOpacity = new Ext.Slider({
     id: 'opacitySlider'
    ,width: 100
    ,minValue: 0
    ,maxValue: 100
    ,plugins: tip
});

sLayerOpacity.on('change', function(slider,value){
    if (gACTIVELAYER != -1) {
		map.layers[gACTIVELAYER].setOpacity(value/100);
	}
});

sLayerOpacity.on('changecomplete', function(slider,value){
    updateMapInfos();
});





