// for the google ajax search API for geoencoding - convert postcode into Lng/Lat values
			var localSearch = new GlocalSearch();
			// this function is called from include_markers.php depending on different scenarios
			function usePointFromPostcode(postcode, callbackFunction, search_str) {
				// if postcode field hasn't been changed by the visitor i.e. it has the default value "anywhere" or is empty
				//alert('We are in the usePointFromPostcode function');
				
				if(postcode.indexOf("anywhere")>=0 || postcode=='') {
					var searchEverywhere = 1;
					if (google.loader.ClientLocation)
						postcode=google.loader.ClientLocation.address.country;
					else postcode="united kingdom";
					zoomLevel=5;
					
				}
				else if(postcode.toLowerCase()=="england" || postcode.toLowerCase()=="united kingdom" || postcode.toLowerCase()=="wales" || postcode.toLowerCase()=="scotland" || postcode.toLowerCase()=="northern ireland") {
					zoomLevel=6;
				}
				else {
					//alert("postcode = " +postcode);
					zoomLevel=11;
				}
				// Google search function
  				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);
					
					if(search_str=='')
						callbackFunction(resultLat, resultLng); 
					else if(search_str=='my xibiti') {

						callbackFunction(resultLng, resultLat, postcode); 
					}
					else if ( typeof(searchEverywhere) !="undefined"){
					callbackFunction(point, postcode, search_str, zoomLevel, 10, searchEverywhere); //, zoomlevel);
					}
					else
						// Visitor had a searchterm entered.
						//alert("2 - callbackFunction function called from positioning.js passing variables back to include_markers.php");
						//alert("point = " + point);
						callbackFunction(point, postcode, search_str, zoomLevel, 10); //, zoomlevel);
				  }else{
					alert("Postcode not found!");
				  }
				});  
				
    			localSearch.execute(postcode + ", UK");
			}
			
			//**
			function setMapCenter(map_lat, map_lng, postcode) {
				
				point=new GLatLng(map_lat, map_lng);
				var map = new GMap2(document.getElementById('map'));
				map.addControl(new GLargeMapControl());
          		map.setCenter(point, 12);
			}
			//this is used in the edit item page
			function get_latlng(item_lat, item_lng) {
				document.getElementById("item_lat").value=item_lat;
				document.getElementById("item_lng").value=item_lng;
				point=new GLatLng(item_lat, item_lng);
				map.panTo(point);
				
			}
			// this is used in edit / amend a existing user profile page
			function get_userlatlng(user_lat, user_lng) {
				document.getElementById("userlat").value=user_lat;
				document.getElementById("userlng").value=user_lng;
				
				//point=new GLatLng(item_lat, item_lng);
				//map.panTo(point);
				
			}
			// this is used in new user reg page
			function get_reglatlng(user_lat, user_lng) {
				document.getElementById("LatProfile").value=user_lat;
				document.getElementById("LngProfile").value=user_lng;
				
				//point=new GLatLng(item_lat, item_lng);
				//map.panTo(point);
				
			}
			
			
			
