//Adds twitter statuses to html
function twitterCallback2(twitters)
{
  var statusHTML = [];
  var displayTweets = 0;

  for (var i=0; i<twitters.length; i++)
  {
    //var username = twitters[i].user.screen_name;

    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
      return '<a href="'+url+'">'+url+'</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
    });

    var linkEscape = new RegExp("\\[]"); // JR writes '[]' in a tweet when the tweet has
					// a link and nonetheless should appear.
    var hasEscape = linkEscape.test(status); // check whether to override showing link
    var aLink = new RegExp("t.co"); //all links contain this expression
    var hasLink = aLink.test(status)  //check if the tweet contains a link
    if (hasEscape || !hasLink)
    {
     //Then we don't have a link, or it's over-ridden.
        statusHTML.push('<div class="quest">' +status+ '<br><div class="notes_content_author grey"><i>'+get_time(twitters[i].created_at)+'</i></div></div><br>');

        displayTweets++;
        if(displayTweets == 2) //when two tweets are displayed on the site
            break;
    }
  }

  if (document.getElementById('twitter_update_list'))
   document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
}


function get_time(time_value)
{
  var values = time_value.split(" ");

  var time = values[3].split(":");

  time_value = values[2] + " " + values[1] + " " +  values[5] + " " + time[0] + ":" + time[1]; //DD Mon YYYY HH:MM

  return time_value;
}

$(document).ready(function() {
    $.getScript("http://twitter.com/statuses/user_timeline/jancisrobinson.json?callback=twitterCallback2&count=15");
});


