﻿ var geocoder;
  var map = [];
  var bounds = [];
  var infowindow;

  function initialize_map(id) {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(56, 13);
    var myOptions = {
      zoom: 14, 
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
        navigationControl: true,
        mapTypeControl: false,
        scaleControl: false
    }
    map[id] = new google.maps.Map(document.getElementById(id), myOptions);
    bounds[id] = new google.maps.LatLngBounds();
    infowindow = new google.maps.InfoWindow({ content: "" });
  }

  function codeAddress(id, address, name, url, popupHtml) {
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        var marker = new google.maps.Marker({
            map: map[id], 
            position: results[0].geometry.location
            //icon: '/Templates/SatelliteSite.v2/img/googleMapsPin.png'
        });
        if(name != undefined) {
            marker.title = name      
        }
        if(url != undefined) {
             google.maps.event.addListener(marker, 'click', function() {
                window.location = url;
              });
        }
        
        if(popupHtml != undefined)
        {                        
            google.maps.event.addListener(marker, 'click', function() {               
               infowindow.setContent(popupHtml);
               infowindow.open(map[id],this);
            });
        }   
        
        var empty = bounds[id].isEmpty();
        
        bounds[id].extend(marker.position);
        if(!empty){
          map[id].fitBounds(bounds[id]);
        }
        map[id].setCenter(bounds[id].getCenter());
      }
    });
  }
