// JavaScript Document
function GetTweets(arg_search,arg_lat,arg_lng,arg_radius){
jQuery(document).ready(function(){ 
		 	//alert("twitter");
			var searchStr = arg_search;
			var lat = arg_lat; 
			var lng = arg_lng;
			var radius = arg_radius;
			
			// if location is UK wide
			if((arg_lat == 55.378051) && (arg_lng == -3.435973)){
			var radius = 200;
			}
			
			
			URLString = "searchterm="+ searchStr + "&lat=" + lat + "&lng=" + lng + "&radius=" + radius;
			//alert("URLString in tweet = " + URLString);
			// need this to remove existing Tweet divs
			jQuery(".tweet").each(function() {
				jQuery(this).remove();
			})
			
             jQuery.ajax({
                 type: "GET",
                 url: "../twitter/getSearchTwitter.php",
                 dataType: "xml",
				 data: URLString,
				 error: function(XMLHttpRequest, textStatus, errorThrown) {
				 alert(textStatus + " : Tweet retrieval error");
				 },
                 success: function(xml) {
                     jQuery(xml).find('entry').each(function(){					 
						 var $entry = jQuery(this); 
						 var name_text = jQuery(this).find('title').text();
						 var id_text = jQuery(this).find('id').text();
						  
						 $entry.find('link').each(function(){
						 	if (jQuery(this).attr('rel') == 'image'){
								profile_image_url = jQuery(this).attr('href');
							}
						 }); 
						 var author_text = $entry.find('uri').text();
						 // build the HTML code that displays the tweet
							 results = '<div class="tweet">';
							 results += '<h4><img src="' + profile_image_url + '" width="35" height="35">' ;
							 results +=  name_text + '</h4>';
							 results += '<h5><strong>From:</strong> <a href="'+ author_text + '">' + author_text + '</a>: </h5>';
							 results += '</div>';
						// add it to the HTML container	 
						jQuery('<p></p>').html(results).appendTo('#tweet-container');
						
                     }); //close each(
                 }
				 
				
    			
				 
             }); //close jQuery.ajax(
			  
       
}); 
}
					 //clos
