// JavaScript Document - Radovan Miholjcic
var map;
var southWest;
var northEast;
function initialize() {
   var myLatlng = new google.maps.LatLng(46.7838, 8.17);

   var myOptions = {
      zoom: 4,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP //mapTypeId: google.maps.MapTypeId.SATELLITE
   }

	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


	// Add 5 markers to the map at random locations
	southWest = new google.maps.LatLng(47.38432269266178, 7.422222656250009);
	northEast = new google.maps.LatLng(46.28356246774826, 8.124371093750009);
	var bounds = new google.maps.LatLngBounds(southWest,northEast);

	map.fitBounds(bounds);
	first=0;
	last=entreprises.length;
	document.write("<option value=\" \" SELECTED > </option> "); 
	
  for (var i = first; i < last; i++) {
    	var location = new google.maps.LatLng(entreprises[i].locationsLat,entreprises[i].locationsLng);
    	var marker = new google.maps.Marker({
        	position: location, 
        	map: map, 
			title: "Réseau plasturgie - Partenaires" 
    	});

    	var numImage=entreprises[i].partenaireType;
    	marker.setTitle(entreprises[i].nom);
    	// NOTE you can also change the marker's icon
    	marker.setIcon(markerImage[numImage]);
    	attachSecretMessage(marker, i);
		
	document.write("<option value=\""+i+"\""); 
	//if(i==0){document.write(" SELECTED ");}
	document.write(" >"+entreprises[i].nom+"</option> "); 
	
  }
}
 

// The five markers show a secret message when clicked
// but that message is not within the marker's instance data

function attachSecretMessage(marker, number) {
  var infowindow = new google.maps.InfoWindow(
      { 
	  
	  content: entreprises[number].html
       //, size: new google.maps.Size(175,180)
	});
  google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
  });
}
function zoomToPoint() { 
  var point = new google.maps.LatLng(entreprises[mode.value].locationsLat,entreprises[mode.value].locationsLng); 
  map.setCenter(point); 
    map.setZoom(17); 
}
function zoomOut(nr) { 
  var point = new google.maps.LatLng(entreprises[nr].locationsLat,entreprises[nr].locationsLng); 
  map.setCenter(point); 
    map.setZoom(7); 
}

