var map;
var geocoder;
var gc_title;
var bounds = new GLatLngBounds(); 
var points = Array();

points[0] = new PVGeoMarker( 'Alden Houston', '1117 Prairie Street Houston, Texas 77002', 'Houston&acute;s finest luxury boutique hotel<br><br>Tel: 832 200 8800 <br>Toll Free: 877 813 1888 <br>Fax: 832 200 8811 <br>Email: info@aldenhouston.com <br>', -95.360901,29.760185 );

/*-------------------------------------------------*/
function PVGeoMarker2(title, address, info, lat, lon) {
		this.title = title;
	this.info = info;
	this.address = address;
	this.lat = lat;
	this.lon = lon;
	this.coords = new GLatLng(this.lat,this.lon);
	this.marker = null;
	this.infohtml = '<b>' + this.title + '</b><br/>' + this.address + '<br/>' + this.info + '<div align="right"><a style="color: #000;"target="_blank" href="http://maps.google.com/maps?f=d&geocode=&daddr='+escape(lat + ', ' + lon)+'&z=13">Get Driving Directions</a></div></span>';
}	

PVGeoMarker2.prototype.createMarker = function() {
	var baseIcon = new GIcon();
	baseIcon.iconSize = new GSize(21,34);
	baseIcon.iconAnchor = new GPoint(11,34);
	baseIcon.infoWindowAnchor = new GPoint(12,0);
	hotelicon = new GIcon(baseIcon);
	hotelicon.image = 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=airport|ff7766';
	hotelicon.shadow = 'http://chart.apis.google.com/chart?chst=d_map_pin_shadow';
	hotelicon.shadowSize = new GSize(38,34);
	
	this.marker = new GMarker(this.coords, {icon: hotelicon});
	this.marker.bindInfoWindowHtml( this.infohtml );
	return this.marker;	
}

PVGeoMarker2.prototype.show = function() {
	map.clearOverlays();
	this.createMarker();
	map.setCenter( this.coords, 14 );
	map.addOverlay(this.marker);
	this.marker.openInfoWindowHtml(this.infohtml);
}
/*-------------------------------------------------*/

function PVGeoMarker(title, address, info, lon, lat) {
		this.title = title;
	this.info = info;
	this.address = address;
	this.lat = lat;
	this.lon = lon;
	this.coords = new GLatLng(this.lat,this.lon);
	this.marker = null;
	this.infohtml = '<b>' + this.title + '</b><br/>' + this.address + '<br/>' + this.info + '<div align="right"><a style="color: #000;"target="_blank" href="http://maps.google.com/maps?f=d&geocode=&daddr='+escape(this.address)+'&z=13">Get Driving Directions</a></div></span>';
}	

PVGeoMarker.prototype.createMarker = function() {
	this.marker = new GMarker(this.coords);
	this.marker.bindInfoWindowHtml( this.infohtml );
	return this.marker;	
}

PVGeoMarker.prototype.show = function() {
	map.clearOverlays();
	this.createMarker();
	map.setCenter( this.coords, 14 );
	map.addOverlay(this.marker);
	this.marker.openInfoWindowHtml(this.infohtml);
}

function AddressCache() {
	GGeocodeCache.apply(this);
}

AddressCache.prototype = new GGeocodeCache();

function createMap( elementid ) {
    map = new GMap2(document.getElementById( elementid ));
    map.enableScrollWheelZoom();
    map.enableContinuousZoom();
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
	
    var point = new GLatLng(0, 0);
	map.setCenter( point , 4 );
	// map.setMapType(G_HYBRID_MAP);
	
    geocoder = new GClientGeocoder();
    geocoder.setCache(new AddressCache());	
}

function loadMarkersLayer() { 
	map.clearOverlays();   	
	
	for (var i = 0; i < points.length; i++) {
		var pt = points[i];
		if(pt != null) {
			map.addOverlay(pt.createMarker());
			bounds.extend(pt.coords);
		}
	}
	if(points.length == 1) {
		map.setCenter(bounds.getCenter(), 15);
	}
	else if (!bounds.isEmpty()) {
		map.setCenter(bounds.getCenter(),
		map.getBoundsZoomLevel(bounds));
	}
}

function loadGoogleMap() {
  if (GBrowserIsCompatible()) {
  	createMap( 'googlemap' );
  	loadMarkersLayer();
  }
}

Event.observe(window, 'load', loadGoogleMap, false);
Event.observe(window, 'unload', GUnload, false);

