/* Function to turn Twitter URLs into <a> elements */
(function($) {
  $.toLink = function(text) {
    var urlRegExp = /((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/gm;
    var newText = text.replace(urlRegExp, '<a href="$1">$1</a>');
    return newText;
  };
})(jQuery);
$(function() {
  var twitterBaseURL = 'http://twitter.com/status/user_timeline/pete_sellwood.json?count=5&callback=?';
  var html = '';
  $('<ol />').appendTo('#twitter');
  $.getJSON(twitterBaseURL, function(json) {
    $.each(json, function(i, item) {
      var text = $.toLink(item.text);
      var profileImageURL = item.user.profile_image_url;
      var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
      var date = new Date(item.created_at);
      html += '<li>' + text + '<br /><sub>' + date.getHours() + ':' + date.getMinutes() + ' on ' + date.getDate() + ' ' + m_names[date.getMonth()] + '</sub></li>';
    });
    $('ol', '#twitter').html(html);
    $('#twitter').animate({
      opacity: 1
    }, 2000);
  });
});
/* DOM loaded events... */
$(document).ready(function() {
  // JS to prevent framing in external sites
  if(top!=self){top.location=self.document.location;}
  $('HTML').addClass('JS');
  $("nav li:first-child > a").addClass('on');
  $("nav li > a").click(function(e){
    e.preventDefault();
    var link = $(this);
    if(!link.hasClass('on')){
      $('nav li > a').removeClass("on");
      $('section').hide();
      $(link.attr('href')).show();
      link.addClass('on');
    }
  });
});
/* IE 7 identity crisis fix */
$(function(){
  if( jQuery.browser.msie && parseInt(jQuery.browser.version) == 7 )
    var ie6BodyTag = $("body.ie6").addClass("ie7").removeClass("ie6");
  return false;
});