function locate_my_services(point, location, searchStr, zoomLevel, max_records)
				{
					
				//alert("we are in locate_my_services looking at the My-Xibiti page")
				
				if (location == "united kingdom" || location == "United Kingdom"){
					zoomLevel = 5;
					//alert(zoomLevel);
				}
				// need to delete message div already attached to the map pane from previous visits
				var item_id_string="";
				jQuery(".message-popup").remove();
				jQuery("#listings-home").hide();
				var div = jQuery('<div></div')
   				.appendTo(document.body).attr('id', 'message-offered').addClass("message-popup").css({ display:'none'}) ;
				var div = jQuery('<div></div')
   				.appendTo(document.body).attr('id', 'message-wanted').addClass("message-popup").css({ display:'none'}) ;
				
				// loop through element "li" and remove
				jQuery("#list li").each(function() {
							jQuery(this).remove();
				});				
						
				//users postcode			
      			var userLat = point.lat(); 
        		var userLng = point.lng();
				if(zoomLevel<=5)
					radius=600;
				else if(zoomLevel<=7)
					radius=300;
				else if(zoomLevel==8)
					radius=120;
				else if(zoomLevel==9)
					radius=70;
				else if(zoomLevel==10)
					radius=25;
				else if(zoomLevel>=11)
					radius=10;
					
				URLString = "lat="+ userLat + "&lng=" + userLng + "&srch=" + searchStr + "&radius=" + radius + "&max=" + max_records;
				//alert(URLString);
				
				// now we have the xml feed / file
					// create new instance of map object
					var map = new GMap2(document.getElementById('map'));
					
					
					var dragEnd = GEvent.addListener(map, "dragend", function(){
						
						GEvent.removeListener(dragEnd);
						GEvent.removeListener(zoomEnd);
						locate_my_services(map.getCenter(), location, searchStr, zoomLevel, 10); 
					});
					var zoomEnd = GEvent.addListener(map, "zoomend", function(oldzoom, newzoom){
						if(oldzoom && oldzoom!=newzoom) {
							//alert(oldzoom+" "+newzoom);
							GEvent.removeListener(dragEnd);
							GEvent.removeListener(zoomEnd);
							locate_my_services(map.getCenter(), location, searchStr, newzoom,  10); //, map.getZoom());
						}
					});
					map.addControl(new GLargeMapControl());
					// Set general location of map based on inputed postcode	
					var Generallocation = new GLatLng(userLat,userLng);
					map.setCenter(Generallocation, zoomLevel);
										// To add markers to represent local users that are either offering or wanting services
					jQuery.ajax({
						type: "GET",
						url: "/xml_results_localusers.php",
						data: URLString,
						dataType: "xml",
						success: function(data,textStatus) {

							jQuery("Localmarker",data).each(function() {
								var lat = parseFloat(jQuery(this).attr("lat"));
								var lng = parseFloat(jQuery(this).attr("lng"));
								var user_name = jQuery(this).attr("user_name");
								
								var label= jQuery(this).attr("");
								
								var point = new GLatLng(lat,lng);
								
								//var location = jQuery(this).attr("location");
								
								var icon_add=icon4;
								Localopts = { 
								  "icon": icon_add,
								  "clickable": true,
								  "dragabble": false,
								  "labelText": label,
								  "labelOffset":new GSize(-18, -53)
								};
								
								var marker = new LabeledMarker(point, Localopts);	
								GEvent.addListener(marker, "click", function() { 
								window.location.href="/profile/?user="+user_name;										   
								});								
								map.addOverlay(marker);								
							});
							
						}
					});
						
					
			
				jQuery.ajax({type:"GET",url:"/xml_results_myxibiti.php", data: URLString ,dataType:"xml",
				success:function(data,textStatus) {
						var count0=0; var count1=0;
					
					jQuery(".box ul").remove();
					jQuery("<ul />").appendTo("#listings-offered");
					jQuery("<ul />").appendTo("#listings-wanted");
					
					
					// creates a marker for each XML entry retrieved
    				jQuery("marker",data).each(function() {
    					// Attributes for each marker.
						
						var lat = parseFloat(jQuery(this).attr("lat"));
						var lng = parseFloat(jQuery(this).attr("lng"));
						var point = new GLatLng(lat,lng);
						var html = jQuery(this).attr("name");
						var item_id = jQuery(this).attr("id");
						var item_type = jQuery(this).attr("type");
						var item_location = jQuery(this).attr("location");
						
						// added M Jakda 04 / 08 / 2009 
						var date_created = jQuery(this).attr("date_created");
						var msg_count = jQuery(this).attr("msg_count");
						
						var rating_div_width = jQuery(this).attr("div_width");
						item_id_string+=item_id+",";
               			// Create the marker.
						
						if(item_type=="1") {
							var icon_add=icon1;
							count1++;
							var label=count1;
							var box_id="#listings-wanted";
							var message_id="#message-wanted";
						}
						else if (item_type=="0") {
							var icon_add=icon;
							count0++;
							var label=count0;
							var box_id="#listings-offered";
							var message_id="#message-offered";	
						}
						opts = { 
						  "icon": icon_add,
				          "clickable": true,
				          "labelText": label,
				          "labelOffset": new GSize(-18, -53)
				        };
						
               			var marker = new LabeledMarker(point, opts);
						
						//add to list on the right hand side
						jQuery("li").addClass("msg-include");
    	   				jQuery("<li />").html(html)
                    	.appendTo("#list")
						// When user click on a list item then the map focuses on the related marker and show the message box
						.click(function(){
							displayPoint(marker, html, item_id, message_id);
							show_item(item_id);
						});
						
						var li_html='<div class="item-number">'+label+'</div>';
						li_html+='<div class="item-head"><h4 id="'+item_id+'"></h4><br /><p>Listed on '+ date_created +'</p>';
						li_html+='<p><strong>Location: </strong>'+item_location+' </p>';
						
						
						li_html+='<div class="msg-indicator"><a href="javascript:;" onclick="show_item('+item_id+');">&nbsp;'+ msg_count + '</a></div>'
						li_html+='</div>';
						li_html+='<div class="clear"></div>\n';
						
						jQuery("<li />").html(li_html)
                    	.appendTo(box_id+" ul");
						
						jQuery("<a />").html(html)
						.appendTo("h4#"+item_id)
                    	.css({ cursor:'pointer'})
						// When user click on a list item then the map focuses on the related marker and show the message box
						.click(function(){
							map.panTo(marker.getLatLng());
							show_item(item_id);
						})
						.mouseover(function(){
							displayPoint(marker, html, item_id, message_id);
						});
						
						var rating_html='<div class="listings-feedback-rating"><div class="feedback-stars" style="width:'+rating_div_width+'px"></div><img src="/images/rating-mask-small.png" alt="Item Rating" width="60" height="15" /></div>';
						
						jQuery("h4#"+item_id).append(rating_html);
						
                  		GEvent.addListener(marker, "click", function() {displayItem(marker, html, item_id, message_id);});
						GEvent.addListener(marker, "mouseover", function() {displayPoint(marker, html, item_id, message_id);});
						GEvent.addListener(marker, "mouseout", function() {jQuery(message_id).hide();});
						
               			map.addOverlay(marker);
						// attaches the custom div 'message layer to the google map window pane
               			jQuery(message_id).appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
						//show_item(item_id);
    				});
					
				
					// To display a custom div box instead of the default Google map window
					function displayPoint(marker, content, item_id, message_id){
						jQuery(".message-popup").hide();
						var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
						jQuery(message_id)
						.fadeIn("fast")
						.css({ top:markerOffset.y-100, left:markerOffset.x+15 })
						.html(content);
					
					}	
					function displayItem(marker, content, item_id, message_id){
						jQuery(message_id).hide();
						show_item(item_id);
						map.panTo(marker.getLatLng());	
					}
								
						

					
										
					if(!jQuery("#listings-wanted ul").html()) jQuery("#listings-wanted ul").html("<li>No listings found. Why not <a href=\"/my/\">ADD A LISTING</a> yourself?</li>");
					if(!jQuery("#listings-offered ul").html()) jQuery("#listings-offered ul").html("<li>No listings found. Why not <a href=\"/my/\">ADD A LISTING</a> yourself?</li>");
				},

    			error:function(XMLHTTPRequest,textStatus,errorThrow){
    				alert("Error 101 There was an error retrieving the marker information.");
    			}});
				
					// ******** Mjakda 24 / 07 / 2009 ********* 
						// add users location marker - set in include_markers.php
						if (profilelocation != ""){
							var icon_add=icon3;
							opts = { 
							  "icon": icon_add,
							  "clickable": false,
							  "dragabble": false,
							  "labelOffset":new GSize(-18, -53)
							};
							var Profilemarker = new LabeledMarker(profilelocation, opts);							
							map.addOverlay(Profilemarker);
						}	
						
				
} //end of locate_my_services function

			
			//This does the search
