var mapCenterX = 447221;
var mapCenterY = 2178268;
var mapCenterZ = 11;
var GoogleMap;
var MAX_ZOOM = 19;

function MapCenter(pf_LamberX, pf_LamberY, pi_scale){
	la_Result = Lamb_WGS84(parseFloat(pf_LamberX), parseFloat(pf_LamberY));
	GoogleMap.setCenter(new GLatLng(parseFloat(la_Result[1]), parseFloat(la_Result[0])), parseInt(pi_scale));
}

//START CUSTOMIZED CONTROL MAP BUTTON

	/* 1. Declaration de la fonction */
	function CustomMapControl() {}

	/* 2. Definition de l'objet 'prototype' comme une instance de l'objet GControl() */
	CustomMapControl.prototype = new GControl();

	/* 3. Creation du 'container', des boutons et des evenements */
	CustomMapControl.prototype.initialize = function(GoogleMap) {
		var container = document.createElement("div");

		//creation bouton Plan
		var CustomMapPlan = document.createElement("div");
		this.setButtonStyle_(CustomMapPlan);
		CustomMapPlan.setAttribute('title','Afficher un plan de ville');
		container.appendChild(CustomMapPlan);
        CustomMapPlan.innerHTML = 'Plan';
        GEvent.addDomListener(CustomMapPlan, "click", function() {
			GoogleMap.setMapType(G_NORMAL_MAP);
			MAX_ZOOM = 19;
        });
		//creation bouton satellite
		var CustomMapSatellite = document.createElement("div");
		this.setButtonStyle_(CustomMapSatellite);
		CustomMapSatellite.setAttribute('title','Afficher les images satellite');
		container.appendChild(CustomMapSatellite);
        CustomMapSatellite.innerHTML = 'Satellite';
        GEvent.addDomListener(CustomMapSatellite, "click", function() {
			GoogleMap.setMapType(G_SATELLITE_MAP);
			MAX_ZOOM = 19;
        });
		//creation bouton Mixte
		var CustomMapMixte = document.createElement("div");
		this.setButtonStyle_(CustomMapMixte);
		CustomMapMixte.setAttribute('title','Afficher les images satellite avec le nom des rues');
		container.appendChild(CustomMapMixte);
        CustomMapMixte.innerHTML = 'Mixte';
        GEvent.addDomListener(CustomMapMixte, "click", function() {
			GoogleMap.setMapType(G_HYBRID_MAP);
			MAX_ZOOM = 19;
        });
		//creation bouton Relief
		/*var CustomMapRelief = document.createElement("div");
		this.setButtonStyle_(CustomMapRelief);
		CustomMapRelief.setAttribute('title','Afficher le relief sur la carte');
		container.appendChild(CustomMapRelief);
        CustomMapRelief.innerHTML = 'Relief';
        GEvent.addDomListener(CustomMapRelief, "click", function() {
			GoogleMap.setMapType(G_PHYSICAL_MAP);
			MAX_ZOOM = 15;
        });*/

		GoogleMap.getContainer().appendChild(container);
        return container;
    }

	/* 4. Positionnement du container */
	CustomMapControl.prototype.getDefaultPosition = function() {
		return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 5));
    }

	/* 5. Definition du style des boutons */
	CustomMapControl.prototype.setButtonStyle_ = function(button) {
		button.style.cssFloat = "left";
        button.style.cursor = "pointer";
		button.style.background = "#FC7905";
		button.style.padding = "0px";
		button.style.width = "70px";
		button.style.textAlign = "center";
		button.style.color = "#FFFFFF";
		button.style.fontSize = "12px";
		button.style.fontWeight = "bold";
		button.style.border = "1px solid #959E21";
	}

//END CUSTOMIZED CONTROL MAP BUTTON



//***************************************
//***** START CUSTOMIZED GLargeMapControl
//***************************************

