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

points[0] = new PVGeoMarker('Hampton Inn & Suites Seattle-North/Lynnwood', '19324 Alderwood Mall Parkway<br>Lynnwood, Washington 98036', 'Phone: (425) 771-1888 / (877) 771-8555<br/>Email: <a href="mailto:info@hamptonseattlenorth.com">info@hamptonseattlenorth.com</a>', -122.271009, 47.823148);
points[1] = new PVGeoMarker( 'Best Western Navigator Inn & Suites', '10210 Evergreen Way<br>Everett, WA 98204', 'Reservations 1-877-488-0510<br/><a href="mailto:info@navigatorsuites.com">info@navigatorsuites.com</a>', -122.244969,47.905197 );
points[2] = new PVGeoMarker( 'Hotel Nexus Seattle', '2140 N. Northgate Way<br>Seattle, WA 98133', 'Phone: 206-365-0700<br/>Toll-Free: 800-435-0754<br/>Email: <a href="info@hotelnexusseattle.com">info@hotelnexusseattle.com</a>', -122.332878,47.708626 );
points[3] = new PVGeoMarker( 'Staybridge Suites Seattle North-Everett', '9600 Harbour Place<br>Mukilteo, WA98275', 'Phone: (425) 493-9500<br/>Email: <a href="gm@staymukilteo.com">gm@staymukilteo.com</a>', -122.308095,47.895567 );

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=16">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.popup = function() {
	this.marker.openInfoWindowHtml(this.infohtml);
}

PVGeoMarker.prototype.show = function() {
	map.clearOverlays();
	this.createMarker();
	map.setCenter( this.coords, 17 );
	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 GSmallMapControl());
    map.addControl(new GLargeMapControl());
    var point = new GLatLng(0, 0);
	 map.setCenter( point , 4 );
	
    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(points[0].coords, 11);
		points[0].popup();
	}
	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);
