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

points[0] = new PVGeoMarker('Knoll at Le Parc', null, '<p></p>', -118.377874,34.084228 );
points[1] = new PVGeoMarker('Nobu Los Angeles', null, '<p></p>', -118.376644,34.087088 );
points[2] = new PVGeoMarker('Belmont', null, '<p></p>', -118.376712,34.084979 );
points[3] = new PVGeoMarker('Koi Restaurant', null, '<p></p>', -118.376126,34.084507 );
points[4] = new PVGeoMarker('Ago Restaurant', null, '<p></p>', -118.37556,34.082187 );
points[5] = new PVGeoMarker('STK', null, '<p></p>', -118.376483,34.085178 );
points[6] = new PVGeoMarker('Le Petit Bistro', null, '<p></p>', -118.37657,34.082402 );
points[7] = new PVGeoMarker('Spanish Kitchen', null, '<p></p>', -118.376091,34.086158 );
points[8] = new PVGeoMarker('Sona', null, '<p></p>', -118.376829,34.078724 );
points[9] = new PVGeoMarker('Stone Fire Pizza', null, '<p></p>', -118.376481,34.086167 );
points[10] = new PVGeoMarker('Cecconi&acute;s', null, '<p></p>', -118.385005,34.080747 );
points[11] = new PVGeoMarker('Le Pain Quotidien', null, '<p></p>', -118.379925,34.082123 );
points[12] = new PVGeoMarker('Sweet Lady Jane', null, '<p></p>', -118.374236,34.083006 );
points[13] = new PVGeoMarker('Barney&acute;s Beanery', null, '<p></p>', -118.374601,34.090756 );
points[14] = new PVGeoMarker('P.F. Chang&acute;s', null, '<p></p>', -118.377562,34.075004 );
points[15] = new PVGeoMarker('The Ivy', null, '<p></p>', -118.384075,34.074787 );
points[16] = new PVGeoMarker('The Palm Restaurant', null, '<p></p>', -118.387282,34.083065 );
points[17] = new PVGeoMarker('Chin-Chin', null, '<p></p>', -118.379524,34.092303 );
points[18] = new PVGeoMarker('Matsuhisa', null, '<p></p>', -118.376443,34.068409 );

points[19] = new PVGeoMarker('Fogo de Chao', null, '<p></p>', -118.376531, 34.068783 );
points[20] = new PVGeoMarker('Fig &amp; Olive', null, '<p></p>', -118.376227, 34.083598 );
points[21] = new PVGeoMarker('Lawry&acute;s Prime Rib', null, '<p></p>', -118.37558, 34.074212 );
points[22] = new PVGeoMarker('Philippe Chow', null, '<p></p>', -118.389566, 34.080725 );
points[23] = new PVGeoMarker('Koi', null, '<p></p>', -118.376407, 34.084458 );
points[24] = new PVGeoMarker('Red O', null, '<p></p>', -118.389584, 34.080724 );
points[25] = new PVGeoMarker('Norm&acute;s Diner (24 hours)', null, '<p></p>', -118.376168, 34.07985 );
points[26] = new PVGeoMarker('Lucques (A favorite of Mrs. Obama)', null, '<p></p>', -118.37567, 34.082226 );
points[27] = new PVGeoMarker('Comme Ca', null, '<p></p>', -118.375754, 34.082434 );
points[28] = new PVGeoMarker('Capital Grille', null, '<p></p>', -118.378769, 34.076318 );
points[29] = new PVGeoMarker('Tender Greens', null, '<p></p>', -118.381712, 34.086602 );

points[30] = new PVGeoMarker2('Le Parc Suite Hotel', null, '<p></p>', 34.084228,-118.377874 );
/*-------------------------------------------------*/
function PVGeoMarker2(title, address, info, lat, lon) {
	
	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>';
	
}		

PVGeoMarker2.prototype.createMarker = function() {
	var baseIcon = new GIcon();
	baseIcon.iconSize = new GSize(32,38);
	baseIcon.iconAnchor = new GPoint(11,37);
	baseIcon.infoWindowAnchor = new GPoint(16,0);
	hotelicon = new GIcon(baseIcon);
	hotelicon.image = '../../images/icons/hotel_icon_lp.png';
	hotelicon.shadow = '../../images/icons/shadow.png';
	hotelicon.shadowSize = new GSize(50,38);
	
	this.marker = new GMarker(this.coords, {icon: hotelicon});
	this.marker.bindInfoWindowHtml( this.infohtml );
	return this.marker;	
}
PVGeoMarker2.prototype.popup = function() {
	this.marker.openInfoWindowHtml(this.infohtml);
}

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

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);
