var geocoder;
var map;
var infowindow;

function initializeMap( type, zoom ) 
{
  if ( !type ) type = google.maps.MapTypeId.ROADMAP;
  if ( !zoom ) zoom = 13;
  
  geocoder = new google.maps.Geocoder();

  var latlng = new google.maps.LatLng( 53.225762, 6.562872 );
  var myOptions = {
    zoom: zoom,
    center: latlng,
    mapTypeId: type,
    scrollwheel: false
  }
  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function codeAddress( hoteldata ) 
{
  if ( infowindow )
  {
    infowindow.close();
  }

  infowindow = new google.maps.InfoWindow();
  
  var address = hoteldata.address;
  if (geocoder) {
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
          map.setCenter(results[0].geometry.location);

          if ( !hoteldata.hidemarker )
          {
            if ( hoteldata.icon )
            {
                var marker = new google.maps.Marker({
                    icon: hoteldata.icon,
                    map: map,
                    position: results[0].geometry.location
                });
            }
            else
              {
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location
                });
              }
          }
          // paint info window 
          
          var formatted = '';
          
          if ( hoteldata.foto )
          {
          	formatted += '<img height="64" src="' + hoteldata.foto + '" style="float:right"></img>';
          }
          
          formatted += '<b>' + hoteldata.name + '</b><br />';
          
          for ( x=0; x<hoteldata.stars; x++ )
          {
            formatted += '<img src="/pics/vt/star_on.gif" />';
          }
      
          formatted += '<br />' + results[0].formatted_address;
          
          infowindow.setContent( formatted );
          infowindow.open(map, marker);

          google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent( formatted );
            infowindow.open(map, marker);
          });

        } else {
          alert("Geen resultaten gevonden");
        }
      } else {
        //alert("Geocoderen is niet gelukt: " + status);
      }
    });
  }
}