var map;
var addressBar;


function init() {
   var mapOptions = {
      center: new google.maps.LatLng(43.020054,-83.693008),
      zoom: 9,
      mapTypeId: 'roadmap',
   };

   map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

   // a new Info Window is created
   addressBar = new google.maps.InfoWindow();

   // close the Info Window with a click on the map
   google.maps.event.addListener(map, 'click', function() {
      addressBar.close();
   });
	
   
	// function called to create markers
   addAdressesToMap();
	
}
google.maps.event.addDomListener(window, 'load', init);





function addAdressesToMap(){
	var addresses = firebase.database().ref('Resources').orderByKey();
	addresses.once('value', function(snapshot){
  	var addressArray = new Array();
  	snapshot.forEach(function(childSnapshot){
  	var addr = childSnapshot.key;
  	var childData = addr;
  	addressArray.push(childData);
  })
  createmap(addressArray);  
})
  
}

function createmap(aArray){
	var bounds = new google.maps.LatLngBounds();
	for (var i = 0; i < aArray.length; i++){
	  var ref1 = firebase.database().ref('Resources').child(aArray[i]);
	  ref1.once('value', function(snapshot){
      var refval = snapshot.val();
      var address = refval.address;
	  
	  var lat = refval.lat;
	  var lng = refval.lng;
      var name = refval.name;
      var phone = refval.phone;
	  var service = refval.service;
	  var latlng = new google.maps.LatLng(lat, lng); 
	  bounds.extend(latlng);
	  createMarker(latlng, name, address, phone, service)
	  map.fitBounds(bounds);
	  })
	  }
	  
    
  
}

// creates marker and set Info Window content
function createMarker(latlng, name, address, phone, service){
    //if (latlng ===""){
	if (service ==="office space"){
		   var marker = new google.maps.Marker({
			  map: map,
			  position: latlng,
			  title: name,
			  icon: "img/GMM/office space.png"
		   });
   	}
		else if (service ==="real estate assistance"){
			var marker = new google.maps.Marker({
			  map: map,
			  position: latlng,
			  title: name,
			  icon: "img/GMM/real estate.png"
		   });
		}
		else if (service ==="kitchen/market"){
			var marker = new google.maps.Marker({
			  map: map,
			  position: latlng,
			  title: name,
			  icon: "img/GMM/kitchen.png"
		   });
		}
		else if (service ==="maker space"){
			var marker = new google.maps.Marker({
			  map: map,
			  position: latlng,
			  title: name,
			  icon: "img/GMM/maker space.png"
		   });
		}
		else if (service === "funding"){
			var marker = new google.maps.Marker({
				  map: map,
				  position: latlng,
				  title: name,
				  icon: "img/GMM/funding.png"
			   });
		}
		else if (service ==="professional services"){	   
			var marker = new google.maps.Marker({
				  map: map,
				  position: latlng,
				  title: name,
				  icon: "img/GMM/pro service.png"
			   });
		}
		else if (service === "workshops/competitions"){
			var marker = new google.maps.Marker({
				  map: map,
				  position: latlng,
				  title: name,
				  icon: "img/GMM/workshop.png"
			   });
		}
		else{
			var marker = new google.maps.Marker({
				  map: map,
				  position: latlng,
				  title: name,
				  icon: "img/GMM/contract.png"
			   });
                }
   //}		   
   //click on a marker
   google.maps.event.addListener(marker, 'click', function() {
      
      //insert info to addressBar
      var iwContent = '<div id="iw_container">' +
            '<div class="iw_title">' + name + '</div>' +
         '<div class="iw_content">' + address + '<br />' +
         phone + '<br />' + '<br />' +
         latlng +
         service +'</div></div>';
      
      // including content to the Info Window.
      addressBar.setContent(iwContent);

      // open the Info Window at the current marker location.
      addressBar.open(map, marker);
   });
}

@@ -1994,16 +1994,17 @@
 );%0D%0A   %09
+%09
 %7D%0D%0A%09%09els
@@ -3413,16 +3413,19 @@
 marker%0D%0A
+   
    googl
@@ -3720,26 +3720,17 @@
 r /%3E' + 
-'%3Cbr /%3E' +
+ 
 %0D%0A      
@@ -3740,16 +3740,27 @@
 latlng +
+ '%3Cbr /%3E' +
 %0D%0A      

Update resourcemap.js