// JavaScript Document
var directionDisplay;
  var directionsService;
  var map;
  var college
 var geocoder;
  var searcher;
  var searchGoogle;
  function initialize_map(postcode) {
	 searchGoogle = new google.search.LocalSearch(); 
  	geocoder = new google.maps.Geocoder(); 
	directionsService = new google.maps.DirectionsService();
    directionsDisplay = new google.maps.DirectionsRenderer();
    college = new google.maps.LatLng(52.5762535, -0.2375547);
    var myOptions = {
      zoom:15,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: college
    }
    map = new google.maps.Map(document.getElementById("mapcontainer"), myOptions);
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));
    searchGoogle.execute( postcode+",UK" ); 
    searchGoogle.setSearchCompleteCallback(null,function() { 
        if (searchGoogle.results[0]) { 
          var resultLat = searchGoogle.results[0].lat; 
          var resultLng = searchGoogle.results[0].lng; 
          college = new google.maps.LatLng(resultLat,resultLng); 
          map.setCenter(college); 
          var marker = new google.maps.Marker({ 
              map: map,  
              position: college
          }); 
          //callbackFunction(point); 
        }else{ 
          //alert("Postcode not found!"); 
        } 
      }); 
	//map.addOverlay(marker); // add the marker to the map	  
  }
  function initialize_event_map(){
	  searchGoogle = new google.search.LocalSearch(); 
	  geocoder = new google.maps.Geocoder(); 
	  college = new google.maps.LatLng(52.5762535, -0.2375547);
	  var myOptions = {
	      zoom:15,
	      mapTypeId: google.maps.MapTypeId.ROADMAP,
	      center: college
	    }
	    map = new google.maps.Map(document.getElementById("eventmap"), myOptions);
  }
  function codeAddress(postcode) {
      searchGoogle.execute( postcode+",UK" ); 
      searchGoogle.setSearchCompleteCallback(null,function() { 
          if (searchGoogle.results[0]) { 
            var resultLat = searchGoogle.results[0].lat; 
            var resultLng = searchGoogle.results[0].lng; 
            var point = new google.maps.LatLng(resultLat,resultLng); 
            map.setCenter(point); 
            var marker = new google.maps.Marker({ 
                map: map,  
                position: point
            }); 
            //callbackFunction(point); 
          }else{ 
            //alert("Postcode not found!"); 
          } 
        }); 



  /*  if (geocoder) { 
      geocoder.geocode( { 'address': postcode}, function(results, status) { 
        if (status == google.maps.GeocoderStatus.OK) { 
          map.setCenter(results[0].geometry.location); 
          var marker = new google.maps.Marker({ 
              map: map,  
              position: results[0].geometry.location
          }); 
          
        } 
      }); 
    }*/ 
  }
  function calcRoute() {
	  searchGoogle.setSearchCompleteCallback(null,function() { 
          if (searchGoogle.results[0]) { 
            var resultLat = searchGoogle.results[0].lat; 
            var resultLng = searchGoogle.results[0].lng; 
            var point = new google.maps.LatLng(resultLat,resultLng); 
            show_route(point);
            //callbackFunction(point); 
          }else{ 
            //alert("Postcode not found!"); 
          } 
        }); 
	  searchGoogle.execute( document.getElementById("address").value+",UK" );    
  }
  function show_route(start){
	    var end =college;
	    var request = {
	        origin:start, 
	        destination:end,
	        travelMode: google.maps.DirectionsTravelMode.DRIVING
	    };
	    directionsService.route(request, function(response, status) {
	      if (status == google.maps.DirectionsStatus.OK) {
	        directionsDisplay.setDirections(response);
	      }
	    });
  }
function change_font(size){
	 $("body").css("font-size", size+"px"); 

}