function locateServices(point, location, searchStr, zoomLevel, max_records){
				
				//alert("4 - We have now come from include_markers.php and are in the LocateServices function")
				// need to delete message div from line 104 which is attached to the map pane
				
				var item_id_string="";
				jQuery(".message-popup").remove();
				jQuery("#listings-home").hide();
				var div = jQuery('<div></div')
   				.appendTo(document.body).attr('id', 'message-offered').addClass("message-popup").css({ display:'none'}) ;
				var div = jQuery('<div></div')
   				.appendTo(document.body).attr('id', 'message-wanted').addClass("message-popup").css({ display:'none'}) ;
				
				// loop through element "li" and remove
				jQuery("#list li").each(function() {
							jQuery(this).remove();
				});				
						
				//users postcode			
      			var userLat = point.lat(); var userLng = point.lng();
				if(zoomLevel<=5)
					radius=600;
				else if(zoomLevel<=7)
					radius=300;
				else if(zoomLevel==8)
					radius=120;
				else if(zoomLevel==9)
					radius=70;
				else if(zoomLevel==10)
					radius=25;
				else if(zoomLevel>=11)
					radius=10;
					
				URLString = "lat="+ userLat + "&lng=" + userLng + "&srch=" + searchStr + "&radius=" + radius + "&max=" + max_records;
				//alert("URLString = " + URLString);
				jQuery.ajax({type:"GET",url:"/xml_results.php", data: URLString ,dataType:"xml",
				success:function(data,textStatus) {
					
					// now we have the xml feed / file
					// create new instance of map object
					var map = new GMap2(document.getElementById('map'));
					var dragEnd = GEvent.addListener(map, "dragend", function(){
						
						GEvent.removeListener(dragEnd);
						GEvent.removeListener(zoomEnd);
						locateServices(map.getCenter(), location, searchStr, zoomLevel, 10); 
					});
					var zoomEnd = GEvent.addListener(map, "zoomend", function(oldzoom, newzoom){
						if(oldzoom && oldzoom!=newzoom) {
							//alert(oldzoom+" "+newzoom);
							GEvent.removeListener(dragEnd);
							GEvent.removeListener(zoomEnd);
							locateServices(map.getCenter(), location, searchStr, newzoom,  10); //, map.getZoom());
						}
					});
					map.addControl(new GLargeMapControl());
					// Set general location of map based on inputed postcode	
					var Generallocation = new GLatLng(userLat,userLng);
					map.setCenter(Generallocation, zoomLevel);
					
					var count0=0; var count1=0;
					
					jQuery(".box ul").remove();
					jQuery("<ul />").appendTo("#listings-offered");
					jQuery("<ul />").appendTo("#listings-wanted");
					
					
					// creates a marker for each XML entry retrieved
    				jQuery("marker",data).each(function() {
    					// Attributes for each marker.
						
               			var lat = parseFloat(jQuery(this).attr("lat"));
               			var lng = parseFloat(jQuery(this).attr("lng"));
               			var point = new GLatLng(lat,lng);
               			var html = jQuery(this).attr("name");
						var item_id = jQuery(this).attr("id");
						
						// added M Jakda 04 / 08 / 2009 
						var date_created = jQuery(this).attr("date_created");
						//var msg_count = jQuery(this).attr("msg_count");
						
						var item_type = jQuery(this).attr("type");
						var rating_div_width = jQuery(this).attr("div_width");
						item_id_string+=item_id+",";
               			// Create the marker.
						if(item_type=="1") {
							var icon_add=icon1;
							count1++;
							var label=count1;
							var box_id="#listings-wanted";
							var message_id="#message-wanted";
						}
						else {
							var icon_add=icon;
							count0++;
							var label=count0;
							var box_id="#listings-offered";
							var message_id="#message-offered";	
						}
						opts = { 
						  "icon": icon_add,
				          "clickable": true,
				          "labelText": label,
				          "labelOffset": new GSize(-18, -53)
				        };
						
               			var marker = new LabeledMarker(point, opts);
						
						//add to list on the right hand side
						//jQuery("li").addClass("msg-include");
    	   				jQuery("<li />").html(html)
                    	.appendTo("#list")
						// When user click on a list item then the map focuses on the related marker and show the message box
						.click(function(){
							displayPoint(marker, html, item_id, message_id);
							show_item(item_id);
						});
    			        
						var li_html='<div class="item-number">'+label+'</div>\n';
						li_html+='<div class="item-head"><h4 id="'+item_id+'"></h4><p>&nbsp;</p></div>\n';
						li_html+='<div class="clear"></div>\n'; 
						
						/*var li_html='<div class="item-number">'+label+'</div>';
						li_html+='<div class="item-head"><h4 id="'+item_id+'"></h4><p>Listed on '+ date_created +'</p>';
						
						li_html+='<div class="msg-indicator"><a href="javascript:;" onclick="show_item('+item_id+');">&nbsp;'+ msg_count + '</a></div>'
						li_html+='</div>';
						li_html+='<div class="clear"></div>\n'; */
						
						jQuery("<li />").html(li_html)
                    	.appendTo(box_id+" ul");
						
						jQuery("<a />").html(html)
						.appendTo("h4#"+item_id)
                    	.css({ cursor:'pointer'})
						// When user click on a list item then the map focuses on the related marker and show the message box
						.click(function(){
							map.panTo(marker.getLatLng());
							show_item(item_id);
						})
						.mouseover(function(){
							displayPoint(marker, html, item_id, message_id);
						});
						
							var rating_html='<div class="listings-feedback-rating">';
									rating_html+='<div class="feedback-stars" style="width:';
									rating_html+=rating_div_width;
									rating_html+='px"></div>\n';
									rating_html+='<img src="/images/rating-mask-small.png" alt="Item Rating" width="60" height="15" />';
									rating_html+='</div>';
						
						jQuery("h4#"+item_id).append(rating_html);
						
                  		GEvent.addListener(marker, "click", function() {displayItem(marker, html, item_id, message_id);});
						GEvent.addListener(marker, "mouseover", function() {displayPoint(marker, html, item_id, message_id);});
						GEvent.addListener(marker, "mouseout", function() {jQuery(message_id).hide();});
               			map.addOverlay(marker);
						// attaches the custom div 'message layer to the google map window pane
               			jQuery(message_id).appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
						//show_item(item_id);
    				});
					
					// To display a custom div box instead of the default Google map window
					function displayPoint(marker, content, item_id, message_id){
						jQuery(".message-popup").hide();
						var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
						jQuery(message_id)
						.fadeIn("fast")
						.css({ top:markerOffset.y-100, left:markerOffset.x+15 })
						.html(content);
					
					}	
					function displayItem(marker, content, item_id, message_id){
						jQuery(message_id).hide();
						show_item(item_id);
						map.panTo(marker.getLatLng());	
					}
										
					if(!jQuery("#listings-wanted ul").html()) jQuery("#listings-wanted ul").html("<li>No listings found. Why not <a href=\"/my/\">ADD A LISTING</a> yourself?</li>");
					if(!jQuery("#listings-offered ul").html()) jQuery("#listings-offered ul").html("<li>No listings found. Why not <a href=\"/my/\">ADD A LISTING</a> yourself?</li>");
				},

    			error:function(XMLHTTPRequest,textStatus,errorThrow){
    				alert("Error 101 There was an error retrieving the marker information.");
    			}});
			}
			
