var map;
var geocoder;
var gc_title;
var bounds = new GLatLngBounds(); 
var points = Array();

// === Create an associative array of GIcons() ===
var gicons = [];
gicons["blue"] = new GIcon(G_DEFAULT_ICON, "http://maps.google.com/mapfiles/ms/micons/blue-dot.png");
gicons["red"] = new GIcon(G_DEFAULT_ICON, "http://maps.google.com/mapfiles/ms/micons/red-dot.png");
gicons["blue"].iconSize = new GSize(32, 32); 
gicons["red"].iconSize = new GSize(32, 32); 
/*


PVGeoMarker constructor:

PVGeoMarker(title, address, pagelink, image, text, lon, lat);

title - displayed in bold, at the top
address - address to be used for the geocoding. NO HTML!!!
pagelink - link to the property page, e.g. http://www.HeartofAmericahotels.com/property/index.html or /property/index.html . do not use relative paths
image - link to an image, e.g. http://www.HeartofAmericahotels.com/property/images/logo.png or /property/images/logo.png . do not use relative paths
text - HTML allowed
lon, lat - coordinates

*/
points[0] = new PVGeoMarker( 'Iowa/Des Moines - The Comfort Suites Hotel', '11167 Hickman Rd. Urbandale, IA 50322', 'ComfortSuitesDesMoines/index.html', 'images/logos/gm_comfort_suites.gif', 'Toll Free - 800.395.7675', -93.771713,41.614979, gicons["blue"] );
points[1] = new PVGeoMarker( 'Iowa/Des Moines - The Wildwood Lodge Hotel', '11431 Forest Avenue Clive, IA 50325', 'WildwoodLodgeDesMoines/index.html','images/logos/gm_wildwood.gif', 'Toll Free - 800.728.1223<br>Local - 515.222.9876', -93.773651,41.601517, gicons["blue"] );
points[2] = new PVGeoMarker( 'Iowa/Des Moines - The Radisson Hotel', '6800 Fleur Drive Des Moines, IA 50321', 'RadissonDesMoines/index.html','images/logos/gm_radisson.gif', 'PH: 515.285.7777<br>FX: 515.256.0000', -93.645081,41.522724, gicons["blue"] );
points[3] = new PVGeoMarker( 'Iowa/Des Moines - The Sleep Inn Hotel', '11211 Hickman Rd. Urbandale, IA 50322', 'SleepInnDesMoines/index.html','images/logos/gm_sleepinn.gif"', 'Located Interstate 80 &amp; 35 at Exit 125<br>Toll Free - 877.233.0333', -93.771935,41.614979, gicons["blue"] );
points[4] = new PVGeoMarker( 'Iowa/Des Moines - The Fairfield Inn &amp; Suites Hotel', '6880 Fleur Drive Des Moines, IA 50312', 'FairfieldInn&Suites/index.html','images/logos/gm_fairfield.gif', 'Located at the<br>Des Moines Airport', -93.645065,41.522194, gicons["blue"] );
points[5] = new PVGeoMarker( 'Minnesota / Lake Elmo - The Wildwood Lodge Hotel', '8511 Hudson Blvd N Lake Elmo, MN 55042', 'WildwoodLodgeStpaul/index.html','images/logos/gm_wildwood.gif', 'Toll Free -866.294.6250', -92.932459,44.951945, gicons["blue"] );
points[6] = new PVGeoMarker( 'Wisconsin / Pewaukee - The Radisson Hotel', 'N14 W24140 Tower Place Pewaukee, WI. 53072', 'RadissonPewaukee/index.html','images/logos/gm_radisson.gif', 'pH: 262.506.6300<br>FX: 262.523.129', -88.227654,43.050739, gicons["blue"] );
points[7] = new PVGeoMarker( 'Kansas / Olathe - The Comfort Suites Hotel', '12070 S Strang Line Rd. Olathe, KS 66062', 'ComfortSuitesKansasOlathe/index.html', 'images/logos/gm_comfort_suites.gif', 'Toll Free - 877.424.6423', -94.769547,38.910130, gicons["blue"] );
points[8] = new PVGeoMarker( 'Iowa / Davenport - The EconoLodge Inn &amp; Suites', '7222 Northwest Blvd. Davenport, Iowa 52806', 'EconoLodgeQuadCity/index.html','images/logos/gm_econolodge.gif', 'I-80 at Northwest Blvd., exit 292<br>Toll Free - 800.272.1779', -90.613113,41.594040, gicons["blue"] );
points[9] = new PVGeoMarker( 'Corporate', '1501 River Drive Moline, IL 61265', '','', '309.797.9300<br>Fax 309.797.8700', -90.517677,41.508160 );
points[10] = new PVGeoMarker( 'The Comfort Suites Hotel - Greater Milwaukee Wisconsin ', 'N14 W24121 Tower Pl. Pewaukee, WI 53072', 'ComfortSuitesPewaukee/index.html','images/logos/gm_comfort_suites.gif', 'Toll Free: (877) 424.6423199<br>Local: (262) 506.2000', -88.219185,43.069139, gicons["blue"] );
points[11] = new PVGeoMarker( 'Holiday Inn & Suites ', '6075 Mills Civic Parkway', 'HolidayInn&Suites/index.html','images/logos/gm_holiday.gif', 'West Des Moines', -93.79056,41.55916, gicons["blue"] );

