(function($) {

	//Attach this new method to jQuery  
    $.fn.extend({   
          
        //----------------------------------------------------------//
        // Title: Haven't decided on a name
        // Author: Jordan Brown
        // Company: MediaFuel
        // Date: 09/22/10
        //----------------------------------------------------------//
         
        facebook: function(id, options, callback) {
			
			var defaults = {
				link: false,
				limit: 5
			}
		
			var options = $.extend(defaults, options);
			
			return this.each(function() {
			
				var o = options;
				
				var obj = $(this);
				
				$.ajax({
					type: "GET",
					// 273838689302216
					url: "https://graph.facebook.com/"+id+"/photos?limit="+o.limit,
					dataType: "jsonp",
					success: function(json) {
						var lis = "";
						var totalWidth = 0;
						for (var i = 0; i < json.data.length; i++) {
							var link = json.data[i].picture;
							lis += "<li><a href=\""+json.data[i].images[0].source+"\"><img src=\""+link+"\" alt=\"\" /></a>";
						}
						var htmlBox = "<a class='backlink' href='/gallery'><< Back to galleries</a><ul class='fb-photos'>";
						htmlBox += lis;
						htmlBox += "</ul>";
/* 						$.map( $('li'), function(element) */
						obj.html(htmlBox);
						
						$(".fb-photos a").lightBox();
						
						if (typeof callback == 'function' && htmlBox != undefined) { // make sure the callback is a function
					        callback.call(this); // brings the scope to the callback
					    }
					}
				});
			
			});
			
		}
	});	
				
})(jQuery);
