var addressAttemp =1;
var geocoder;
var Icon = new GIcon(G_DEFAULT_ICON);
Icon.image = "coldmarker.png";
var side_bar_html = "";
var gmarkers = [];
var htmls = [];
var i = 0;
var map = null;
var centerLocation = null;
var ToolTipData = null;
var attempt =1; 
	function initialize()
    {
      function createMarker(point,name,html,tooltip)
      {
	        var marker = new GMarker(point,{title:tooltip});
	        GEvent.addListener(marker, "click", 
		        function()
		        {
					marker.openInfoWindowHtml("<div align='left' style='width:240px'><font style='Font-Size: 'Smaller';FONT-FAMILY: 'Verdana'><i><b>Name:</b> </i>" + name + "<br>" + "<i><b>Address:</b></i>" + html + "</font></div>");
			        
		        }
		    );
	        gmarkers[i] = marker;
	        htmls[i] = html;
	        i++;
	        return marker;
      }
      
      function myclick(i)
      {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      }
     
	 function addAddressToMap(response)
	 {
	      	map.clearOverlays();
	      	if (!response || response.Status.code != 200)
	      	{
	        	
	        	if(attempt == 2){
	        	   	attempt = 3;
	        	   	showLocation(address1);
	        	}else if(attempt == 1){
	        		attempt = 2;
	        		showLocation(address2);
	        	}else{
	        		alert("Sorry, we were unable to locate that property address");
	        	}
	        	
	      	}
	      	else
	      	{
	        	place = response.Placemark[0];
	        	point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
	        	var marker = createMarker(point,html,label,tooltip);
	        	map.addOverlay(marker);
	        	marker.openInfoWindowHtml("<div align='left' style='width:240px'><font style='Font-Size: 'Smaller';FONT-FAMILY: 'Verdana'><i><b>Name:</b> </i>" + html + "<br>" + "<i><b>Address:</b></i>" + label + "</font></div>");
	      	}
    	}	   
	    function showLocation(address) 
	    {
	    	 var address = address;
	    	 geocoder.getLocations(address, addAddressToMap);
	    }	 
	    map = new GMap2(document.getElementById("map_canvas"));
	    map.setCenter(new GLatLng(28.304380682962783,  -109.6875), 10);
	    map.enableDoubleClickZoom();
	    map.addControl(new GSmallMapControl());
	    map.addControl(new GMapTypeControl());
	    geocoder = new GClientGeocoder();
	    showLocation(address3);
   }  