points[12] = new PVGeoMarker( 'Grammas Kitchen ', '2955 N Plainview RD Walcott, IA 52773', 'http://www.hoari.com/Grammas/','images/logos/gm_grammas_k.gif', '(563) 284-5055', -90.783090,41.614375, gicons["red"] );
points[19] = new PVGeoMarker( 'Grammas Kitchen', '2955 N Plainview RD Walcott, IA 52773 ', 'http://www.hoari.com/Grammas/','images/logos/gm_grammas_k.gif', '(563) 284-5055', -90.780201,41.605046, gicons["red"] );
points[16] = new PVGeoMarker( 'Grammas Kitchen ', '2955 N Plainview RD Walcott, IA 52773', 'http://www.hoari.com/Grammas/','images/logos/gm_grammas_k.gif', '(563) 284-5055', -90.782926,41.615571, gicons["red"] );

points[14] = new PVGeoMarker( 'Johnnys Italian Steakhouse', '6800 Fleur Dr Des Moines, IA 50321 ', 'http://www.johnnysitaliansteakhouse.com/des_moines.asp','images/logos/gm_johnnys.gif', '515-287-0847', -93.650486,41.526652, gicons["red"] );
points[18] = new PVGeoMarker( 'Johnnys Italian Steakhouse', '1300 River Dr Moline, IL 61265 ', 'http://www.johnnysitaliansteakhouse.com/moline.aspx','images/logos/gm_johnnys.gif', '(309) 736-0100', -90.526164,41.511148, gicons["red"] );
points[24] = new PVGeoMarker( 'Johnnys Italian Steakhouse', '8390 Market St Middleton, WI 53562', 'http://www.johnnysitaliansteakhouse.com/middleton.aspx','images/logos/gm_johnnys.gif', '(608) 831-3705', -88.25986,43.08229, gicons["red"] );
points[27] = new PVGeoMarker( 'Johnnys Italian Steakhouse', '5201 W War Memorial Dr # 300 Peoria, IL 61615', 'http://www.johnnysitaliansteakhouse.com/peoria.aspx','images/logos/gm_johnnys.gif', '(309) 692-3887', -89.67365,40.776496, gicons["red"] );
points[29] = new PVGeoMarker( 'Johnnys Italian Steakhouse', '305 N 170th St Omaha, NE 68118', 'http://www.johnnysitaliansteakhouse.com/omaha.aspx','images/logos/gm_johnnys.gif', '(309) 692-3887', -96.181396,41.260940, gicons["red"] );

