// JavaScript Document

//Description: Functions of google maps for the location
//Author: Paula Andrea Bejarano Garcia



var map; 

var geocoder;

var xhr;

var marker;

var locationIcon = new GIcon();


function load() {

		if (GBrowserIsCompatible()) {

	
			xhr = GXmlHttp.create();//createRequest();
	
			geocoder = new GClientGeocoder();
	
	
			// create map
	
			map = new GMap2(document.getElementById("map"));
	
	
	
			map.addControl(new GLargeMapControl());
	
			map.addControl(new GMapTypeControl());
	
			
		     locationIcon.image = site+"images/"+site_name+"location.png";
			locationIcon.iconSize = new GSize(21, 48);
			locationIcon.shadowSize = new GSize(21, 48);
			locationIcon.iconAnchor = new GPoint(9, 21);
			locationIcon.infoWindowAnchor = new GPoint(9, 2);
			locationIcon.infoShadowAnchor = new GPoint(21, 48);
			locationIcon.transparent =  site+"images/"+site_name+"location.png";
			locationIcon.printImage =  site+"images/"+site_name+"location.png";
			locationIcon.mozPrintImage =  site+"images/"+site_name+"location.png";


   		}
}

 
function clean(){
	map.clearOverlays();	 
}

function centermap(){
	geocoder.getLatLng("9 Coonuc Road, Traralgon VIC 3844", function(point){map.setCenter(point, 13)});	
}

function addLocation(title,short_description,date_start,date_end,lat,lng,street,suburb,state,postcode){

		createMarker(title,short_description,date_start,date_end,lat,lng,street,suburb,state,postcode);

}


function createMarker(title,short_description,date_start,date_end,lat,lng,street,suburb,state,postcode) { 



	var point = new GLatLng(lat, lng);


	
	var marker = new GMarker(point,locationIcon); 

	//var streetOverlay = new GStreetviewOverlay();

	 GEvent.addListener(marker, "click", function() { 



		

	    var html= "<div id='location-description'>";

	    html+="<div id='location-title'>";
	    html+= title;
		html+="</div>";
		html+="<div id='location-text'>";
		html+= street+" "+suburb+", "+state+" "+postcode;
	    html+="<div id='location-short-description'>";
		html+= short_description;
		html+="</div>";
	    html+="<div id='location-date'>";
		html+= "<span>Date: </span>"+date;
		html+="</div>";
	    html+="<div id='location-time'>";
		html+= "<span>Time: </span>"+get_time(date_start)+"-"+get_time(date_end);
		html+="</div>";
		html+="</div>";
	    html+="<div id='location-thumbnail'>";
		html+= "<img src='http://cbk0.google.com/cbk?output=thumbnail&w=90&h=68&ll="+lat+","+lng+"&thumb=0'/>";
		html+="</div>";
		html+= "</div>";


    	marker.openInfoWindowHtml(html); 
		


 	}); 

	
	map.setCenter(point, 7);  
	map.addOverlay(marker);
	
}   




		
function click_location(){
	var streetname = document.getElementById("streetname").value;
	var suburb = document.getElementById("suburb").value;
	var postcode = document.getElementById("postcode").value;
	var state = document.getElementById("state").value;
	var address = ""+streetname+" "+suburb+" "+state+" "+postcode+" , Australia";
	
		geocoder.getLatLng(address, function(point) {

			if (!point) {

				alert(address + " not found");

			} 

			else{

				if(marker){
					map.removeOverlay(marker);
				}
				marker = new GMarker(point); 
	            var lat=point.lat();
				var lng=point.lng();
								
				document.getElementById("lat").value = ""+lat;
				document.getElementById("lng").value = ""+lng;	
				map.setCenter(point, 12);  
				map.addOverlay(marker);	
				

			}

		});
		
		
		
				
		
}





