    //Begins 
     function loadScript() {
     	var script = document.createElement('script');
     	script.type = 'text/javascript';
     	script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&key=AIzaSyDfW9YcvZCJafB-k2c-SBaBhGOvcy5f148' +
     		'&callback=initialize';
     	document.body.appendChild(script);
     }

     window.onload = loadScript;
     //var executed=false;
     var projectpng='/static/images/google_maps_icon/project.png';
     var z;
     var map;
     
  	var marker;
  	var mapOptions;
  	var ZOOM=4;
     //Functions for current real time positions

     	function geocodePosition(pos) {
     		geocoder = new google.maps.Geocoder();
     		geocoder.geocode({
     			latLng: pos
     		},

     		function(results, status) {
     			if (status == google.maps.GeocoderStatus.OK) {
     				$('[name=full_address]').val(results[0].formatted_address);
     				$('[name=lat]').val(results[0].geometry.location.lat);
     				$('[name=lng]').val(results[0].geometry.location.lng);
                         $(".business_coords")[0].value = results[0].geometry.location.lat + "," + results[0].geometry.location.lng;
     				$("#mapErrorMsg").hide(100);
     			} else {
     				$("#mapErrorMsg").html('Cannot determine address at this location.' + status).show(100);
     			}
     		});
     	}    	
     	function geocodeAddress() {
     		var ajson = "https://maps.googleapis.com/maps/api/geocode/json?address=" + $('[name=full_address]').val()
     		$.ajax({
     			dataType: "json",
     			url: ajson,
     			success: function(d) {
     				z = d.results[0].geometry.location
     				$('[name=lat]').val(z.lat);
     				$('[name=lng]').val(z.lng);
     				marker.setPosition(z);
     				map.setCenter(z);
     			}
     		});
     	}

     	function initializeProjectEdit() {
     		var posLatLngHome
     		if($('[name=lat]').val() == '39.9129412') //Default geolocation of nothing (near denver)
     		{
     			posLatLngHome = new google.maps.LatLng("<?= $project['lat'] ?>", "<?= $project['lng'] ?>");
     		} else {
     			posLatLngHome = new google.maps.LatLng($('[name=lat]').val(), $('[name=lng]').val());
     		}
     		marker = new google.maps.Marker({
     			position: posLatLngHome,
     			draggable: true,
     			animation: google.maps.Animation.DROP,
     			map: map,
     			title: 'Office',
     			icon: projectpng

     		});
     		google.maps.event.addListener(marker, 'dragend', function() {
     			geocodePosition(marker.getPosition());
     		});



     	}
     function initialize() {
     	var posLatLngHome = new google.maps.LatLng($('[name=lat]').val(), $('[name=lng]').val());
     	mapOptions = {
     		zoom: ZOOM,
     		center: posLatLngHome,
            scrollwheel: false
     	}

          map_elm = document.getElementById('map-canvas');
     	map = new google.maps.Map(map_elm, mapOptions);
     	
     	marker = new google.maps.Marker({
     		position: posLatLngHome,
     		draggable: true,
     		animation: google.maps.Animation.DROP,
     		map: map,
     		title: 'Office Position!',
     		icon: projectpng

     	});
     	google.maps.event.addListener(marker, 'dragend', function() {
      		geocodePosition(marker.getPosition());
      	});
     }
     	
     
     