document.observe('dom:loaded', function(){  
	
	loadLatestTweet();
	
})

function loadLatestTweet(){   

	// setup some vars to handle the Twitter API's URL
	var api_url =  'http://search.twitter.com/search.json?q=radarredux';  // url of API service
	var proxy_url =  '/wp-content/themes/2009/proxy.php?url='; // needed to circumvent the Same Origin Policy
	var url = proxy_url + encodeURIComponent(api_url); // put the whole url together, to be used in our Ajax.Request below

	// make the AJAX request, using Prototype's helper 
	new Ajax.Request(url, {   
		 
		// configuration options:
	  method: 'get', // we're just "getting" information here, so set method to 'get' 
	
		// what to do once we've received the data
	  onSuccess: function(raw_result) {    

			// 1) convert the result to an easier format to work with: JSON
			formatted_result = raw_result.responseText.evalJSON();             
			
			// 2) get the piece of content we want 
			var content = formatted_result.results[0].text;
			
			
			var content = formatted_result.results.first().text;
			
			content = content.gsub(/(https?:\/\/[^ ]+)/, "<a href='#{1}' target='_blank'>#{1}<a>")
			
			// 3) display that content on the page 
			$('tweet').down('.twitFeed p').update(content);
			
		}
		
	});

}    


