$(document).ready(function(){
  showTweet();
});

function showTweet()
{
    
  String.prototype.linkify = function() {
  	return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
  		return m.link(m);
  	});
  };

  String.prototype.atify = function() {
    return this.replace(/@[\w]+/g, function(m) {
      return "<a href='http://www.twitter.com/"+m.replace('@','')+"'>"+m+"</a>";
    });
  };
  tweetCount = 0;
  $.getJSON('http://twitter.com/status/user_timeline/StreVat.json?count=1&callback=?', function(data){
  	$.each(data, function(index, item){
  	  tweetCount++
  		$('#twitter').append('<ul class="twitter-mentions tweet-'+ tweetCount +'" style="display:none; opacity:0;"><li>' + item.text.linkify().atify() + '<span class="tweetAuthor"><br />by <a href="http://twitter.com/StreVat" target="_blank">' + item.user.screen_name + '</a><span class="viaSource"> on ' + item.source + '</span></span></li></ul>');
  	});
  });

  $("#twitter").show().fadeTo(1500,1);
  
  int = 0;
  var findTweet = window.setInterval( "findTweets()", 400);
  
}

//lets add to this later
function findTweets()
{
  if ( int < 1 )
  {
    int++;
    $(".tweet-"+ int +"").show().fadeTo(1500,1);
  }
  else
  {
    if ( int != 1 )
    {
      int++;
      $(".tweet-"+ int +"").show().fadeTo(1500,1);
      $('#twitter').append('<a href="http://www.twitter.com/strevat" class="moreTweet" style="display:none; opacity:0;">view more</a>');
      $(".moreTweet").show().fadeTo(1500,1);
      window.clearInterval( findTweets );  
    }
  
    else
    {
      window.clearInterval( findTweets );
    }
  }
}
