/*	
 *	facebug.js
 *	ver 0.1
 *
 *	pulls facebook wall feed from specified public page
 *	by RS, 09/2010
 *	
 */

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



var FBURL = 'http://graph.facebook.com/104675669590892/feed?fields=message,from,type&limit=';
FBURL += facebookCount;
FBURL += '&callback=?';

//console.log('Goliath online.');

$.getJSON(FBURL, function(json){

	//console.log('FB: JSON received');
	
	$.each(json.data, function(i, item){
	
		var message = item.message;
		////console.log(message);
		
		var wallItem = '<div class="fb-item">';
		
		wallItem += '<img class="author-picture" src="https://graph.facebook.com/'+item.from.id+'/picture?type=square" width="50" height="50" />';
		wallItem += '<span class="author-name">'+item.from.name+'</span>';
		wallItem += '<p class="message-text">'+message.linkify()+'</p>';
		
		wallItem += '<div class="clear"></div>';
		wallItem += '</div>';
		
		////console.log(wallItem);
		
		$('#facebug').append(wallItem);
	
	});
	
});
