///////////////////////////////////////////////////
//                  MAP                          //
///////////////////////////////////////////////////

//Variable globale
var maMap;

    function initialize() {
        
        var monDivMap = document.getElementById('map');

        // Coordonnées
        var adresse = '2 allée des Moulineaux, Issy les Moulineaux cedex, france';
        var titre = 'OPTIMEGE';
        var contenu = '<p style="color: #000;">2 allée des Moulineaux, <br />92445 Issy les Moulineaux cedex</p>';

        ville = new Array(adresse, titre, contenu);
        
        villes = new Array(ville);
        
        //Config de la map
        var mesOptionsMap = {
            center: new google.maps.LatLng(48.8432838,2.2593706),
            zoom: 10,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            streetViewControl: true
          }

        // Création de la carte
        maMap = new google.maps.Map(
            monDivMap,
            mesOptionsMap
        );

        localisationVille(villes);

    }

    function localisationVille(villes)
    {
        var geocoder = new google.maps.Geocoder();
        var index = 0;
        for (var i = 0; i <= (villes.length-1); i++) {

           geocoder.geocode({'address': villes[i][0]},
           function(results, status) {

              if (status == google.maps.GeocoderStatus.OK) {
                  var pointCourant = results[0].geometry.location;

                 // Création du Marker
                   var monMarker = new google.maps.Marker({
                        // Coordonnées GPS suite à l'adresse'
                        position: pointCourant,
                        map: maMap,
                        title: villes[index][1]
                    });
                    //Ajout de la fenetre d'informations au marqueur
                    var infoBulle = new google.maps.InfoWindow({
                        content: villes[index][2]+'<div id="StreetView" style="overflow: none; width: 200px; height: 100px; text-align:center">Street View en cours de chargement ...</div>'
                    });
                   
                    google.maps.event.addListener(monMarker, 'click', function() {
                        infoBulle.open(maMap,monMarker);
                        document.getElementById("StreetView").innerHTML="";

                        var panoramaOptions = {
                          position: pointCourant,
                          pov: {
                            heading: 0,
                            pitch: 0,
                            zoom: 1                            
                          }
                        };

                        StreetView = new  google.maps.StreetViewPanorama(document.getElementById("StreetView"), panoramaOptions);

                        //StreetView.setPov({heading:30, pitch:0, zoom:4});
                        //StreetView.setPosition(new google.maps.LatLng(pointCourant));
                        //maMap.setStreetView(StreetView);

                    });


                    index++;  

              } else {
                    alert("Geocode was not successful for the following reason: " + status);
              }

            });              
        }
    }



