 var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map;
  var selectedMode = 'DRIVING';

  function initialize() {
 	directionsDisplay = new google.maps.DirectionsRenderer();
    var latlng = new google.maps.LatLng(40.7087918, -73.9731807);
    var latlngHome = new google.maps.LatLng(40.7087918, -73.9431807);
    var MY_MAPTYPE_ID = 'NH';
    var stylez = [
    {
      featureType: "road",
      elementType: "all",
      stylers: [
        { hue: "#ffffff" },
        { saturation: -100 },
		{ lightness: 40}
      ]
    },
    {
      featureType: "landscape",
      elementType: "all",
      stylers: [
        { hue: "#ffffff" },
        { saturation: 0 },
        { lightness: 100}
      ]
    },
	 {
      featureType: "transist",
      elementType: "all",
      stylers: [
        { hue: "#ffffff" },
        { saturation: -10 },
        { lightness: 30}
      ]
    },
	{
	 featureType: "water",
      elementType: "all",
      stylers: [
        { hue: "#0091ff" },
        { saturation: 0 },
        { lightness: 10}
      ]
    },
	{ featureType: "poi", 
	elementType: "all", 
	stylers: [ { visibility: "simplified" }, 
			  { hue: "#fff700" },
			  { saturation:	40}] },
	{ featureType: "road.highway", 
	elementType: "all", 
	stylers: [ { visibility: "off" }] },
	{ featureType: "transit", 
	elementType: "all", 
	stylers: [ { visibility: "off" }] },
	{ featureType: "administrative", 
	elementType: "all", 
	stylers: [ { visibility: "simplified" }] }
  ];

  var mapOptions = {
    zoom: 12,
    center: latlng,
    mapTypeControlOptions: {
       mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
    },
    mapTypeId: MY_MAPTYPE_ID,
    disableDefaultUI: true
  };

  map = new google.maps.Map(document.getElementById("fs_map"),
      mapOptions);
      
  var styledMapOptions = {
    name: "Missed C"
  };

  var jayzMapType = new google.maps.StyledMapType(stylez, styledMapOptions);
  
  map.mapTypes.set(MY_MAPTYPE_ID, jayzMapType);
  
  var image = 'images/mapPin.png';	
  var addMarker = function(){

	var marker = new google.maps.Marker({
	  position: latlngHome,
	  map: map,
	  icon: image
	});
	
	 var content = '<strong>omg hey yo yay !!</strong>';

	  infowindow = new google.maps.InfoWindow({
	    content: content
	  });
	google.maps.event.addListener(marker, 'click', function() {
      infowindow.open(map, this);
    });

	}  
    google.maps.event.addListener(map, 'tilesloaded', addMarker);
   
    directionsDisplay.setMap(map);
  }

 
  function calcRoute() {
  	if(ufo.aniStats.contact == 0) ufo.contactPage();
  	var text;
  	var duration;
    var start = '162 scholes st. Brooklyn, NY 11206';
    var end = document.getElementById('address').value;
    if(end==''){
    	text = 'Your address is empty?! : (';
    	paperOpen(true, text);
    	return;
    }
    var request = {
        origin:start, 
        destination:end,
        travelMode: google.maps.DirectionsTravelMode[selectedMode]
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
        duration = response.routes[0].legs[0].duration;
       //value
       	
       	switch(selectedMode){
       		case "DRIVING":
	   			if(duration.value < 4000){
	   	     		
	       		text = 'Yay, it only takes '+duration.text+' ! We are close, let\'s hang out!'	
	       	
		       	}else if(duration.value < 10000){
		       		
		       		text = 'It takes '+duration.text+' ! We aren\'t far away, right? '
		       		
		       	}else{
		       		text = 'Oh wow, '+duration.text+' ?! That\'s a bit far, but we can work it out.'
		       	}

       		break;
       		
       		case "WALKING":
      	 		if(duration.value < 3000){
	   	     		
	       		text = 'Wow, it only takes '+duration.text+' ! We are close, let\'s have a beer!'	
	       	
		       	}else if(duration.value < 10000){
		       		
		       		text = 'It takes '+duration.text+' ! My legs are sour already. '
		       		
		       	}else{
		       		text = 'Omg, '+duration.text+' ?! Is there a better way than walking?'
		       	}
       		break;
       		
       		case "BICYCLING":
       		
       			if(duration.value < 3000){
	   	     		
	       		text = 'Wow, it only takes '+duration.text+' ! We are close. Let\'s hang out!'	
	       	
		       	}else if(duration.value < 10000){
		       		
		       		text = 'It takes '+duration.text+' ! I will try to get there by my lovely bike '
		       		
		       	}else{
		       		text = 'Jeez '+duration.text+' ?! My bicycle wheels are on fire.'
		       	}
       		break;
       	
       	}
       	      
      }else{
      	text = 'Sorry, there\'s an error : ( Wanna send me an email?'
      }
      paperOpen(true, text);
    });
  }

