 	
 	  // Cinnamon Blur / Robert Jones / December 2010
 	
 	  var lastMap
 	  
    var shopData  = { "Lat"       : 1,
                      "Lng"       : 1,
                      "ShopName"  : "",
                      "ShopTel"   : "",
                      "ShopEmail" : ""
                       };

	 	
	 	function setShopData (pshopData) {
        shopData.Lat       = pshopData.Lat;
        shopData.Lng       = pshopData.Lat;
        shopData.ShopName  = pshopData.ShopName;
        shopData.ShopTel   = pshopData.ShopTel;
        shopData.ShopEmail = pshopData.ShopEmail;
    } 	
	
		function ShowMapData(pmyMapData) {
		
			var myLat = pmyMapData.Lat;
			var myLng = pmyMapData.Lng;

      // offset the center of the map to allow room for the info window to display
			var myMapLng = myLng;
			var myMapLat = myLat + 0.002;
			
      var myLatlng = new google.maps.LatLng(myLat, myLng); 
      var myMapLatlng = new google.maps.LatLng(myMapLat, myMapLng); 
     
      // set options for map display
      var myOptions = {
          zoom: 15,
          center: myMapLatlng,
          navigationControl: true,
          navigationControlOptions: {
             style: google.maps.NavigationControlStyle.SMALL
             },
          mapTypeId: google.maps.MapTypeId.ROADMAP
          }
          
      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
 
      // style the content of the info window 
      var contentString = '<div id="map_content">'+
          '<span id="map_shopname" >' + pmyMapData.ShopName + '</span><br />'+
          '<span id="map_tel">Tel: ' + pmyMapData.ShopTel + ' </span><br />' +
          '<span id="map_email">Email: <a href="mailto:' + pmyMapData.ShopEmail + '">' +
          pmyMapData.ShopEmail + '</a></span>'+
          '</div>';

      // setup the info window with content from above. disable pan to stop it centering in the map
      var infowindow = new google.maps.InfoWindow({
          content: contentString,
          disableAutoPan: true
          });
  
      // define the marker for the shop
      var marker = new google.maps.Marker({
          position: myLatlng,
          title: pmyMapData.ShopName,
          map: map
           });

      // display the info window at the marker position  
      infowindow.open(map,marker);
  
      // ** instead of auto showing - could setup event for click on marker to show info window
      // google.maps.event.addListener(marker, 'click', function() {
      // infowindow.open(map,marker);
      // });
  
      // save map data for directions
      lastMap = pmyMapData

  }

  function getDirections(pElement) {
  	
  	  var directionsDisplay = new google.maps.DirectionsRenderer();;
      var directionsService = new google.maps.DirectionsService();

      var start = document.getElementById(pElement).value;
      var end = new google.maps.LatLng(lastMap.Lat,lastMap.Lng);

      document.getElementById('map_directions').innerHTML = "";

      directionsDisplay.setPanel(document.getElementById("map_directions"));
      var myOptions = {
          zoom: 14,
          mapTypeId: google.maps.MapTypeId.ROADMAP
          }
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
      directionsDisplay.setMap(map);

      // build the options for direction request
      var request = {
          origin:start, 
          destination:end,
          provideRouteAlternatives: false,
          travelMode: google.maps.DirectionsTravelMode.DRIVING,
          unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL
          };
      directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
         directionsDisplay.setDirections(response);
      } else {
      	alert('Sorry, unable to get directions for route.');
      }
      
    });
    
  }

   printMap = function(){
        var a = window.open('','','width=300,height=300');
        a.document.open('text/html');
        a.document.write(document.getElementById('map_directions').innerHTML);
        a.document.close();
        a.print();
        a.close();
    }


