﻿

var map;
var baseIcon;
var currentMarker;
var mapIcons = [];
	
baseIcon = new GIcon();
baseIcon.shadow = "/PlugIns/GoogleMapsEditor/icons/shadow_project.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(72, 49);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);

function displayCategoryPoints(cId)
{

	if(!mapCoordinates)
		return;
	
	for(i = 0;i < mapCoordinates.length;i++)
	{
		if(mapCoordinates[i].CategoryID == cId || mapCoordinates[i].CategoryID == 1 || cId == 0)
		{
			if(mapCoordinates[i].IconURL)
			{
				var markerOptions;
				var letteredIcon = new GIcon(baseIcon);
				
				var point = new GLatLng(mapCoordinates[i].Y, mapCoordinates[i].X);
						
				letteredIcon.image = mapCoordinates[i].IconURL;
				letteredIcon.iconSize = new GSize(49, 48);
				letteredIcon.iconAnchor = new GPoint(25, 48);
				markerOptions = { icon:letteredIcon };
				currentMarker = new GMarker(point, markerOptions);

			}
			else
			{
				var point = new GLatLng(mapCoordinates[i].Y, mapCoordinates[i].X);
				currentMarker = new GMarker(point);
			}
			
			//GEvent.addListener(currentMarker, "click", function() {
				//	currentMarker.openInfoWindowHtml("Marker <b>" + letter + "</b>");
				//  });
			
				
			addMapAction(currentMarker, i);
			
			
            mapIcons.push({"ID":mapCoordinates[i].ID, "Image" :mapCoordinates[i].IconURL, "marker" : currentMarker});
            map.addOverlay(currentMarker);

         
		}
		
	}
}

function addMapAction(m, index) {
 
	GEvent.addListener(m, "mouseover", function() {
		M2MControl.focus(mapCoordinates[index].ID, true);
		
	});
	
	GEvent.addListener(m, "mouseout", function() {
		M2MControl.blur(mapCoordinates[index].ID, true);
		
	});
	
	GEvent.addListener(m, "click", function() {
		M2MControl.click(mapCoordinates[index].ID);
		
	});
	
	 return m;
}

function addInfoWindow(m, index)
{
	GEvent.addListener(m, "click", function() {
		var newTitle = mapCoordinates[index].InfoTitle;
		var newText = mapCoordinates[index].InfoText;
		m.openInfoWindowHtml("<h2>" + newTitle + "</h2><p>" + newText + "</p>");
	});
	 return m;
}