// *******************************************


function locate_profile_services(map_lat,map_lng, location, searchStr, zoomLevel, max_records, user_profile_id, user_name)
				{
				//alert("we are in locate_profile_services looking at the profile page");
				if (location == "united kingdom" || location == "United Kingdom"){
					zoomLevel = 5;
				}
				// need to delete message div already attached to the map pane from previous visits
				var item_id_string="";
				jQuery(".message-popup").remove();
				jQuery("#listings-home").hide();
				var div = jQuery('<div></div')
   				.appendTo(document.body).attr('id', 'message-offered').addClass("message-popup").css({ display:'none'}) ;
				var div = jQuery('<div></div')
   				.appendTo(document.body).attr('id', 'message-wanted').addClass("message-popup").css({ display:'none'}) ;
				
				// loop through element "li" and remove
				jQuery("#list li").each(function() {
							jQuery(this).remove();
				});				
						
				//users postcode			
      			var userLat = map_lat; 
        		var userLng = map_lng;
				
				if(zoomLevel<=5)
					radius=600;
				else if(zoomLevel<=7)
					radius=300;
				else if(zoomLevel==8)
					radius=120;
				else if(zoomLevel==9)
					radius=70;
				else if(zoomLevel==10)
					radius=25;
				else if(zoomLevel>=11)
					radius=10;
					
				URLString = "lat="+ userLat + "&lng=" + userLng + "&srch=" + searchStr + "&radius=" + radius + "&max=" + max_records + "&user_profile_id=" + user_profile_id;				
				// now we have the xml feed / file
					// create new instance of map object
					var map = new GMap2(document.getElementById('map'));
					
					point= new GLatLng(userLat, userLng);
					
					profilelocation= new GLatLng(userLat, userLng);
					
					var dragEnd = GEvent.addListener(map, "dragend", function(){
						GEvent.removeListener(dragEnd);
						GEvent.removeListener(zoomEnd);
						locate_profile_services(point.lat(),point.lng(),  location, searchStr, zoomLevel, 10, user_profile_id, user_name); 
					});
					var zoomEnd = GEvent.addListener(map, "zoomend", function(oldzoom, newzoom){
						if(oldzoom && oldzoom!=newzoom) {
							GEvent.removeListener(dragEnd);
							GEvent.removeListener(zoomEnd);
							locate_profile_services(point.lat(),point.lng(), location, searchStr, newzoom,  10, user_profile_id, user_name); //, map.getZoom());
						}
					});
					map.addControl(new GLargeMapControl());
					
					var Generallocation = new GLatLng(userLat,userLng);
					map.setCenter(Generallocation, zoomLevel);
					
					
				
					
			
				jQuery.ajax({type:"GET",url:"/xml_results_userprofile.php", data: URLString ,dataType:"xml",
				success:function(data,textStatus) {
						var count0=0; var count1=0;
					
					jQuery(".box ul").remove();
					jQuery("<ul />").appendTo("#listings-offered");
					jQuery("<ul />").appendTo("#listings-wanted");
					
					
					// creates a marker for each XML entry retrieved
    				jQuery("marker",data).each(function() {
    					// Attributes for each marker.
						
						var lat = parseFloat(jQuery(this).attr("lat"));
						var lng = parseFloat(jQuery(this).attr("lng"));
						var point = new GLatLng(lat,lng);
						var html = jQuery(this).attr("name");
						var item_id = jQuery(this).attr("id");
						var item_type = jQuery(this).attr("type");
						var item_location = jQuery(this).attr("location");
						
						// added M Jakda 04 / 08 / 2009 
						var date_created = jQuery(this).attr("date_created");
						var msg_count = jQuery(this).attr("msg_count");
						
						var rating_div_width = jQuery(this).attr("div_width");
						item_id_string+=item_id+",";
               			// Create the marker.
						
						if(item_type=="1") {
							var icon_add=icon1;
							count1++;
							var label=count1;
							var box_id="#listings-wanted";
							var message_id="#message-wanted";
						}
						else if (item_type=="0") {
							var icon_add=icon;
							count0++;
							var label=count0;
							var box_id="#listings-offered";
							var message_id="#message-offered";	
						}
						opts = { 
						  "icon": icon_add,
				          "clickable": true,
				          "labelText": label,
				          "labelOffset": new GSize(-18, -53)
				        };
						
               			var marker = new LabeledMarker(point, opts);
						
						//add to list on the right hand side
						jQuery("li").addClass("msg-include");
    	   				jQuery("<li />").html(html)
                    	.appendTo("#list")
						// When user click on a list item then the map focuses on the related marker and show the message box
						.click(function(){
							displayPoint(marker, html, item_id, message_id);
							show_item(item_id);
						});
						
						var li_html='<div class="item-number">'+label+'</div>';
						li_html+='<div class="item-head"><h4 id="'+item_id+'"></h4><br /><p>Listed on '+ date_created +'</p>';
						li_html+='<p><strong>Location: </strong>'+item_location+' </p>';
						
						
						li_html+='<div class="msg-indicator"><a href="javascript:;" onclick="show_item('+item_id+');">&nbsp;'+ msg_count + '</a></div>'
						li_html+='</div>';
						li_html+='<div class="clear"></div>\n';
						
						jQuery("<li />").html(li_html)
                    	.appendTo(box_id+" ul");
						
						jQuery("<a />").html(html)
						.appendTo("h4#"+item_id)
                    	.css({ cursor:'pointer'})
						// When user click on a list item then the map focuses on the related marker and show the message box
						.click(function(){
							map.panTo(marker.getLatLng());
							show_item(item_id);
						})
						.mouseover(function(){
											
							displayPoint(marker, html, item_id, message_id);
						});
						
						var rating_html='<div class="listings-feedback-rating"><div class="feedback-stars" style="width:'+rating_div_width+'px"></div><img src="/images/rating-mask-small.png" alt="Item Rating" width="60" height="15" /></div>';
						
						jQuery("h4#"+item_id).append(rating_html);
						
                  		var t1 = GEvent.addListener(marker, "click", function() {displayItem(marker, html, item_id, message_id);});
						var t2 = GEvent.addListener(marker, "mouseover", function() {displayPoint(marker, html, item_id, message_id);});
						var t3 = GEvent.addListener(marker, "mouseout", function() {jQuery(message_id).hide();});
					
						
               			map.addOverlay(marker);
						// attaches the custom div 'message layer to the google map window pane
               			jQuery(message_id).appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
						//show_item(item_id);
						
    				});
					
				
				
					// To display a custom div box instead of the default Google map window
					function displayPoint(marker, content, item_id, message_id){
						jQuery(".message-popup").hide();
						var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
						jQuery(message_id)
						.fadeIn("fast")
						.css({ top:markerOffset.y-100, left:markerOffset.x+15 })
						.html(content);
					
					}	
					function displayItem(marker, content, item_id, message_id){
						jQuery(message_id).hide();
						show_item(item_id);
						map.panTo(marker.getLatLng());	
					}
								
						

					
										
					if(!jQuery("#listings-wanted ul").html()) jQuery("#listings-wanted ul").html("<li>No listings found. Why not <a href=\"/my/\">ADD A LISTING</a> yourself?</li>");
					if(!jQuery("#listings-offered ul").html()) jQuery("#listings-offered ul").html("<li>No listings found. Why not <a href=\"/my/\">ADD A LISTING</a> yourself?</li>");
				},

    			error:function(XMLHTTPRequest,textStatus,errorThrow){
    				alert("Error 101 There was an error retrieving the marker information.");
    			}});
				
				// add users location marker 
				if (profilelocation != ""){
					var icon_add=profileIcon;
								Localopts = { 
								  "icon": icon_add,
								  "clickable": true,
								  "dragabble": false,
								  "labelOffset":new GSize(-18, -53)
								};
								
					var Profilemarker = new LabeledMarker(profilelocation, Localopts);
					GEvent.addListener(Profilemarker, "click", function() {;
					window.location.href="/profile/?user="+user_name;										   
					});
					map.addOverlay(Profilemarker);
				
				}	
						

				
} //end of locate_profile_services function

		//This does the search
