
var hotels_map;
var hotels_mkmgr;
var hotels_icon;

function gmap_init(map_element_id) {
   if (GBrowserIsCompatible()) {
      hotels_map = new GMap2(document.getElementById(map_element_id));
      hotels_map.setMapType(G_HYBRID_MAP);
      
      hotels_map.addControl(new GSmallMapControl());
      hotels_map.addControl(new GMapTypeControl());

      hotels_icon = new GIcon();
      hotels_icon.image = '/images/_base/gmarker_oczko.png';
      hotels_icon.shadow = '/images/_base/gmarker_oczko_shadow.png';
      hotels_icon.iconSize = new GSize(92, 64);
      hotels_icon.shadowSize = new GSize(92, 64);
      hotels_icon.iconAnchor = new GPoint(35, 62);
      hotels_icon.infoWindowAnchor = new GPoint(32, 1);

      hotels_mkmgr = new GMarkerManager(hotels_map);
   }
}

function gmap_set_view(lat, long, zoom) {
	if (GBrowserIsCompatible()) {
		if (hotels_map == undefined) {
			gmap_init();
		}
		hotels_map.setCenter(new GLatLng(lat, long), zoom);
	}
}

function gmap_hotel(map_element_id, lat, long, zoom, hotel_name, hotel_href, hotel_image, hotel_image_width, hotel_image_height, show_infobox) {
	if (GBrowserIsCompatible()) {
		if (hotels_map == undefined) {
			gmap_init(map_element_id);
		}
		
		if (hotel_href.length > 0) {
			var hotel_link = '<a href="' + hotel_href + '">' + hotel_name + '</a>';
		} else {    	  
			var hotel_link = hotel_name;
		}
		if (hotel_image.length > 0) {
			var hotel_img = '<br /><a href="' + hotel_href + '"><img width="' + hotel_image_width + '" height="' + hotel_image_height + '" style="border: 1px solid #404040; margin-top: 5px;" src="' + hotel_image + '" /></a>';
		} else {    	  
			var hotel_img = '';
		}
		var hotel_html = '<div class="gmap-hotel-name" style="text-align: center; font-size: 14px; font-weight: bold">' + hotel_link + hotel_img + '</div>';
      
      var hotel = new GLatLng(lat, long);
      var hotelmk = new GMarker(hotel, {icon:hotels_icon});
      var mkevent = function() {
    	  this.openInfoWindowHtml(hotel_html);
      };
      var tl = function(vischanged) {
    	  if (gmap_hotel.first_shown != hotel_name && show_infobox) {
    		  hotelmk.openInfoWindowHtml(hotel_html);
    		  gmap_hotel.first_shown = hotel_name;
    	  }
      };
      GEvent.addListener(hotelmk, 'click', mkevent);
      GEvent.addListener(hotels_map, 'tilesloaded', tl);
      hotels_mkmgr.addMarker(hotelmk, 0, 17);
      hotels_mkmgr.refresh();
      hotelmk.show();      
   }
}
