	
	/*     GOOGLE MAP WITH MULTIPLE ADDRESS MARKERS        */	
	
	var tp_mapDiv = "tp_mapContainer";
    var tp_mapContainer = null;    
	var tp_mapIndex = 0;
	var tp_mapAddresses = null;
	var tp_mapAddrType = 0;
	
	function tp_map_load(lat,lon){
      if(GBrowserIsCompatible()){
        tp_mapContainer = new GMap2(document.getElementById(tp_mapDiv));
        tp_mapContainer.addControl(new GSmallMapControl());
        tp_mapContainer.addControl(new GMapTypeControl());	
		var mydefaultPoint = new GLatLng(lat, lon);
		var desc = (tp_mapAddrType==0)? tp_eventTitle : tp_mapAddresses[tp_mapIndex].description;
        tp_mapContainer.setCenter(mydefaultPoint, 12);        
        var marker = new GMarker(mydefaultPoint);
        GEvent.addListener(marker, "click", function(){ marker.openInfoWindowHtml('<div style="width:200px">' +  desc + '</div>');}); 
        tp_mapContainer.addOverlay(marker);
      }
    };
	
    function tp_map_AddMarker(lat,lon){
      var marker = new GMarker(new GLatLng(lat, lon));	  
      var desc = tp_mapAddresses[tp_mapIndex].description;
	  GEvent.addListener(marker, "click", function(){ marker.openInfoWindowHtml('<div style="width:200px">' +  desc + '</div>');});
      tp_mapContainer.addOverlay(marker);
    };
	
	function GeoCodeObject() { }
	YGeoCode = new GeoCodeObject();
	YGeoCode.getPoint = function(d){ 	  
	  if(tp_mapContainer != null){tp_map_AddMarker(d.GeoPoint.Lat,d.GeoPoint.Lon);}
	  else{tp_map_load(d.GeoPoint.Lat,d.GeoPoint.Lon);}	  
	
	  if(tp_mapAddrType==0)return;
	  tp_mapIndex++;
	  if(tp_mapIndex >= tp_mapAddresses.length)return;	  
	  setTimeout(function(){tp_map_geoCodeAddress(tp_mapAddresses[tp_mapIndex].address)},0);
	};

	var requestId = 0;
	function tp_map_geoCodeAddress(address) {
	 requestId++;
	  var head = document.getElementsByTagName("head")[0];
	  script = document.createElement('script');
	  script.id = 'geocode'+requestId;
	  script.type = 'text/javascript';
	  script.src = "http://api.maps.yahoo.com/ajax/geocode?appid=batchGeocode&qt=3&id="+requestId+"&qs="+encodeURI(address);
	  head.appendChild(script);	  
      script.onreadystatechange=function (){
		if (this.readyState == 'complete') {	
			document.getElementsByTagName('head')[0].removeChild(this);
		}
      }	    
      script.onload=function(){
        document.getElementsByTagName('head')[0].removeChild(this);
      }
	};
		 
    function tp_map_findLocation(obj){
      if(obj == null)return;
	  if(typeof(obj)=='string' && obj.length>0){
	    tp_map_geoCodeAddress(obj);		
		return;
	  }	  
	  tp_mapAddresses = tp_map_mergeAddressDetails(obj.AddressDetails);
	  if(tp_mapAddresses == null || tp_mapAddresses.length == 0)return;
	  tp_mapAddrType = 1;
	  tp_map_geoCodeAddress(tp_mapAddresses[tp_mapIndex].address);
    };
	
	function tp_map_mergeAddressDetails(objAD){
	  var AD=objAD;var _AD=[];var adDesc='';
	  AD.sort(tp_map_sortByAddress);	 
	  for(var i=0;i<objAD.length;i++){
	    if(i==0){adDesc=AD[i].description;_AD.push(AD[i]);}	    
		if((i+1)!=objAD.length){
		  if(AD[i].address==AD[(i+1)].address){		  
		   adDesc += '<br /><br />' + AD[(i+1)].description;
		   if((i+2)==objAD.length){			  
		     AD[i].description=adDesc;
			  _AD.push(AD[i]);
			}
		  }else{
		    AD[i].description=adDesc;
			_AD.push(AD[i]);
			adDesc=AD[(i+1)].description;
			if((i+2)==objAD.length){_AD.push(AD[(i+1)]);}
		  }
	    }
	  }return _AD;
	};
	
	function tp_map_sortByAddress(a, b){
	  var x = a.address.toLowerCase();
	  var y = b.address.toLowerCase();
	  return ((x<y)?-1:((x>y)?1:0));
    };	
	
	function AddressDetails(address, description){ 
	  this.address=address;this.description=description;  
	};
	
	//============================================
	/*  HOW TO USE THIS STUFF:
	//  Add the google script and provide and API KEY to your corresponding domain
	//  Get an API KEY here : http://www.google.com/apis/maps/signup.html
	//  Example:
	//      <!--<script src="http://maps.google.com/maps?file=api&amp;v=2.77&amp;key=<API KEY HERE>" type="text/javascript"></script>-->
	// 	
	//  NEXT STEP: 
	
	//=========================================================================================	
	// Using Single Address
	//=========================================================================================	
		<script type="text/javascript">
		var tp_eventTitle='Tyler\'s Farmers Market';window.onunload = function(){GUnload();}
		window.onload = function(){tp_map_findLocation('2112 W Front St, Tyler, TX,');}
		</script>
	
	
	//=========================================================================================	
	// Using Multiple Addresses
	//=========================================================================================
	//
	//  FORMING A JSON STRING or JSON OBJECT FOR ADDRESS DETAILS parameter
	
	/*
		//======================================================================================
		// Form a JSON String for the address parameter
		//======================================================================================
		var JSONtext = 
			eval(
				'({"AddressDetails":\
				  [\
				    {"address":"Atlanta, GA","description":"This is atlanta GA"},\
				    {"address":"Add address here","description":"Add description here"},\
					{"address":"Add address here","description":"Add description here"},\
					{"address":"Add address here","description":"Add description here"},\
					{"address":"Add address here","description":"Add description here"},\
					{"address":"Add address here","description":"Add description here"}\
				  ]\
				})'
			);
			
		//======================================================================================
		// Form a JSON Object for the address parameter
		//======================================================================================
		var JSONtext = new Object();
		JSONtext.AddressDetails = [];

		//Using in a loop
		for(var x=0;x<=6;x++){
		  JSONtext.AddressDetails.push(new AddressDetails('Atlanta,GA','This is atlanta GA'));
		}

		//or Adding each item
		JSONtext.AddressDetails.push(new AddressDetails('Atlanta,GA','This is atlanta GA'));
		JSONtext.AddressDetails.push(new AddressDetails('Add address here','Add description here'));
		JSONtext.AddressDetails.push(new AddressDetails('Add address here','Add description here'));
		JSONtext.AddressDetails.push(new AddressDetails('Add address here','Add description here'));
		JSONtext.AddressDetails.push(new AddressDetails('Add address here','Add description here'));
		JSONtext.AddressDetails.push(new AddressDetails('Add address here','Add description here'));
		
		//=======================================================================================
		
		
		//Example for displaying the map:
		
		 //  USING THE SCRIPT WITH JSON String Parameter:
		
			<script type="text/javascript">
		 	window.onunload = function(){GUnload();}		
		 	window.onload = function(){
			  var JSONtext = 
				eval(
					'({"AddressDetails":\
					  [\
					    {"address":"Atlanta, GA","description":"This is atlanta GA"},\
					    {"address":"Add address here","description":"Add description here"},\
						{"address":"Add address here","description":"Add description here"},\
						{"address":"Add address here","description":"Add description here"},\
						{"address":"Add address here","description":"Add description here"},\
						{"address":"Add address here","description":"Add description here"}\
					  ]\
					})'
				);
				tp_map_findLocation(JSONtext);					
			}		
			</script>		
		
		 //  USING THE SCRIPT WITH JSON OBJECT Parameter:
		   
			<script type="text/javascript">
		 	window.onunload = function(){GUnload();}		
		 	window.onload = function(){
				var JSONobj = new Object();
				JSONobj.AddressDetails = [];

				//Using in a loop with 6 Address Details example
				for(var x=0;x<=6;x++){
				  JSONobj.AddressDetails.push(new AddressDetails('Atlanta,GA','This is atlanta GA'));
				}

				//or Adding each item			
				JSONobj.AddressDetails.push(new AddressDetails('870 7th Ave, New York','This is atlanta GA'));
				JSONobj.AddressDetails.push(new AddressDetails('70 Park Ave, New York','Add description here'));
				JSONobj.AddressDetails.push(new AddressDetails('2 West St, New York','Add description here'));
				JSONobj.AddressDetails.push(new AddressDetails('36 Central Park S, New York','Add description here'));
				JSONobj.AddressDetails.push(new AddressDetails('40 W 40th St, New York','Add description here'));
				JSONobj.AddressDetails.push(new AddressDetails('122 E 28th St, New York','Add description here'));
				tp_map_findLocation(JSONobj);					
			}		
			</script>
			<div id='tp_mapContainer' style='width:300px;height:300;'></div>
	*/