function locateAllServices(point, location, searchStr, zoomLevel, max_records, searchEverywhere){
				
				//alert("4 - We have now come from include_markers.php and are in the LocateALLServices function")
				// need to delete message div from line 104 which is attached to the map pane
				var item_id_string="";
				jQuery(".message-popup").remove();
				jQuery("#listings-home").hide();
				var div = jQuery('<div></div')
   				.appendTo(document.body).attr('id', 'message-offered').addClass("message-popup").css({ display:'none'}) ;
				var div = jQuery('<div></div')
   				.appendTo(document.body).attr('id', 'message-wanted').addClass("message-popup").css({ display:'none'}) ;
				
				// loop through element "li" and remove
				jQuery("#list li").each(function() {
							jQuery(this).remove();
				});				
						
				//users postcode			
      			var userLat = point.lat(); var userLng = point.lng();
				
				URLString = "lat="+ userLat + "&lng=" + userLng + "&srch=" + searchStr + "&max=" + max_records;
				jQuery.ajax({type:"GET",url:"/xml_LocateAllServices.php", data: URLString ,dataType:"xml",
				success:function(data,textStatus) {
					
					// now we have the xml feed / file
					// create new instance of map object
					var map = new GMap2(document.getElementById('map'));
					var dragEnd = GEvent.addListener(map, "dragend", function(){
						
						GEvent.removeListener(dragEnd);
						GEvent.removeListener(zoomEnd);
						
						locateAllServices(map.getCenter(), location, searchStr, zoomLevel, 10, 1); 
					});
					var zoomEnd = GEvent.addListener(map, "zoomend", function(oldzoom, newzoom){
						if(oldzoom && oldzoom!=newzoom) {
							//alert(oldzoom+" "+newzoom);
							GEvent.removeListener(dragEnd);
							GEvent.removeListener(zoomEnd);
							locateAllServices(map.getCenter(), location, searchStr, newzoom,  10, 1); //, map.getZoom());
						}
					});
					map.addControl(new GLargeMapControl());
					// Set general location of map based on inputed postcode	
					var Generallocation = new GLatLng(userLat,userLng);
					map.setCenter(Generallocation, zoomLevel);
					
					var count0=0; var count1=0;
					
					jQuery(".box ul").remove();
					jQuery("<ul />").appendTo("#listings-offered");
					jQuery("<ul />").appendTo("#listings-wanted");
					
					
					// creates a marker for each XML entry retrieved
    				jQuery("marker",data).each(function() {
    					// Attributes for each marker.
						
               			var lat = parseFloat(jQuery(this).attr("lat"));
               			var lng = parseFloat(jQuery(this).attr("lng"));
               			var point = new GLatLng(lat,lng);
               			var html = jQuery(this).attr("name");
						var item_id = jQuery(this).attr("id");
						
						// added M Jakda 04 / 08 / 2009 
						var date_created = jQuery(this).attr("date_created");
						//var msg_count = jQuery(this).attr("msg_count");
						
						var item_type = jQuery(this).attr("type");
						var rating_div_width = jQuery(this).attr("div_width");
						item_id_string+=item_id+",";
               			// Create the marker.
						if(item_type=="1") {
							var icon_add=icon1;
							count1++;
							var label=count1;
							var box_id="#listings-wanted";
							var message_id="#message-wanted";
						}
						else {
							var icon_add=icon;
							count0++;
							var label=count0;
							var box_id="#listings-offered";
							var message_id="#message-offered";	
						}
						opts = { 
						  "icon": icon_add,
				          "clickable": true,
				          "labelText": label,
				          "labelOffset": new GSize(-18, -53)
				        };
						
               			var marker = new LabeledMarker(point, opts);
						
									
						//add to list on the right hand side
						//jQuery("li").addClass("msg-include");
    	   				jQuery("<li />").html(html)
                    	.appendTo("#list")
						// When user click on a list item then the map focuses on the related marker and show the message box
						.click(function(){
							displayPoint(marker, html, item_id, message_id);
							show_item(item_id);
						});
    			        
						var li_html='<div class="item-number">'+label+'</div>\n';
						li_html+='<div class="item-head"><h4 id="'+item_id+'"></h4><p>&nbsp;</p></div>\n';
						li_html+='<div class="clear"></div>\n'; 
						
						
						jQuery("<li />").html(li_html)
                    	.appendTo(box_id+" ul");
						
						jQuery("<a />").html(html)
						.appendTo("h4#"+item_id)
                    	.css({ cursor:'pointer'})
						// When user click on a list item then the map focuses on the related marker and show the message box
						.click(function(){
							map.panTo(marker.getLatLng());
							show_item(item_id);
						})
						.mouseover(function(){
							displayPoint(marker, html, item_id, message_id);
						});
						
							var rating_html='<div class="listings-feedback-rating">';
									rating_html+='<div class="feedback-stars" style="width:';
									rating_html+=rating_div_width;
									rating_html+='px"></div>\n';
									rating_html+='<img src="/images/rating-mask-small.png" alt="Item Rating" width="60" height="15" />';
									rating_html+='</div>';
						
						jQuery("h4#"+item_id).append(rating_html);
						
                  		GEvent.addListener(marker, "click", function() {displayItem(marker, html, item_id, message_id);});
						GEvent.addListener(marker, "mouseover", function() {displayPoint(marker, html, item_id, message_id);});
						GEvent.addListener(marker, "mouseout", function() {jQuery(message_id).hide();});
               			map.addOverlay(marker);
						// attaches the custom div 'message layer to the google map window pane
               			jQuery(message_id).appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
						//show_item(item_id);
    				});
					
					// To display a custom div box instead of the default Google map window
					function displayPoint(marker, content, item_id, message_id){
						jQuery(".message-popup").hide();
						var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
						jQuery(message_id)
						.fadeIn("fast")
						.css({ top:markerOffset.y-100, left:markerOffset.x+15 })
						.html(content);
					
					}	
					function displayItem(marker, content, item_id, message_id){
						jQuery(message_id).hide();
						show_item(item_id);
						map.panTo(marker.getLatLng());	
					}
										
					if(!jQuery("#listings-wanted ul").html()) jQuery("#listings-wanted ul").html("<li>No listings found. Why not <a href=\"/my/\">ADD A LISTING</a> yourself?</li>");
					if(!jQuery("#listings-offered ul").html()) jQuery("#listings-offered ul").html("<li>No listings found. Why not <a href=\"/my/\">ADD A LISTING</a> yourself?</li>");
				},

    			error:function(XMLHTTPRequest,textStatus,errorThrow){
    				alert("Error 101 There was an error retrieving the marker information.");
    			}});
			}
			
// *******************************************

			