points[13] = new PVGeoMarker( 'Machine Shed ','11151 Hickman Road, Urbandale, IA 50322 ', 'http://www.machineshed.com/restaurants/desmoines.asp','images/logos/gm_machine_shed.gif', '(515) 270-6818', -93.771632,41.614967, gicons["red"] );
points[20] = new PVGeoMarker( 'Machine Shed', '7250 Northwest Blvd Davenport, IA 52806 ', 'http://www.machineshed.com/restaurants/davenport.asp','images/logos/gm_machine_shed.gif', '(563) 391-2427', -90.615406,41.58977, gicons["red"] );
points[22] = new PVGeoMarker( 'Machine Shed', 'N14w24145 Tower Pl Waukesha, WI 53188 ', 'http://www.machineshed.com/restaurants/pewaukee.asp','images/logos/gm_machine_shed.gif', '(262) 523-1322',-88.226808,43.050972, gicons["red"] );
points[25] = new PVGeoMarker( 'Machine Shed', '220 N. Fox River Drive Grand Chute, WI 54914 ', 'http://www.machineshed.com/restaurants/appleton.asp','images/logos/gm_machine_shed.gif', '(920) 830-2326', -88.392863,44.270249, gicons["red"] );
points[26] = new PVGeoMarker( 'Machine Shed', '8515 Hudson Blvd N Lake Elmo, MN 55042 ', 'http://www.machineshed.com/restaurants/lake_elmo.asp','images/logos/gm_machine_shed.gif', '(651) 735-7436', -92.862239,44.952195, gicons["red"] );
points[15] = new PVGeoMarker( 'Machine Shed', '87475 E State St Rockford, IL 61108 ', 'http://www.machineshed.com/restaurants/rockford.asp','images/logos/gm_machine_shed.gif', '(815) 229-3276', -88.969517,42.270259, gicons["red"] );

points[17] = new PVGeoMarker( 'Thunder Bay Grille', '6511 N Brady St Davenport, IA 52806 ', 'http://www.thunderbaygrille.com/loc-davenport.aspx','images/logos/gm_tbgrill.gif', '(563) 386-2722', -90.571113,41.584546, gicons["red"] );
points[21] = new PVGeoMarker( 'Thunder Bay Grille', 'N14w24130 Tower Pl Pewaukee, WI 53072', 'http://www.thunderbaygrille.com/loc-pewaukee.aspx','images/logos/gm_tbgrill.gif', '(262) 523-4244', -88.25986,43.08229, gicons["red"] );
points[28] = new PVGeoMarker( 'Thunder Bay Grille', '7652 Potawatomi Trl Rockford, IL 61107', 'http://www.thunderbaygrille.com/loc-rockford.aspx','images/logos/gm_tbgrill.gif', '(815) 397-4800', -88.967714,42.273181, gicons["red"] );
points[23] = new PVGeoMarker( 'Thunder Bay Grille', 'N14w24130 Tower Pl Pewaukee, WI 53072', 'http://www.thunderbaygrille.com/loc-pewaukee.aspx','images/logos/gm_tbgrill.gif', '(262) 523-4244', -88.260813,43.079625, gicons["red"] );

function PVGeoMarker(title, address, pagelink, image, text, lon, lat, icon) {
	this.title = title;
	this.pagelink = pagelink;
	this.image = image;
	this.info = text;
	this.address = address;
	this.lat = lat;
	this.lon = lon;
	this.coords = new GLatLng(this.lat,this.lon);
	this.marker = null;
	this.icon = icon;
	// this.pagelink = 'http://www.google.com';
	// this.image = 'http://www.macuser.com/images_site/apple_tv_50.png';
	
	this.htmlpagelink = this.pagelink != '' ? '<div style="clear:both;" align="right"><a style="color: #000;"target="_self" href="'+this.pagelink+'">View Webpage</a></div>' : '';
	this.htmlimage = this.image != '' ? '<div style="float:left; height: 48px; padding: 8px 4px 4px 0px;"><img border="0" src="' + this.image + '" alt="image" /></div>' : '';
	
	this.infohtml = '<b>' + this.title + '&nbsp;&nbsp;&nbsp;&nbsp;</b><br/>'+ this.htmlimage + '<div style="float:left; text-align: left; padding-top: 8px; padding-left: 2px; width: 160px;">' + this.info + '<br/>' + this.address + '</div><div style="clear:both;" 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>' + this.htmlpagelink;
}

PVGeoMarker.prototype.createMarker = function() {
	this.marker = new GMarker(this.coords, this.icon);
	
	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 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, 10);
	}
	else if (!bounds.isEmpty()) {
		map.setCenter(bounds.getCenter(),
		map.getBoundsZoomLevel(bounds));
	}
}

function loadGoogleMap() {
  if (GBrowserIsCompatible()) {
  	createMap( 'googlemap' );
	if(typeof(openmapid) != 'undefined')  {
		points[openmapid].show();
	}
	else {
  		loadMarkersLayer();
	}
  }
}

Event.observe(window, 'load', loadGoogleMap, false);
Event.observe(window, 'unload', GUnload, false);
