var msn_map = null;var xml = null;var pins = null;(function($) {	$.fn.msnMap = function() {		var defaults = {			url : "/voice-restaurant/xml/map.xml",			dom : "map"		};		var opts = $.extend(defaults, opts);				return this.each(function() {			var map = $(this);			$.mapFNC.showMap(opts.dom);			$.get(opts.url, function(data) { 				xml = data; $.mapFNC.activateControls(); 				$.mapFNC.addPushPin(0);				$.mapFNC.centerMap(0, 11); 			});		});	};		$.mapFNC = {		showMap: function(dom) {			msn_map = new VEMap(dom);			msn_map.LoadMap();			msn_map.SetMouseWheelZoomToCenter(false);		},		activateControls: function() {					$('#click-from').click(function() {				$('#from').val($(this).attr('rel'));					return false;			});			$('#click-to').click(function() {				$('#to').val($(this).attr('rel'));				return false;			});			$('.map-form #submit').click(function() { $.mapFNC.getRouteList(); return false; });			$('#clearRoute').click(function() { $.mapFNC.clearRouteList(); return false; });		},		addPushPin: function(num) {				var place = $('item:eq('+num+')', xml);			var shape = new VEShape(VEShapeType.Pushpin, $.mapFNC.getLatLong(num) );			shape.SetTitle( $('title', place).text() ); 			shape.SetCustomIcon($('pushpin', place).text());			shape.SetPhotoURL($('photo', place).text());			shape.SetDescription($('description', place).text());			msn_map.AddShape(shape);		},		centerMap: function(num, zoom) {			msn_map.SetCenterAndZoom( $.mapFNC.getLatLong(num), zoom);		},		getLatLong: function(num) {			var point = $('item:eq('+num+')', xml);			return new VELatLong($('lat', point).text(), $('long', point).text());		},		getRouteList: function() {			var myOptions = new VERouteOptions;			var routeOrder = new Array();						$('input:text', '.map-form').each(function(i) {				if($(this).val()!='')					routeOrder[i] = $(this).val();									   			});						if(routeOrder.length < 2) {				alert("Please add another location to your trip");				$('input:text:eq(0)', '.map-form').focus();			} else {				myOptions.DrawRoute      = true;				myOptions.RouteCallback  = $.mapFNC.printRoute;				msn_map.GetDirections(routeOrder, myOptions);					}		},		clearRouteList: function() {			$('#route-list').html('');			$('#route-info').html('');			$('input:text', '.map-form').val('');			$('input:text:eq(0)', '.map-form').focus();			try { msn_map.DeleteRoute(); }            			catch (err) { alert(err.message); } 			$.mapFNC.centerMap(0, 11);		},		printRoute: function(route) {							var legs	= route.RouteLegs;			var turns   = "<h2>My Route</h2>";				turns 	+= "<p>Total distance: " + route.Distance.toFixed(1) + " mi</p>";				turns	+= "<ol>";			var numTurns = 0;			var leg      = null;			$.each(legs, function(i) {				leg = legs[i]; 				var turn = null;  				$.each(leg.Itinerary.Items, function(j) {					turn = leg.Itinerary.Items[j];					numTurns++;					turns += "<li>" + turn.Text + " (" + turn.Distance.toFixed(1) + " mi)</li>";				});			});						turns += "</ol>";						$('#route-info').html('');			$('#route-info').append(turns); 			}	};})(jQuery);