
var timer;   

function linkify(text){
		if( !text ) return text;
		text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,function(url){
			nice = url;
			if(url.match('^https?:\/\/')){
				nice = nice.replace(/^https?:\/\//i,'')
			}
			else{
				url = 'http://'+url;
			}
			
			return '<a target="_blank" rel="nofollow" href="'+ url +'">'+ nice.replace(/^www./i,'') +'</a>';
		});
		
		return text;
	}
	
function getUser(theQuery)   
{

	clearTimeout(timer);   
	var results = "";   
	//var theQuery = "audi+s5";   
  
	$j.post("/tweets/getUser", {query: theQuery},  function(xml){   
		$j('entry',xml).each(function(i){   
		
		
			var title = $j(this).find("title").text();  
			title = linkify(title);
			var icon = $j(this).find("link[rel='image']").attr("href");
			var user = $j(this).find("name").text();
			var uri = $j(this).find("uri").text();
			results = results + "<div class='clearfix'><a href='"+uri+"'><img src='"+icon+"'></a> " +"<p><strong><a href='"+uri+"'>"+user+"</a></strong> " + title + "</p></div>";   
		}); 
		results = results + "<div class='seeAll'><a href='http://twitter.com/"+theQuery+"' target='_blank'>See all tweets from "+theQuery+" &raquo;</a></div>";
	$j("#tweetContainer").html(results);   
	});   
  
	
	//timer = setTimeout('getSearch("'+theQuery+'")', 60000);
}