// == Some global variables ==
	var Y_SLIDER_LENGTH = 136; // maximum length that the cursor can move (slide height minus cursor height)
    //var MAX_ZOOM = 17;
	var IMG_PATH = urlImage+"/GoogleMapCustom/";

    // == Create a Custom GControl ==
    function CustomGLargeMapControl() { }
    CustomGLargeMapControl.prototype = new GControl();

    // == This function positions the slider to match the specified zoom level ==
    CustomGLargeMapControl.prototype.setSlider = function(zoom) {
		var top = Math.round(Y_SLIDER_LENGTH-Y_SLIDER_LENGTH/MAX_ZOOM*zoom);
		var topZoom = Math.round(Y_SLIDER_LENGTH/MAX_ZOOM*zoom);
        this.slide.top = top;
        this.cursorContainer.style.top = top+"px";
    }

    // == This function reads the slider and sets the zoom level ==
	CustomGLargeMapControl.prototype.setZoom = function() {
        var z=Math.round(this.slide.top*MAX_ZOOM/Y_SLIDER_LENGTH);
        this.map.setZoom(MAX_ZOOM-z);
    }


    // == This gets called bu the API when addControl(new CustomGLargeMapControl()) is used ==
    CustomGLargeMapControl.prototype.initialize = function(map) {
        // obtain Function Closure on a reference to "this"
        var that=this;
        // store a reference to the map so that we can call setZoom() on it
        this.map = map;

		var mainContainer = document.createElement("div");
		this.setMainContainerStyle_(mainContainer);


		// panningControls
		var panningControls = document.createElement("div");
		this.setPanningControlsStyle_(panningControls);
		mainContainer.appendChild(panningControls);

		// Creation bouton panUp
		var panUp = document.createElement("div");
		panUp.setAttribute('title','D\351placer vers le haut');
        panningControls.appendChild(panUp);
		this.setPanUpStyle_(panUp);
        GEvent.addDomListener(panUp, "click", function() {
			map.panDirection(0,1);
        });

		// Creation bouton panDown
		var panDown = document.createElement("div");
		panDown.setAttribute('title','D\351placer vers le bas');
        panningControls.appendChild(panDown);
		this.setPanDownStyle_(panDown);
        GEvent.addDomListener(panDown, "click", function() {
			map.panDirection(0,-1);
        });

		// Creation bouton panLeft
		var panLeft = document.createElement("div");
		panLeft.setAttribute('title','D\351placer vers la gauche');
        panningControls.appendChild(panLeft);
		this.setPanLeftStyle_(panLeft);
        GEvent.addDomListener(panLeft, "click", function() {
			map.panDirection(1,0);
        });

		// Creation bouton panRight
		var panRight = document.createElement("div");
		panRight.setAttribute('title','D\351placer vers la droite');
        panningControls.appendChild(panRight);
		this.setPanRightStyle_(panRight);
        GEvent.addDomListener(panRight, "click", function() {
			map.panDirection(-1,0);
        });

		// creation bouton panCenter
		var panCenter = document.createElement("div");
		panCenter.setAttribute('title','Revenir au r\351sultat initial');
		this.setPanCenterStyle_(panCenter);
		panningControls.appendChild(panCenter);
        GEvent.addDomListener(panCenter, "click", function() {
			MapCenter(mapCenterX,mapCenterY,mapCenterZ);
        });

		// Creation bouton ZoomIn
		var zoomIn = document.createElement("div");
		this.setZoomInStyle_(zoomIn);
		zoomIn.setAttribute('title','Zoom avant');
		mainContainer.appendChild(zoomIn);
		GEvent.addDomListener(zoomIn, "click", function() {
			map.zoomIn();
		});

		// Creation bouton ZoomOut
		var zoomOut = document.createElement("div");
		this.setZoomOutStyle_(zoomOut);
		zoomOut.setAttribute('title','Zoom arri\350re');
		mainContainer.appendChild(zoomOut);
		GEvent.addDomListener(zoomOut, "click", function() {
			map.zoomOut();
		});

		// zoomSlider
		var zoomSlider = document.createElement("div");
		this.setZoomSliderStyle_(zoomSlider);
		mainContainer.appendChild(zoomSlider);

		// zoom cursor
		this.cursorContainer = document.createElement("div");
		this.cursorContainer.setAttribute("title","Faites glisser le curseur pour zoomer");
		this.setCursorContainerStyle_(this.cursorContainer);
		zoomSlider.appendChild(this.cursorContainer);

        this.slide=new GDraggableObject(this.cursorContainer, {container:zoomSlider});

        // Listen for other things changing the zoom level and move the slider
        GEvent.addListener(map, "zoomend", function(a,b) {that.setSlider(b)});

        // Listen for the slider being moved and set the zoom level
        GEvent.addListener(this.slide, "dragend", function() {that.setZoom()});


        map.getContainer().appendChild(mainContainer);
		return mainContainer;
    }

	// == Set the default position for the customized GLargeMapControl ==
	CustomGLargeMapControl.prototype.getDefaultPosition = function() {
		return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5,5));
    }

	//mainContainer style
	CustomGLargeMapControl.prototype.setMainContainerStyle_ = function(button) {
        button.style.height = "256px";
		button.style.overflow = "hidden";
		button.style.position = "absolute";
		button.style.border = "0px solid black";
		button.style.left = "100px";
		button.style.textAlign = "left";
		button.style.top = "55px";
		button.style.width = "59px";
	}

	//panningControls style
	CustomGLargeMapControl.prototype.setPanningControlsStyle_ = function(button){
		button.style.height = "62px";
		button.style.left = "0";
		button.style.position = "absolute";
		button.style.top = "0";
		button.style.width = "59px";
	}

	//panUp style
	CustomGLargeMapControl.prototype.setPanUpStyle_ = function(button) {
		button.style.backgroundImage = "url('" + IMG_PATH + "panup.gif')";
		button.style.backgroundPosition = "center center";
		button.style.backgroundRepeat = "no-repeat";
		button.style.cursor = "pointer";
        button.style.height = "18px";
		button.style.left = "20px";
		button.style.position = "absolute";
		button.style.top = "0px";
        button.style.width = "18px";
	}

	//panDown style
	CustomGLargeMapControl.prototype.setPanDownStyle_ = function(button) {
		button.style.backgroundImage = "url('" + IMG_PATH + "pandown.gif')";
		button.style.backgroundPosition = "center center";
		button.style.backgroundRepeat = "no-repeat";
		button.style.cursor = "pointer";
        button.style.height = "18px";
		button.style.left = "20px";
		button.style.position = "absolute";
		button.style.top = "40px";
        button.style.width = "18px";
	}

	//panLeft style
	CustomGLargeMapControl.prototype.setPanLeftStyle_ = function(button) {
		button.style.backgroundImage = "url('" + IMG_PATH + "panleft.gif')";
		button.style.backgroundPosition = "center center";
		button.style.backgroundRepeat = "no-repeat";
		button.style.cursor = "pointer";
        button.style.height = "18px";
		button.style.left = "0px";
		button.style.position = "absolute";
		button.style.top = "20px";
        button.style.width = "18px";
	}

	//panRight style
	CustomGLargeMapControl.prototype.setPanRightStyle_ = function(button) {
		button.style.backgroundImage = "url('" + IMG_PATH + "panright.gif')";
		button.style.backgroundPosition = "center center";
		button.style.backgroundRepeat = "no-repeat";
		button.style.cursor = "pointer";
        button.style.height = "18px";
		button.style.left = "40px";
		button.style.position = "absolute";
		button.style.top = "20px";
        button.style.width = "18px";
	}

	//panCenter style
	CustomGLargeMapControl.prototype.setPanCenterStyle_ = function(button) {
		button.style.backgroundImage = "url('" + IMG_PATH + "pancenter.gif')";
		button.style.backgroundPosition = "center center";
		button.style.backgroundRepeat = "no-repeat";
		button.style.cursor = "pointer";
        button.style.height = "18px";
		button.style.left = "20px";
		button.style.position = "absolute";
		button.style.top = "20px";
        button.style.width = "18px";
	}

	//ZoomIn style
	CustomGLargeMapControl.prototype.setZoomInStyle_ = function(button) {
		button.style.backgroundImage = "url('" + IMG_PATH + "zoomin.gif')";
		button.style.backgroundPosition = "center center";
		button.style.backgroundRepeat = "no-repeat";
		button.style.cursor = "pointer";
        button.style.height = "17px";
		button.style.left = "20px";
		button.style.position = "absolute";
		button.style.top = "65px";
        button.style.width = "17px";
	}

	//ZoomOut style
	CustomGLargeMapControl.prototype.setZoomOutStyle_ = function(button) {
		button.style.backgroundImage = "url('" + IMG_PATH + "zoomout.gif')";
		button.style.backgroundPosition = "center center";
		button.style.backgroundRepeat = "no-repeat";
		button.style.cursor = "pointer";
        button.style.height = "17px";
		button.style.left = "20px";
		button.style.position = "absolute";
		button.style.top = "238px";
        button.style.width = "17px";
	}

	//ZoomSlider style
	CustomGLargeMapControl.prototype.setZoomSliderStyle_ = function(button){
		button.style.backgroundImage = "url('" + IMG_PATH + "slide.gif')";
		button.style.backgroundPosition = "center top";
		button.style.backgroundRepeat = "no-repeat";
		button.style.cursor = "pointer";
		button.style.height = "150px";
		button.style.left = "20px";
		button.style.position = "absolute";
		button.style.top = "86px";
		button.style.width = "17px";
	}

	//CursorContainer style
	CustomGLargeMapControl.prototype.setCursorContainerStyle_ = function(button){
		button.style.backgroundImage = "url('" + IMG_PATH + "cursor.gif')";
		button.style.backgroundPosition = "center center";
		button.style.backgroundRepeat = "no-repeat";
		button.style.cursor = "url(http://maps.google.com/intl/fr_ALL/mapfiles/openhand.cur), default";
		button.style.height = "14px";
		button.style.left = "0px";
		button.style.overflow = "hidden";
		button.style.position = "absolute";
		button.style.top = "72px";
		button.style.width = "17px";
	}

//*************************************
//***** END CUSTOMIZED GLargeMapControl
//*************************************
