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

points[0] = new PVGeoMarker('Des Moines Quality Inn & Suites Event Center', null, '<p><div dir=\"ltr\"><span style=\"color:rgb(51, 51, 51);font-size:11px\"><span style=\"color:rgb(88, 77, 51)\">929 Third Street (I-235, Exit 8)<br>Des Moines, IA 50309</span><br><strong>Phone:</strong> (515) 282-5251<br><strong>Toll-free Reservations:</strong> (800) 903-0009<br><strong>Fax:</strong> (515) 282-6871<br><strong>Email:</strong> <a style=\"color:rgb(184, 165, 105)\" href=\"mailto:gm.ia103@choicehotels.com\">gm.ia103@choicehotels.com</a></span><br> </div></p>', -93.620773,41.594635 );
points[1] = new PVGeoMarker('Quality Inn & Suites Starlite Conference Center, Ames IOWA', null, '<p><span style=\"color:rgb(51, 51, 51);font-size:11px\"><span style=\"color:rgb(88, 77, 51)\">2601 East 13th St. (I-35, Exit 113)<br>Ames, IA 50010<br>(515) 598-5293 </span><br><strong>Toll-Free Reservations:</strong> (800) 903-0009<br><strong>Phone:</strong> (515) 232-9260<br><strong>Fax:</strong> (515) 598-5293<br><strong>Email:</strong> <a style=\"color:rgb(184, 165, 105)\" href=\"mailto:gm.ia102@choicehotels.com\">gm.ia102@choicehotels.com</a></span><br></p>', -93.579849,42.034451 );
points[3] = new PVGeoMarker('LeClaire Comfort Inn & Suites Riverview', null, '<p><span style=\"color:rgb(51, 51, 51);font-size:11px\"><span style=\"color:rgb(88, 77, 51)\">902 Mississippi View Court (I-80, Exit 306)<br>LeClaire, IA 52753</span><br><strong>Phone:</strong> (563) 289-4747<br><strong>Fax:</strong> (563) 289-5535<br><strong>Email:</strong> <a style=\"color:rgb(184, 165, 105)\" href=\"mailto:gm.ia062@choicehotels.com\">gm.ia062@choicehotels.com</a></span><br></p>', -90.362648,41.587975 );
points[4] = new PVGeoMarker('LeClaire Super 8', null, '<p><span style=\"color:rgb(51, 51, 51);font-size:11px\"><span style=\"color:rgb(88, 77, 51)\">1552 Welcome Center Drive (I-80, Exit 306) <br>Quad Cities<br>LeClaire, Iowa 52753 </span><br><strong>Phone:</strong> (563) 289-5888<br><strong>Fax:</strong> (563) 289-5535<br><strong>E-mail:</strong> <a style=\"color:rgb(184, 165, 105)\" href=\"mailto:GeneralManager10970@wynhg.com\">GeneralManager10970@wynhg.com</a></span><br></p>', -90.364632,41.588615 );
points[5] = new PVGeoMarker('Best Western Starlite Village Inn & Suites', null, '<p><span style=\"color:rgb(51, 51, 51);font-size:11px\"><span style=\"color:rgb(88, 77, 51)\">1518 3rd Ave NW (Hwy 169 & 7)<br>Fort Dodge, IA 50501</span><br><strong>Phone: </strong>(515) 573-7177<br><strong>Toll-free Reservations:</strong> (800) 903-0009<br><strong>Fax: </strong>(515) 573-3999<br><strong>Email:</strong> <a style=\"color:rgb(184, 165, 105)\" href=\"mailto:troystar@frontiernet.net\">troystar@frontiernet.net</a></span><br></p>', -94.222702,42.515553 );

function PVGeoMarker(title, address, info, lon, lat) {
	
	this.title = title;
	this.info = info;
	if(address)
		this.address = address;
	else
		this.address = lat + ', ' + lon;
	
	this.lat = lat;
	this.lon = lon;
	this.marker = null;
	this.infohtml = '<b>' + this.title + '    </b><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() {
	/* var ico = new GIcon(G_DEFAULT_ICON, 'http://maps.google.com/mapfiles/ms/micons/blue-dot.png');
	ico.iconSize = new GSize(32, 32); */

	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, 15 );
	map.addOverlay(this.marker);
	this.marker.openInfoWindowHtml(this.infohtml);
}

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

function createMap( elementid ) {
	map = new google.maps.Map2(document.getElementById( elementid ));
    // map.enableScrollWheelZoom();
    map.enableContinuousZoom();
    // map.addControl(new GSmallMapControl());
    map.addControl(new GLargeMapControl());
	// map.addControl(new GMapTypeControl());
    var point = new GLatLng(0, 0);
	map.setCenter( point , 4 );
	
	AddressCache.prototype = new GGeocodeCache();

    geocoder = new GClientGeocoder();
    geocoder.setCache(new AddressCache());	
}

function loadMarkersLayer() {
	bounds = new GLatLngBounds();
	map.clearOverlays();   	
	
	if(typeof(showpoint) != 'undefined') {
		
		var pt = points[showpoint];
		if(pt != null) {
			pt.coords = new GLatLng(pt.lat,pt.lon);
			map.addOverlay(pt.createMarker());
			
			map.setCenter(pt.coords, 15);
			pt.popup();
		}
		else
			alert('map-api error: point id is invalid!');
	}
	else {
		for (var i = 0; i < points.length; i++) {
			var pt = points[i];
			if(pt != null) {
				pt.coords = new GLatLng(pt.lat,pt.lon);
				map.addOverlay(pt.createMarker());
				bounds.extend(pt.coords);
			}
		}
		
		if(points.length == 1) {
			map.setCenter(points[0].coords, 10);
			points[0].popup();
		}
		else if (!bounds.isEmpty()) {
			boundzoom = map.getBoundsZoomLevel(bounds);
			map.setCenter(bounds.getCenter(), --boundzoom);
		}
	}
}

function loadGoogleMap() {
	
	createMap( 'googlemap' );
	loadMarkersLayer();

}

google.load("maps", "2.x");
google.setOnLoadCallback(loadGoogleMap);
