    
	var map = null;
	var pinID = 1;
	var pinString = "|";
	var locs = null;
	var num = 1;

	function GetMap(directionsAff, pinColor, moreInfo) {
	
		// If the browser is Firefox get the version number
		var ffv = 0;
		var ffn = "Firefox/"
		var ffp = navigator.userAgent.indexOf(ffn);
		if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
		// If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
		if (ffv >= 1.5) {
		  Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
		}

		map = new VEMap("myMap");	
		map.LoadMap();

		map.AttachEvent('onendzoom', SetSliderEvent);
		map.HideDashboard();
		createControl();			
						
						
		var pinArray = pinString.split("|");
		num=1;
		locs = new Array;

		var pinArrayLength = pinArray.length;
		pinArrayLength = pinArrayLength-1;

		// Loop through results to add pushpins
		while (num < pinArrayLength) {

			pinDetails = pinArray[num].split(";");
			
			var pinHtml = new StringBuilder();
			
			pinHtml.append('<form action="/sp" name="pinForm' + num +'" method="get">');
			pinHtml.append('<input type="hidden" name="aff" value="' + directionsAff + '"/>'+pinDetails[1]+'<div style="padding:8px;"></div>');
			
			if (directionsAff != '-1') {
				pinHtml.append('<b>Directions</b> <span class="glob_link_12px"><a href="javascript:show(\'dirTo\',\''+num+'\');" id="toLink'+num+'" style="font-weight:bold;">To here</a></span>&nbsp;|&nbsp;<span class="glob_link_12px"><a href="javascript:show(\'dirFrom\',\''+num+'\');" id="fromLink'+num+'">From here</a></span>');
				pinHtml.append('<div style="padding:3px;"></div><div id="dirTo'+num+'">');
				pinHtml.append('Starting Point:<div style="padding:3px;"></div><input type="text" name="start" id="startingAddress'+num+'" value="" size="30"/>');
				pinHtml.append('<div align="center" style="padding:5px 0 0 0;"><input type="submit" value="Get Directions" onclick="this.form.end.value=\''+ pinDetails[1] +'\'" /></div>');
			
				pinHtml.append('</div><div id="dirFrom'+num+'" style="display:none;">');
				pinHtml.append('Ending Point:<div style="padding:3px;"></div><input type="text" name="end" id="endingAddress'+num+'" value="" size="30"/>');
				pinHtml.append('<div align="center" style="padding:5px 0 0 0;"><input type="submit" value="Get Directions" onclick="this.form.start.value=\''+ pinDetails[1] +'\'"/></div>');
				pinHtml.append('</div></div>');
			}
			
			pinHtml.append('</form>');
					
			var pushPin = 'http://gdev.admin.planetdiscover.com/images/pins/' + pinColor + '/' + pinColor + '_pin_' + num + '.gif';
			
			if (moreInfo == 'true') {
				pushPin = 'http://gdev.admin.planetdiscover.com/images/pins/' + pinColor + '/' + pinColor + '_pin.gif';
			}
			
			if (pinDetails[4]!='') {							
				pinTitle = '<div align="center" style="padding:0 0 10px 0;"><img src="'+pinDetails[4]+'"></div><div><b>'+pinDetails[0]+'</b>';
			} else {
				pinTitle = '<div><b>'+pinDetails[0]+'</b>';
			}
			
			map.AddPushpin(new VEPushpin(num, 
				new VELatLong(pinDetails[2], pinDetails[3]),
				pushPin,
				pinTitle,
				pinHtml.toString()
				)
			);
			
			// Add result to locations array
			var loc = new VELatLong(pinDetails[2], pinDetails[3]);
			locs.push(loc);
			num+=1;
		}
		
		DoBestMap(locs, num);			
	}
	
	
	// Auto fit all pushpins into view and auto zoom
	function DoBestMap(locs, num) {
		map.SetMapView(locs);
		
		if (num <=2 ) {
			map.SetZoomLevel(15);
		}

		SetSliderLevel(map.GetZoomLevel());
	}


    function getDirections(starting, ending) {
    	// If the browser is Firefox get the version number
		var ffv = 0;
		var ffn = "Firefox/"
		var ffp = navigator.userAgent.indexOf(ffn);
		if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
		// If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
		if (ffv >= 1.5) {
		  Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
		}

    	map = new VEMap('myMap');		
		map.LoadMap();
		map.AttachEvent('onendzoom', SetSliderEvent);
		map.HideDashboard();
		createControl();	
		
        map.GetRoute(starting,
        		 ending,                 
                 null,
                 VERouteType.Quickest,
                 printRoute);
    }
    
    
    function addPin(title,address,lat,long,image) {
    	pinString += title + ";" + address + ";" + lat + ";" + long + ";" + image + "|";
    }        
   		
		
	function printRoute(route) {
    	var routeInfo = new StringBuilder();
     	routeInfo.append('<div class="glob_results_hdr_container" style="margin:10px 0 0 0;">');
		routeInfo.append('<div class="glob_results_hdr_col_1" style="margin-left:5px;">Route Info:</div>');
		routeInfo.append('<div class="glob_results_hdr_col_2"><b>Total Distance:</b> ' + route.Itinerary.Distance + ' mi. | <a href="javascript:window.print();">PRINT PAGE</a></div>');
		routeInfo.append('<div style="clear:both;"></div></div>');
		routeInfo.append('<div class="directions_list"><ol>');
		
		var len = route.Itinerary.Segments.length;
        for(var i = 0; i<len ;i++) {
	        routeInfo.append('<li><span style="font-weight:normal;">' + route.Itinerary.Segments[i].Instruction + ' -- ');
            routeInfo.append('(' + route.Itinerary.Segments[i].Distance + ' mi.) </span></li>');
        }

		routeInfo.append('</ol></div>');
     
        document.getElementById('directions').innerHTML = routeInfo.toString();
     }
     
    
    function createControl() {
		var control = document.createElement("div");
		control.id = "mapControl";
        control.style.top ="10px"; 
        control.style.left = "10px"; 
	
		var controlHtml = new StringBuilder();
		controlHtml.append('<style>');
		controlHtml.append('#translucent { background-color: #f0f0ff; margin:0; padding:0;');
		controlHtml.append('/* the filter attribute is recognized in Internet Explorer and should be a percentage */ ');
		controlHtml.append('filter: alpha(opacity=90);');
		controlHtml.append('/* the -moz-opacity attribute is recognized by Gecko browsers and should be a decimal */');
		controlHtml.append('-moz-opacity: .90;');
		controlHtml.append('/* opacity is the proposed CSS3 method, supported in recent Gecko browsers */');
		controlHtml.append('opacity: .90;');
		controlHtml.append('}');
		controlHtml.append('</style>');
		
		controlHtml.append('<script type="text/javascript" src="/scripts/prototype.js"></script>'); 
    	controlHtml.append('<script type="text/javascript" src="/scripts/slider.js"></script>');
		
  		controlHtml.append('<div style="background-color:#ffffff; height:78px; width:88px;" id="translucent">');
		controlHtml.append('<img name="maptool" src="/images/maptool.gif" width="88" height="78" border="0" usemap="#m_maptool" alt="">');
		controlHtml.append('</div>');
		controlHtml.append('<map name="m_maptool"><area shape="circle" coords="29,49, 7" onclick="CenterMap()" style="cursor:pointer; cursor:hand;" alt="Back to Original" ><area shape="rect" coords="19,26,36,41" onclick="DoPanUp()" style="cursor:pointer; cursor:hand;" alt="Move Up" ><area shape="rect" coords="20,58,37,73" onclick="DoPanDown()" style="cursor:pointer; cursor:hand;" alt="Move Down" ><area shape="rect" coords="37,42,51,57" onclick="DoPanRight()" style="cursor:pointer; cursor:hand;" alt="Move Right" ><area shape="rect" coords="5,42,21,56" onclick="DoPanLeft()" style="cursor:pointer; cursor:hand;" alt="Move Left" ></map>');	  
	  
	  	controlHtml.append('<div style="position:relative; margin:-70px 0 0 5px; font-family:Arial; Helvetica; font-size:9px; font-weight:normal;">');
	  	controlHtml.append('<a id="roadLink" onclick="SetStyleRoad()" style="font-weight:bold; cursor:pointer; cursor:hand; text-decoration:none;">Road</a>&nbsp;&nbsp;<a id="aerialLink" onclick="SetStyleAerial()" style="font-weight:normal; color:#999999; cursor:pointer; cursor:hand; text-decoration:none;">Aerial</a>');
	  	controlHtml.append('</div>');
	  
	  	controlHtml.append('<div id="track" style="position:relative; margin:-12px 0 0 68px; height:65px; width:11px; background-image:url(/images/slidervert.gif); background-repeat:no-repeat;">');
    	controlHtml.append('<div id="handle" style="position:relative; height:8px; width:21px; background-image:url(/images/sliderhandle.gif); background-repeat:no-repeat; margin-left:-5px;"></div>');
		controlHtml.append('</div>');
	  	
	  	control.innerHTML = controlHtml;
	  		  	
	  	map.AddControl(control);
	  	
	  	createSlider();
	  	
	}					
	
     
     
     
     function getURLParam(strParamName){
		var strReturn = "";
		var strHref = window.location.href;

		if ( strHref.indexOf("?") > -1 ){
			var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
			var aQueryString = strQueryString.split("&");

			for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){

				if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
					var aParam = aQueryString[iParam].split("=");
					strReturn = aParam[1];
					break;
				}
			}
		}
	
		return strReturn;
	}
	
	
	
	function show(id, num) {
		if (id == 'dirFrom') {
			document.getElementById('dirFrom'+num).style.display="block";
			document.getElementById('dirTo'+num).style.display="none";
			
			document.getElementById('fromLink'+num).style.fontWeight="bold";
			document.getElementById('toLink'+num).style.fontWeight="normal";
		} else {
			document.getElementById('dirTo'+num).style.display="block";
			document.getElementById('dirFrom'+num).style.display="none";
			
			document.getElementById('toLink'+num).style.fontWeight="bold";
			document.getElementById('fromLink'+num).style.fontWeight="normal";
		}
	}
	
	
	function createSlider() {
	   	sl = new Control.Slider(
	    	'handle',
		    'track',
	    	{ axis:'vertical',
	    	values:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],
		    range:$R(20,0), 
	    	sliderValue:4,
	    	onSlide:function(v){ SetZoom(v); }, 
		    onChange:function(v){ SetZoom(v); }
	    	}
	   	);
	}
	
	// ### Map Navigation functions ###	
	function CenterMap() {
		DoBestMap(locs, num);
	}
	
	function DoPanUp() {
		map.Pan(0, -50);
	}
		
	function DoPanDown() {
		map.Pan(0, 50);
	}
	
	function DoPanRight() {
		map.Pan(50, 0);
	}
	
	function DoPanLeft() {
		map.Pan(-50, 0);
	}
	
	function SetStyleRoad() {
		document.getElementById('roadLink').style.fontWeight = 'bold';
		document.getElementById('roadLink').style.color = '#000000';
		document.getElementById('aerialLink').style.fontWeight = 'normal';
		document.getElementById('aerialLink').style.color = '#999999';
		map.SetMapStyle(VEMapStyle.Road);
	}
	
	function SetStyleAerial() {
		document.getElementById('roadLink').style.fontWeight = 'normal';
		document.getElementById('roadLink').style.color = '#999999';
		document.getElementById('aerialLink').style.fontWeight = 'bold';
		document.getElementById('aerialLink').style.color = '#000000';
		map.SetMapStyle(VEMapStyle.Aerial);	
	}
	
	function SetZoom(level) {
		map.SetZoomLevel(level);
	}
	
	function SetSliderEvent(e) {
		sl.setValue(e.view.zoomLevel);
	}
	
	function SetSliderLevel(level) {
		sl.setValue(level);
	}
	
	
	// ### String builder functions ###
	function StringBuilder(value) {
	    this.strings = new Array("");
	    this.append(value);
	}
	
	// Appends the given value to the end of this instance.
	StringBuilder.prototype.append = function (value) {
	    if (value)
	    {
	        this.strings.push(value);
	    }
	}
	
	// Clears the string buffer
	StringBuilder.prototype.clear = function () {
	    this.strings.length = 1;
	}
	
	// Converts this instance to a String.
	StringBuilder.prototype.toString = function () {
	    return this.strings.join("");
	}