﻿var slider;     // sert pour la barre de zoom
var zoomSaved;  // zoom par défaut

// Création des boutons personnalisés
//// BOUTONS PLAN - SATELLITE -MIXTE
function PSMBoutonControl() { }
PSMBoutonControl.prototype = new GControl();
PSMBoutonControl.prototype.initialize = function(map) {

    var fond_container = document.createElement('div');
    fond_container.setAttribute('id', 'fond_container_controls');
    var container_controls = document.createElement('div');
    container_controls.setAttribute('id', 'container_controls');
    var body = document.getElementById('MapLeiContentContainer');
    body.appendChild(fond_container);
    body.appendChild(container_controls);

    var containerPSM = document.createElement('div');
    containerPSM.setAttribute("class", "container");

    // Création du bouton Plan //
    var boutonPlan = document.createElement('div');
    boutonPlan.id = "navPlan";
    boutonPlan.appendChild(document.createTextNode('Plan'));
    GEvent.addDomListener(boutonPlan, 'click', function() {
        map.setMapType(G_NORMAL_MAP);
        document.getElementById("navRelief").className = "";
        document.getElementById("navMixte").className = "";
        document.getElementById("navSatellite").className = "";
        document.getElementById("navPlan").className = "navSelected";
    });
    document.getElementById("navigationType").appendChild(boutonPlan);

    // Cr&eacute;ation du bouton Satellite //
    var boutonSatellite = document.createElement('div');
    boutonSatellite.id = "navSatellite";
    boutonSatellite.appendChild(document.createTextNode('Satellite'));
    GEvent.addDomListener(boutonSatellite, 'click', function() {
        map.setMapType(G_SATELLITE_MAP);
        document.getElementById("navRelief").className = "";
        document.getElementById("navMixte").className = "";
        document.getElementById("navSatellite").className = "navSelected";
        document.getElementById("navPlan").className = "";
    });
    document.getElementById("navigationType").appendChild(boutonSatellite);

    // Création du bouton Mixte //
    var boutonMixte = document.createElement('div');
    boutonMixte.id = "navMixte";
    boutonMixte.appendChild(document.createTextNode('Mixte'));
    GEvent.addDomListener(boutonMixte, 'click', function() {
        map.setMapType(G_HYBRID_MAP);
        document.getElementById("navRelief").className = "";
        document.getElementById("navMixte").className = "navSelected";
        document.getElementById("navSatellite").className = "";
        document.getElementById("navPlan").className = "";
    });
    document.getElementById("navigationType").appendChild(boutonMixte);

    // Création du bouton Relief //
    var boutonRelief = document.createElement('div');
    boutonRelief.id = "navRelief";
    boutonRelief.appendChild(document.createTextNode('Relief'));
    GEvent.addDomListener(boutonRelief, 'click', function() {
        map.setMapType(G_PHYSICAL_MAP);
        document.getElementById("navRelief").className = "navSelected";
        document.getElementById("navMixte").className = "";
        document.getElementById("navSatellite").className = "";
        document.getElementById("navPlan").className = "";
    });
    document.getElementById("navigationType").appendChild(boutonRelief);

    document.getElementById('container_controls').appendChild(containerPSM);

    //map.getContainer().appendChild(containerPSM);
    return containerPSM;
}

// Style deS boutons BOUTONS PLAN - SATELLITE -MIXTE //
PSMBoutonControl.prototype.setButtonStyle_PSM = function(button) {
    button.style.textDecoration = 'none';
    button.style.color = '#fff';
    button.style.background = "url('"+iconeDir+"fond_button.png')";
    button.style.backgroundRepeat = 'repeat-x';
    button.style.backgroundPosition = '0 -3px';
    button.style.font = '13px Arial';
    button.style.border = '1px solid #fff';
    button.style.padding = '2px 7px 2px 7px';
    button.style.marginTop = '7px';
    button.style.marginLeft = '7px';
    button.style.textAlign = 'center';
    button.style.width = '80px';
    button.style.cursor = 'pointer';
    button.style.display = 'inline';
}

// Position des boutons BOUTONS PLAN - SATELLITE -MIXTE //
PSMBoutonControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(14, 50));
}


