function format_date(timestamp) {
 
 	  var values = timestamp.split(" ");
 	  var the_month = values[1];
 	  var the_day_otw = values[0];
 	  var the_day_otm = values[2];
 	  return (the_day_otw + " " + the_day_otm + " " + the_month);
 	  
 }
 
 function activate_links(text) {
 
 
 	var text_array = text.split(" ");
	var output_string = "";
	$.each(text_array, function(i, item) {
		
		var is_link = item.match("http://");
		
		if (is_link) {item = "<a href=\"" + item + "\">" + item + "</a>"}
		
		output_string = output_string + " " + item;
		
	});
 	
 	return output_string;
 }
 


$(document).ready(function () {



	 var url = "http://twitter.com/status/user_timeline/cern.json?count=4&callback=?"; 
       $.getJSON(url, 
        function(data){
        	
        	
            $.each(data, function(i, item) {
            	var item_id = item.id;  // might use this later to link to a tweet
            	var item_text = item.text;
            	item_text = activate_links(item_text);
            	var date_string = format_date(item.created_at);
                $("#twitter_block #ajax_content").append("<div class=\"tweet\"><p>"  
                      + item_text
                      + " <span class=\"date\">"
                      + date_string
                      + "</span></p></div>"); 
                      if ( i == 3 ) return false;
            }); 
            
            if(data) {
            	$("#ajax_content").append("<p class=\"right\"><a href=\"http://twitter.com/cern/\">&raquo; more</a></p>");  
            }
        }); 
	



});