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 type = refval.type;
	  var latlng = new google.maps.LatLng(lat, lng); 
	  bounds.extend(latlng);
	  createMarker(latlng, name, address, phone, type)
	  map.fitBounds(bounds);
	  })
	  }
	  
    
  
}

// creates marker and set Info Window content
function createMarker(latlng, name, address, phone, type){
   if (type ==="Office Space"){
		   var marker = new google.maps.Marker({
			  map: map,
			  position: latlng,
			  title: name,
			  icon: "img/GMM/space.png"
		   });
   }
		else if (type ==="Business Consultation"){
			var marker = new google.maps.Marker({
			  map: map,
			  position: latlng,
			  title: name,
			  icon: "img/GMM/Business Consultation.png"
		   });
		}
		else if (type === "Business Resource"){
			var marker = new google.maps.Marker({
				  map: map,
				  position: latlng,
				  title: name,
				  icon: "img/GMM/financial.png"
			   });
		}
		else if (type ==="Information Resource"){	   
			var marker = new google.maps.Marker({
				  map: map,
				  position: latlng,
				  title: name,
				  icon: "img/GMM/Information.png"
			   });
		}
		else if (type === "Legal"){
			var marker = new google.maps.Marker({
				  map: map,
				  position: latlng,
				  title: name,
				  icon: "img/GMM/legal.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 + '</div></div>';
      
      // including content to the Info Window.
      addressBar.setContent(iwContent);

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

@@ -1786,16 +1786,16 @@
 ===%22
-O
+o
 ffice 
-S
+s
 pace
@@ -1970,37 +1970,38 @@
 ype ===%22
-Business Consultation
+real estate assistance
 %22)%7B%0D%0A%09%09%09
@@ -2186,25 +2186,15 @@
 == %22
-Business Resource
+funding
 %22)%7B%0D
@@ -2375,28 +2375,29 @@
 ===%22
-Information Resour
+professional servi
 ce
+s
 %22)%7B%09
@@ -2585,13 +2585,30 @@
 == %22
-Legal
+workshops/competitions
 %22)%7B%0D

Update resourcemap.js