$(document).ready(function(){
	initTwitter();
});

/*function initTwitter(){
	var jqxhr = $.getJSON("http://twitter.com/status/user_timeline/HMRDiet.json?exclude_replies=true&count=3&callback=?", function( data )   
    {  
		var TwitterTab_p = $("#sideBarTwitterCallout #postContent");
        if (data != null && data.length > 0) 
		{
			for (var i=0; i < data.length; i++) {
				var postText = data[i].text;
				
				if (postText.search(/@/g) != 0)
				{
					var date = data[i].created_at;
					$('#postDate').prepend(date.replace(/\+0000/g, ' '));
					
					var tweetText = createLinkInText(data[i].text);
					
					TwitterTab_p.html(tweetText);
					if (TwitterTab_p.html().length > 1) 
						var fullText = TwitterTab_p.html();
					else 
						var fullText = 'Sorry, Twitter cannot be accessed right now.';
					TwitterTab_p.html(fullText.replace(/href/g, 'target="_blank" href'));
					TwitterTab_p.fadeIn(1000);
					$('#postDate').fadeIn(1000);
					break;
				}
			}
		}
    })
}*/

function initTwitter(){
	var jqxhr = $.getJSON("http://twitter.com/status/user_timeline/HMRDiet.json?exclude_replies=true&count=5&callback=?", function( data )   
    {  
        var TwitterTab_p = $("#sideBarTwitterCallout #postContent");
		if (data != null && data.length > 0) 
		{
			for (x in data)
			{
				if(data[x].text)
				{
					var postText = data[x].text;
					if(postText.length > 0)
					{
						//do a search for @, if it it's in there - don't display it. - make the count in the initial call go back 5. 
						//loop through the retunred items, if @ isn't in there, break the loop
						if (postText.search(/@/g) < 0)
						{
							var date = data[x].created_at;
							var tweetText = createLinkInText(data[x].text);
							
							$('#postDate').prepend(date.replace(/\+0000/g, ' '));
							
							TwitterTab_p.html(tweetText);
							TwitterTab_p.fadeIn(1000);
							$('#postDate').fadeIn(1000);
							break;
						}
					}
				}
			}
		}
    })
}
