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 () {



	if (top.location != location) {
    top.location.href = document.location.href ;
 	 }



	 var url = "http://twitter.com/status/user_timeline/cern.json?count=4&callback=?"; 
	 
	   $.ajaxSetup({
		timeout: 3000 //timeout value 3 seconds
	   });
       $.getJSON(url, 
        function(data){
        	
        	
            $.each(data, function(i, item) {
				var reply = item.in_reply_to_screen_name;
            	if (!reply) {				  
            	   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("<span class=\"tweet\">"  
                         + item_text
                         + " <span class=\"date\">"
                         + date_string
                         + "</span></span>"); 
                         if ( i == 0 ) return false;
				}
            });  
            
           
        }); 
	



});
