﻿
var map2;
var cgm2;

$(document).ready(function() {
	mapInit2();
	$(":checkbox:not(.layer-group)", $("div.map-layers-container")).click(layerClick);
});
function layerClick() {
	if ($(this).attr("checked")) {
		cgm2.showLayer($(this).attr("name"));
	} else {
		cgm2.hideLayer($(this).attr("name"));
	}
}
function mapInit2() {
	if ($("#map_guide").length > 0) {
		map2 = new GMap2($("#map_guide").get(0));
		map2.setCenter(new GLatLng(33.823215, -116.512114), 11);
		var mapTypePos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10, 10));
		var mapControlPos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10, 50));

		map2.addControl(new GSmallMapControl(), mapControlPos);
		map2.addControl(new GMenuMapTypeControl(), mapTypePos);
		//map2.addControl(new GScaleControl());

		map2.enableContinuousZoom();
		map2.enableScrollWheelZoom();

		cgm2 = new CRGGoogleMap(map2, { maxInitZoom: 17, minClusterSize: 0 });
		//cgm.onLayersLoadStart = function() { $("#loading").show(); };
		//cgm.onLayersLoadComplete = function() { $("#loading").hide(); };
		//cgm.onZoomEnd = function(o, n) { setupLayers(); };
		cgm2.initialize();


		ml = new MapLayer("Profile Entry", "/WebServices/MapService.svc/GetOverlayByEntryId", { 'entryIds': ProfileEntry }, { visible: true, center: true, filterMb: false, cluster: false, clusterGridSize: 0 });
		//ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
		//ml.onMaxResults = function() { $("#tooManyResults").show(); };
		//ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
		ml.MarkerOptions = { icon: createicon('/images/map/marker_yellowstar.png') };
		ml.onClick = markerClick;
		cgm2.addLayer(ml);

		if (typeof (StayNearby) != "undefined") {
			var jdata = { 'query': StayNearby, 'geotypes': 'Marker' };
			ml = new MapLayer("StayNearby", "/WebServices/MapService.svc/GetOverlayByEntryQuery", jdata, { visible: false, center: false, filterMb: false, cluster: false, distinctEntry: true, clusterGridSize: 0 });
			ml.MarkerOptions = { icon: createicon('/images/map/marker_orangestay.png') };
			ml.onClick = markerClick;
			cgm2.addLayer(ml);
		}
		if (typeof (PlayNearby) != "undefined") {
			var jdata = { 'query': PlayNearby, 'geotypes': 'Marker' };
			ml = new MapLayer("PlayNearby", "/WebServices/MapService.svc/GetOverlayByEntryQuery", jdata, { visible: false, center: false, filterMb: false, cluster: false, distinctEntry: true, clusterGridSize: 0 });
			ml.MarkerOptions = { icon: createicon('/images/map/marker_orangeplay.png') };
			ml.onClick = markerClick;
			cgm2.addLayer(ml);
		}
		if (typeof (DineNearby) != "undefined") {
			var jdata = { 'query': DineNearby, 'geotypes': 'Marker' };
			ml = new MapLayer("DineNearby", "/WebServices/MapService.svc/GetOverlayByEntryQuery", jdata, { visible: false, center: false, filterMb: false, cluster: false, distinctEntry: true, clusterGridSize: 0 });
			ml.MarkerOptions = { icon: createicon('/images/map/marker_orangedine.png') };
			ml.onClick = markerClick;
			cgm2.addLayer(ml);
		}
		if (typeof (ShopNearby) != "undefined") {
			var jdata = { 'query': ShopNearby, 'geotypes': 'Marker' };
			ml = new MapLayer("ShopNearby", "/WebServices/MapService.svc/GetOverlayByEntryQuery", jdata, { visible: false, center: false, filterMb: false, cluster: false, distinctEntry: true, clusterGridSize: 0 });
			ml.MarkerOptions = { icon: createicon('/images/map/marker_orangeshop.png') };
			ml.onClick = markerClick;
			cgm2.addLayer(ml);
		}
		if (typeof (VSNearby) != "undefined") {
			var jdata = { 'query': VSNearby, 'geotypes': 'Marker' };
			ml = new MapLayer("VSNearby", "/WebServices/MapService.svc/GetOverlayByEntryQuery", jdata, { visible: false, center: false, filterMb: false, cluster: false, distinctEntry: true, clusterGridSize: 0 });
			ml.MarkerOptions = { icon: createicon('/images/map/marker_orangeinfo.png') };
			ml.onClick = markerClick;
			cgm2.addLayer(ml);
		}
	}
}