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

points[0] = new PVGeoMarker( '<strong>CARRIAGE HOUSE</strong>', null, '<br>Telephone: (702) 798-1020<br>Reservations: (800) 221-2301 ext. 280<br>Fax: (702) 798-0007<br><br>Email Inquiries:<br><a href="mailto:info@carriagehouselasvegas.com?subject=Email%20Inquiry">info@carriagehouselasvegas.com</a><br/><br/>', -115.167824,36.108028 );

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 + '&nbsp;&nbsp;&nbsp;&nbsp;</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, 17 );
	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);
