var map;
var localSearch = new GlocalSearch();

var icon = new GIcon();
icon.image = "http://www.google.com/mapfiles/marker.png";
icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
icon.iconSize = new GSize(20, 34);
icon.shadowSize = new GSize(37, 34);
icon.iconAnchor = new GPoint(10, 34);

function initialize_map(map_name, longtitude, latitude) {
   if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById(map_name));
    map.setCenter(new GLatLng(longtitude,latitude),13);
    map.addControl(new GLargeMapControl());
    map.addControl(new GOverviewMapControl());
    map.enableDoubleClickZoom();
    bounds = map.getBounds();
   
    var point = new GLatLng(longtitude, latitude);
    map.addOverlay(new GMarker(point));    
  }
}

function usePointFromPostcode(postcode, mapid) {
	
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById(mapid));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.checkResize();
		
	}
	localSearch.setSearchCompleteCallback(null, 
		function() {
			
			if (localSearch.results[0])
			{		
				var resultLat = localSearch.results[0].lat;
				var resultLng = localSearch.results[0].lng;
				var point = new GLatLng(resultLat,resultLng);
				//callbackFunction(point);
			    var marker = new GMarker(point,icon);
			    map.setCenter(point, 13);
			    map.addOverlay(marker);
			   
			    
			}else{
				alert("Postcode not found!");
			}
		});	
		
	localSearch.execute(postcode);
}


function getContactPDFMap(){
    var lat = document.getElementById('hdnLat').value;
    var lng = document.getElementById('hdnLng').value;
  
    if((lat.length>0)&&(lng.length>0))
       initialize_map('contact_map', lng, lat);
       
       
}




function expand_div(id, longtitude, latitude){
    
    var more_div  = document.getElementById(id + "_container");
    var more_image = document.getElementById(id + "_expand_image");
    
    if (more_div.style.display == "none"){
        more_div.style.display = "block";
        more_image.src = "/img/cms/collapse_icon.gif";
 
        initialize_map(id + "_map", longtitude, latitude)

    
    }else{
        more_div.style.display = "none";
        more_image.src = "/img/cms/expand_icon.gif";
    }
}

function expand_person_office(id){

    var more_div = document.getElementById("personoffice_" + id + "_container");
      var more_image = document.getElementById("personoffice_" +id + "_expand_image");
      
    if (more_div.style.display == "none"){
        more_div.style.display = "block";
        more_image.src = "/img/cms/collapse_icon.gif";
    
    }else{
        more_div.style.display = "none";
        more_image.src = "/img/cms/expand_icon.gif";
    }
}