//// BOUTONS de déplacement
function SRBoutonControl() { }
SRBoutonControl.prototype = new GControl();
SRBoutonControl.prototype.initialize = function(map) {
    var containerSR = document.createElement('div');

    // Cr&eacute;ation du bouton Restauration Zoom et emplacement de la carte //
    var boutonRestauration = document.createElement('div');
    boutonRestauration.setAttribute("id", "pan_restore");
    this.setButtonStyle_Bis_(boutonRestauration, 0);
    containerSR.appendChild(boutonRestauration);
    //boutonRestauration.appendChild(document.createTextNode('Restaurer la carte'));
    GEvent.addDomListener(boutonRestauration, 'click', function() {
        map.returnToSavedPosition();
        //slider.set(minGMapZoom);
    });

    var boutonPanRight = document.createElement('div');
    boutonPanRight.setAttribute("id", "pan_r");
    this.setButtonStyle_Bis_(boutonPanRight, 1);
    containerSR.appendChild(boutonPanRight);
    GEvent.addDomListener(boutonPanRight, 'click', function() {
        map.panDirection(-1, 0);
    });

    var boutonPanLeft = document.createElement('div');
    boutonPanLeft.setAttribute("id", "pan_l");
    this.setButtonStyle_Bis_(boutonPanLeft, 2);
    containerSR.appendChild(boutonPanLeft);
    GEvent.addDomListener(boutonPanLeft, 'click', function() {
        map.panDirection(+1, 0);
    });

    var boutonPanUp = document.createElement('div');
    boutonPanUp.setAttribute("id", "pan_u");
    this.setButtonStyle_Bis_(boutonPanUp, 3);
    containerSR.appendChild(boutonPanUp);
    GEvent.addDomListener(boutonPanUp, 'click', function() {
        map.panDirection(0, +1);
    });

    var boutonPanDown = document.createElement('div');
    boutonPanDown.setAttribute("id", "pan_d");
    this.setButtonStyle_Bis_(boutonPanDown, 4);
    containerSR.appendChild(boutonPanDown);
    GEvent.addDomListener(boutonPanDown, 'click', function() {
        map.panDirection(0, -1);
    });

    document.getElementById('container_controls').appendChild(containerSR);
    //map.getContainer().appendChild(containerSR);
    return containerSR;
}

// Position des boutons //
SRBoutonControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}

// Deuxieme Style de boutons //
SRBoutonControl.prototype.setButtonStyle_Bis_ = function(button, style) {
    switch (style) {

        //Bouton de replacement  
        case 0:
            button.style.background = "url('" + iconeDir + "button_replacement.png')";
            break;
        case 1:
            button.style.background = "url('" + iconeDir + "button_droit.png')";
            break;
        case 2:
            button.style.background = "url('" + iconeDir + "button_left.png')";
            break;
        case 3:
            button.style.background = "url('" + iconeDir + "button_top.png')";
            break;
        case 4:
            button.style.background = "url('" + iconeDir + "button_down.png')";
            break;
    }

    button.style.height = '16px';
    button.style.width = '16px';
    button.style.cursor = 'pointer';
}

