// Facebook status
// More documentation on: http://developers.facebook.com/docs/api
function fbFetch(facebookId,maxNumItems, displayComments){
	//Set Url of JSON data from the facebook graph api. make sure callback is set with a '?' to overcome the cross domain problems with JSON
	var feedUrl = "https://graph.facebook.com/"+facebookId+"/feed?callback=?"; // set limit: &limit=10
	var maxNum = maxNumItems;
	//Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the relevant data.
	$.getJSON(feedUrl,function(json){
		var html = '<ul>';
		var count = 1;
		//loop through and within data array's retrieve the message variable.
		$.each(json.data,function(i,fb){
			if(fb.type=='status' && count <= maxNum){
				count = count+1;
				html += '<li>';
				html += '<img src="https://graph.facebook.com/'+facebookId+'/picture" alt="'+fb.from.name+'"/><span class="fbMsg">' + fb.message + '</span>'
				if(fb.comments && displayComments==1){
					html += '<ul>'
					$.each(fb.comments.data,function(i,fb){
						html += '<li><img src="https://graph.facebook.com/'+fb.from.id+'/picture" alt="'+fb.from.name+'"/><span class="fbMsg">' + fb.message + '</span></li>'
					});
					html += '</ul>'
				}
				html += '</li>'
			}
		});
		html += '</ul>'
		//A little animation once fetched
		$('#fbFeed').animate({opacity:0}, 500, function(){
			$('#fbFeed').html(html + name);
		});
		$('#fbFeed').animate({opacity:1}, 500);
	});
}
