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

points[0] = new PVGeoMarker('Monique Lhuillier', null, '<p></p>', -118.376238,34.083853 );
points[1] = new PVGeoMarker('Coco de Mer', null, '<p></p>', -118.374214,34.083016 );
points[2] = new PVGeoMarker('Kitson Melrose', null, '<p></p>', -118.379557,34.081914 );
points[3] = new PVGeoMarker('Trashy Lingerie', null, '<p></p>', -118.376554,34.079854 );
points[4] = new PVGeoMarker('Beverly Center', null, '<p></p>', -118.376608,34.075945 );
points[5] = new PVGeoMarker('John Varvartos', null, '<p></p>', -118.385715,34.08057 );
points[6] = new PVGeoMarker('Beverly Connection', null, '<p></p>', -118.375777,34.073311 );
points[7] = new PVGeoMarker('Maxfield', null, '<p></p>', -118.386278,34.081042 );
points[8] = new PVGeoMarker('Fred Segal', null, '<p></p>', -118.366622,34.083716 );
points[9] = new PVGeoMarker('Kitson Men', null, '<p></p>', -118.383692,34.076604 );
points[10] = new PVGeoMarker('Stella McCartney', null, '<p></p>', -118.384573,34.077472 );
points[11] = new PVGeoMarker('Ted Baker', null, '<p></p>', -118.384067,34.07612 );
points[12] = new PVGeoMarker('Lisa Kline', null, '<p></p>', -118.383452,34.074353 );
points[13] = new PVGeoMarker('True Religion', null, '<p></p>', -118.383457,34.074504 );

points[14] = new PVGeoMarker('James Perse', null, '<p></p>', -118.389477, 34.080729 );
points[15] = new PVGeoMarker('Armani Exchange', null, '<p></p>', -118.383873, 34.076846 );
points[16] = new PVGeoMarker('Wells Fargo', null, '<p></p>', -118.378286, 34.08866 );
points[17] = new PVGeoMarker('Bank of America', null, '<p></p>', -118.384882, 34.084649 );
points[18] = new PVGeoMarker('Chase', null, '<p></p>', -118.366795, 34.097883 );
points[19] = new PVGeoMarker('Trader Joe&acute;s', null, '<p></p>', -118.379472, 34.087862 );
points[20] = new PVGeoMarker('Pavilions', null, '<p></p>', -118.386462, 34.08395 );

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