//// BOUTONS de zoom
function ZOOMBoutonControl() { }
ZOOMBoutonControl.prototype = new GControl();
ZOOMBoutonControl.prototype.initialize = function(map) {

    var containerZOOM = document.createElement('div');

    var boutonRestauration = document.createElement('div');
    boutonRestauration.setAttribute("id", "pan_restore");
    var imgPanR = document.createElement('img');
    imgPanR.setAttribute('src', iconeDir + "button_replacement.png");
    boutonRestauration.appendChild(imgPanR);
    GEvent.addDomListener(boutonRestauration, 'click', function() {
        map.returnToSavedPosition();
        slider.set(zoomLvl);
    });
    document.getElementById('navMoveCenter').appendChild(boutonRestauration);

    var boutonPanRight = document.createElement('div');
    boutonPanRight.setAttribute("id", "pan_r");
    var imgPanR = document.createElement('img');
    imgPanR.setAttribute('src', iconeDir + "button_droit.png");
    boutonPanRight.appendChild(imgPanR);
    GEvent.addDomListener(boutonPanRight, 'click', function() {
        map.panDirection(-1, 0);
    });
    document.getElementById('navMoveRight').appendChild(boutonPanRight);

    var boutonPanLeft = document.createElement('div');
    boutonPanLeft.setAttribute("id", "pan_l");
    var imgPanR = document.createElement('img');
    imgPanR.setAttribute('src', iconeDir + "button_left.png");
    boutonPanLeft.appendChild(imgPanR);
    GEvent.addDomListener(boutonPanLeft, 'click', function() {
        map.panDirection(+1, 0);
    });
    document.getElementById('navMoveLeft').appendChild(boutonPanLeft);

    var boutonPanUp = document.createElement('div');
    boutonPanUp.setAttribute("id", "pan_u");
    var imgPanR = document.createElement('img');
    imgPanR.setAttribute('src', iconeDir + "button_top.png");
    boutonPanUp.appendChild(imgPanR);
    GEvent.addDomListener(boutonPanUp, 'click', function() {
        map.panDirection(0, +1);
    });
    document.getElementById('navMoveUp').appendChild(boutonPanUp);

    var boutonPanDown = document.createElement('div');
    boutonPanDown.setAttribute("id", "pan_d");
    var imgPanR = document.createElement('img');
    imgPanR.setAttribute('src', iconeDir + "button_down.png");
    boutonPanDown.appendChild(imgPanR);
    GEvent.addDomListener(boutonPanDown, 'click', function() {
        map.panDirection(0, -1);
    });
    document.getElementById('navMoveDown').appendChild(boutonPanDown);

    var boutonZoomPlus = document.createElement('div');
    boutonZoomPlus.setAttribute("id", "btn_plus");
    var imgPanR = document.createElement('img');
    imgPanR.setAttribute('src', iconeDir + "button_plus.png");
    boutonZoomPlus.appendChild(imgPanR);
    GEvent.addDomListener(boutonZoomPlus, 'click', function() {
        if (map.getZoom() + 1 <= maxGMapZoom) {
            map.zoomIn();
            //alert(maxGMapZoom);
            slider.set(map.getZoom() - minGMapZoom);
        }
    });
    document.getElementById('navMovePlus').appendChild(boutonZoomPlus);

    var boutonZoomMoins = document.createElement('div');
    boutonZoomMoins.setAttribute("id", "btn_moins");
    var imgPanR = document.createElement('img');
    imgPanR.setAttribute('src', iconeDir + "button_moins.png");
    boutonZoomMoins.appendChild(imgPanR);
    GEvent.addDomListener(boutonZoomMoins, 'click', function() {
        if (map.getZoom() - 1 >= minGMapZoom) {
            map.zoomOut();
            //alert(map.getZoom());
            slider.set(map.getZoom() - minGMapZoom);
        }
    });
    document.getElementById('navMoveMoins').appendChild(boutonZoomMoins);

    var slideArea = document.createElement('div');
    slideArea.setAttribute("id", "area");
    var slideKnob = document.createElement('div');
    slideKnob.setAttribute("id", "knob");
    slideArea.appendChild(slideKnob);
    var imgPanR = document.createElement('img');
    imgPanR.setAttribute('src', iconeDir + "button_slide.png");
    slideKnob.appendChild(imgPanR);

    slideArea.style.backgroundImage = "url('" + iconeDir + "slide_hori.png')";

    document.getElementById('navMoveArea').appendChild(slideArea);

    // Create the new slider instance
    slider = new Slider('area', 'knob', {
        steps: (maxGMapZoom - minGMapZoom), // There are 35 steps
        range: (maxGMapZoom-minGMapZoom), // Minimum value is 8
        onChange: function(value) {
        map.setZoom(value + minGMapZoom);
        }
    }).set( map.getZoom() );
    zoomSaved = map.getZoom();

    return containerZOOM;
}

ZOOMBoutonControl.prototype.setButtonStyle_Zoom_ = function(button, style) {
    switch (style) {
        //Bouton de replacement 
        case 0:
            button.style.height = '16px';
            button.style.width = '16px';
            break;
        case 1:
            button.style.height = '16px';
            button.style.width = '16px';
            break;
        case 2:
            button.style.height = '16px';
            button.style.width = '16px';
            break;
        case 3:
            button.style.height = '16px';
            button.style.width = '16px';
            break;
        case 4:
            button.style.height = '16px';
            button.style.width = '16px';
            break;

        //Bouton de Zoom 
        case 5:
            button.style.height = '4px';
            button.style.width = '12px';
            break;
        case 6:
            button.style.height = '12px';
            button.style.width = '12px';
            break;
        case 7:
            button.style.background = "url('"+ iconeDir + "slide_hori.png')";
            button.style.height = '4px';
            button.style.width = '100px';
            break;
        case 8:
            button.style.height = '18px';
            button.style.width = '25px';
            break;
    }
    button.style.cursor = 'pointer';
}
ZOOMBoutonControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}
