


 



// MAP types
function Marker(name, link, isGroup, zoomLevel, longitude, latitude, zipCode, city){

  this.name = name;
  this.link = link;
  this.isGroup = isGroup;
  this.zoomLevel = zoomLevel;
  this.longitude = longitude;
  this.latitude = latitude;
  this.zipCode = zipCode;
  this.city = city;
  this.points = new Array();

  this.addPoint = function(latitude, longitude){
	
	if (this.points == null){
		this.points = new Array();			 
	}
        var index = this.points.length;
	this.points[index] = new Array();		
        this.points[index][0]=longitude;
	this.points[index][1]=latitude;	
  }

}


    var bdMarker = null;
    var bdMarkerTab = new Array();

    var map;
    var mgr;
    var geocoder;
    var icon;
    var iconBd;
    var iconBdGroup;
    var centerPoint;
    var addressNotFound;


    function loadMap() {
      

      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));



	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GScaleControl());
	//map.addControl(new GOverviewMapControl());
	geocoder = new GClientGeocoder();
	var markers = [];
	var markersBd = [];

	icon = new GIcon();
	icon.image = "/configuration/images/map/astron_icon.gif";
	//icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	icon.iconSize = new GSize(12, 12);
	//icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);

	iconBd = new GIcon();
	iconBd.image = "/configuration/images/map/astron_icon_bd.gif";
	//iconBd.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconBd.iconSize = new GSize(27, 19);
	//iconBd.shadowSize = new GSize(22, 20);
	iconBd.iconAnchor = new GPoint(6, 20);
	iconBd.infoWindowAnchor = new GPoint(5, 1);


	iconBdGroup = new GIcon();
	iconBdGroup.image = "/configuration/images/map/astron_icon_bd_group.gif";
	iconBdGroup.iconSize = new GSize(35, 30);
	iconBdGroup.iconAnchor = new GPoint(6, 20);
	iconBdGroup.infoWindowAnchor = new GPoint(5, 1);

	iconBd1 = new GIcon();
	iconBd1.image = "/configuration/images/map/astron_icon_bd_1.gif";
	//iconBd1.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconBd1.iconSize = new GSize(29, 23);
	//iconBd1.shadowSize = new GSize(22, 20);
	iconBd1.iconAnchor = new GPoint(6, 20);
	iconBd1.infoWindowAnchor = new GPoint(5, 1);





        //showAddress('Hambourg Germany', null, null, true, false, 3, false );


      }
    }

  
        function zoom(zoom){
          if (addressNotFound){
            alert("Impossible de trouver l'adresse du Bâtisseur");
          }
          else {
            map.setCenter(centerPoint, zoom);
          }
        }


        // USED IN THE BUILDER PAGE
        function showBdPoint(name, longitude, latitude, zoom){
           var point = new GLatLng(latitude, longitude);
           map.setCenter(point,zoom);

           var marker = new GMarker(point, iconBd1);
           map.addOverlay(marker);

           var tabs = new Array();
           var tab = new GInfoWindowTab("label", "<div style='background-color:white; '><img src='/configuration/images/map/astron_logo_map.jpg' align='left'> Bâtisseur agréé Lindab<br/>société: <b>" + name + "</b><br/></div>" );
	   tabs[0] = tab;
           var opts = {pixelOffset:new GSize(15,-20)}; 
           marker.openInfoWindowTabs(tabs,opts);

           GEvent.clearListeners(map.getInfoWindow(),'closeclick'); 
        }



        function createEventOnMarker(marker, index){
               marker.value = index;
               GEvent.addListener(marker, "mouseover", function() {
                  
	  	  //map.setCenter(marker.getPoint(), 12);
           	  var tabs = new Array();
                  var tab = new GInfoWindowTab("label", "<div style='background-color:white'><table><tr><td><img src='/configuration/images/map/astron_logo_map.jpg' align='left'/></td><td>Bâtisseur agréé Lindab<br/>société: <b><a href='"+ bdMarkerTab[index].link + "'>" + bdMarkerTab[index].name + "</a></b><br/>"+bdMarkerTab[index].zipCode+" "+bdMarkerTab[index].city+"</td></tr></table></div>" );
	          tabs[0] = tab;
                  var opts = {pixelOffset:new GSize(15,-20)}; 
                  map.openInfoWindowTabs(marker.getPoint(), tabs, opts);

               });

               GEvent.addListener(marker, "click", function() {
	          window.location.href=bdMarkerTab[index].link;
               }); 	

               GEvent.addListener(marker, "mouseout", function() {
		  //map.getInfoWindow().hide();
	       });
        }

        function zoomOnGroup(index){
	          map.getInfoWindow().hide(); 
                  var bounds = new GLatLngBounds();
                  for (j=0; j<bdMarkerTab[index].points.length; j++){
                      var point = new GLatLng(bdMarkerTab[index].points[j][0],bdMarkerTab[index].points[j][1]);  
                      bounds.extend(point);
                  }

	          var newZoom = map.getBoundsZoomLevel(bounds);
                  if (!(newZoom == (map.getZoom()+1)))
                     newZoom--;
  
                  map.setZoom(newZoom);
                  map.setCenter(bounds.getCenter());

        }

        function createEventOnMarkerGroup(marker, index){
               marker.value = index;
               GEvent.addListener(marker, "click", function() {
                  
                  map.getInfoWindow().hide(); 

                  var bounds = new GLatLngBounds();
                  for (j=0; j<bdMarkerTab[index].points.length; j++){
                      var point = new GLatLng(bdMarkerTab[index].points[j][0],bdMarkerTab[index].points[j][1]);  
                      bounds.extend(point);
                  }

		  var newZoom = map.getBoundsZoomLevel(bounds);
		  if (!(newZoom == (map.getZoom()+1)))
                     newZoom--;

                  map.setZoom(newZoom);
                  map.setCenter(bounds.getCenter());

               });

               GEvent.addListener(marker, "mouseover", function() {
                  
           	  var tabs = new Array();
                  var tab = new GInfoWindowTab("label", "<div style='background-color:white'><img src='/configuration/images/map/astron_logo_map.jpg' align='left'>Several dealers located in this area<br/><a href='javascript:zoomOnGroup("+index+")'>Click here to zoom</a></b><br/></div>" );
	          tabs[0] = tab;
	          var opts = {pixelOffset:new GSize(15,-20)}; 
                  map.openInfoWindowTabs(marker.getPoint(), tabs, opts);

               });

               GEvent.addListener(marker, "mouseout", function() {
		  //map.getInfoWindow().hide();
	       });
        }

        function showBdPointOverviewOnMap(){

          if (map==null){
             window.setTimeout("showBdPointOverviewOnMap()",1000);
	     return;
          }


          for (i=0; i<bdMarkerTab.length;i++){

             var marker = bdMarkerTab[i];

             var point = new GLatLng(marker.latitude, marker.longitude);           

             var myIcon; 
             if (marker.isGroup)
               myIcon = iconBdGroup;
             else           
               myIcon = iconBd1;

             var bdMarker1 = new GMarker(point, myIcon);
             //bdMarkerTab[index]=bdMarker1;
           
             mgr.addMarker(bdMarker1, marker.zoomLevel, marker.zoomLevel);

             if (!marker.isGroup) {

               var markerIndex = i;
               createEventOnMarker(bdMarker1,markerIndex);

             }  
             else {
               var markerIndex = i;
               createEventOnMarkerGroup(bdMarker1,markerIndex);

             }          

          }

          mgr.refresh();


        } 



        function showCountry(id, name, longitude, latitude, zoom, isCenter, displayMarker){
           var point = new GLatLng(latitude, longitude);

           if (isCenter){
             map.setCenter(point,zoom);
           }

           if (displayMarker) {
             var marker = new GMarker(point, icon);
             map.addOverlay(marker);           
           

             var tabs = new Array();
	     var tab = new GInfoWindowTab("label", "<div style='background-color:white'>" + name + "<br/><br/><br/><br/></div>" );
	     tabs[0] = tab;

    	     GEvent.addListener(marker, "mouseover", function() {
             marker.openInfoWindowTabs(tabs);
	     });
       	
             GEvent.addListener(marker, "mouseout", function() {
		map.getInfoWindow().hide();
	     });

	     GEvent.addListener(marker, "click", function() {
	  	//map.setCenter(marker.getPoint(),zoomCountry);
		window.location.href="/contact/carte-batisseurs.html?country="+id;
	     });	
           }

        }

	
        // USED IN THE ASTRON CONTACT PAGE	
   	function showContactAddress (flagimg, company, address1, address2, address3, address4, phone, fax, email, webSite, latitude, longitude) {

           var point = new GLatLng(latitude, longitude);
           map.setCenter(point, 12);           

	   var iconContact = new GIcon();
	   iconContact.image = flagimg;
  	   iconContact.iconSize = new GSize(18, 12);
	   iconContact.iconAnchor = new GPoint(6, 20);
	   iconContact.infoWindowAnchor = new GPoint(5, 1);

           contactMarker = new GMarker(point, iconContact);
           map.addOverlay(contactMarker);

           var tabs = new Array();

           var tabcontent;
           tabcontent = "<div style='background-color:white'><img src='/configuration/images/map/astron_logo_map.jpg' align='left'>";
           tabcontent += company;
           tabcontent += address1;
           tabcontent += address2;
           tabcontent += address3;
           tabcontent += address4;
           tabcontent += phone;
           tabcontent += fax;
           tabcontent += email;
           tabcontent += webSite;

           var tab = new GInfoWindowTab("label", tabcontent );
	   tabs[0] = tab;
           contactMarker.openInfoWindowTabs(tabs);

           GEvent.clearListeners(map.getInfoWindow(),'closeclick'); 
        }


	

	function displayPoints(){

          if (map==null){
             window.setTimeout("displayPoints()",1000);
          }
          else {
           var pointEurope = new GLatLng(53.556626, 9.992065);
           map.setCenter(pointEurope, 3);      


showCountry('36','Algérie', 2.329102,  29.152161, 5, false, true);
showCountry('31','Allemagne', 9.810791,  50.951506, 6, false, true);
showCountry('20','Autriche', 13.337402,  47.694974, 6, false, true);
showCountry('2','Belgique', 4.630737,  50.724286, 7, false, true);
showCountry('3','Bosnie-Herzégovine', 17.764893,  43.350000, 7, false, true);
showCountry('4','Bulgarie', 25.246582,  41.926803, 6, false, true);
showCountry('1','Bélarus', 27.953389,  53.709807, 6, false, true);
showCountry('38','Congo', 15.15,  1, 6, false, true);
showCountry('10','Croatie', 16.36799,  45.47599, 6, false, true);
showCountry('6','Danemark', 10.371094,  55.615589, 6, false, true);
showCountry('8','Espagne', -3.647461,  40.027614, 5, false, true);
showCountry('7','Estonie', 25.916748,  58.699776, 6, false, true);
showCountry('32','France', 2.390213,  47.082748, 5, false, true);
showCountry('17','Hongrie', 19.503304,  46.900000, 6, false, true);
showCountry('11','Irlande', -7.866211,  53.14677, 6, false, true);
showCountry('12','Islande', -19.020835,  64.963051, 5, false, true);
showCountry('13','Italie', 12.612305,  42.972502, 5, false, true);
showCountry('35','Kazakhstan', 65.917969,  51.890054 , 4, false, true);
showCountry('14','Lettonie', 25.180664,  56.956957, 6, false, true);
showCountry('15','Lituanie', 23.994141,  55.241552, 6, false, true);
showCountry('16','Luxembourg', 6.166077,  49.601811, 8, false, true);
showCountry('37','Moldavie', 28.707275,  47.129951 , 7, false, true);
showCountry('34','Monténégro', 19.105225,  42.85986 , 8, false, true);
showCountry('19','Norvège', 10.393066,  63.435774, 4, false, true);
showCountry('18','Pays-Bas', 5.778809,  52.247983, 7, false, true);
showCountry('21','Pologne', 19.335938,  51.957807, 6, false, true);
showCountry('23','Roumanie', 25.353699,  45.823057, 5, false, true);
showCountry('9','Royaume-Uni', -3.955078,  54.41893, 5, false, true);
showCountry('24','Russie', 37.683105,  55.776573, 2, false, true);
showCountry('5','République tchèque', 15.472962,  49.817492, 6, false, true);
showCountry('26','Slovaquie', 19.699024,  48.669026, 6, false, true);
showCountry('25','Slovénie', 15.029297,  46.111326, 7, false, true);
showCountry('27','Suisse', 8.227512,  46.505954, 7 , false, true);
showCountry('28','Suède', 19.511719,  63.548552, 4, false, true);
showCountry('30','Ukraine', 31.640625,  48.545705, 5, false, true);


          } // end else

        }
	


