//
// locationIndex is the index of the location in the location array
// mapIndex is the index of the pin on the map
// resultIndex is the index of the result among all results
function addMapResult(locations, locationIndex, mapIndex, resultIndex, lat, lon, name, st, ci, pv, pc) {
	var iconSpec = createIconSpecification('/images/dart.png', '<div id="' + mapIndex + '" class="pushpin"><span class="text">' + mapIndex + '</span></div>');
	iconSpec.TextContent = resultIndex; 
	locations[locationIndex] = new Array();
	locations[locationIndex][0] = lat;
	locations[locationIndex][1] = lon;
	locations[locationIndex][2] = '<a href="javascript:getListingLink(' + resultIndex + ');" name="&amp;lid=website&amp;lpos=results_map" style="font-weight: bold;">' + name + '</a>';
	locations[locationIndex][3] = st;
	locations[locationIndex][4] = ci;
	locations[locationIndex][5] = pv;
	locations[locationIndex][6] = pc;
	locations[locationIndex][7] = '';
	locations[locationIndex][8] = iconSpec;
}

//
function addMapLandmark(locations, lat, lon, name) {
	var iconSpec = createIconSpecification('/images/bluePushpin.gif', '<div id="0" class="pushpinLandmark"></div>');
	locations[0] = new Array();
	locations[0][0] = lat;
	locations[0][1] = lon;
	locations[0][2] = name;
	locations[0][3] = '';
	locations[0][4] = '';
	locations[0][5] = '';
	locations[0][6] = '';
	locations[0][7] = '';
	locations[0][8] = iconSpec;
}

function createIconSpecification(imgFile, customHtml) {
	var iconSpec = new VECustomIconSpecification();
	iconSpec.BackColor = new VEColor(0,0,0,0);//3D only
	iconSpec.Image = (null != imgFile) ? imgFile : '/images/dart.png';//3D only
	iconSpec.ImageOffset = new VEPixel(0,0);//3D only
	iconSpec.TextOffset = new VEPixel(10,5);//3D only
	iconSpec.ForeColor = new VEColor(0,0,0,1);
	iconSpec.CustomHTML = (null != customHtml) ? customHtml : '<div id="1" class="pushpin"></div>';//2D Maps custom spec
	iconSpec.TextContent = '';
	return iconSpec;
}

// Icon specification for standard "dart" pin
function createPin(mapIndex) {
	return createIconSpecification('/images/dart.png', '<div id="' + mapIndex + '" class="pushpin"></div>');
}

// Icon specification for standard landmark pin
function createLmPin(mapIndex) {
	return createIconSpecification('/images/bluePushpin.gif', '<div id="' + mapIndex + '" class="pushpinLandmark"></div>');
}

function createMap(clientToken, lat, lon, zoom) {
	//Changing the icon can be done a couple of ways, this method defines a
	//VECustomIconSpecification, if you are going to use 3D maps you will want to 
	//use this method as 3D maps do not display the custom icons if they are only
	//defined using html.
	//
	//The second method, which is preferable is you are going to use 2D maps only
	//is to use the VPGMapControl pushPinIcon property and set it to the same image url or
	//html markup that we are setting in the VECustomIconSpecification.CustomHTML property (ref 1 below).
	//
	//If you use a custom icon that does not have its "point" in the same spot as the
	//regular pushpin icon will require position adjustment of the icon to put your "point" in
	//the right spot.  I've done that here with the creation of the css class pushpin defined above.
	//Be aware that this will not move the infobox and the progress animation, they will remain
	//where it was based on a standard pushpin.  This can be adjusted by overriding the VE
	//styles .ero-progressAnimation and .ero-leftBreak as demonstrated above.		
	
	map = new YPGMapControl("MapResults");
	var style = VEMapStyle.Road;
	var fixed = false;
	var mode = VEMapMode.Mode2D;
	var showSwitch = true;
	var latLong = new VELatLong(lat, lon);
	map.CreateAndLoadMap(latLong, zoom, style, fixed, mode, showSwitch, clientToken);
	return map;
}