/*!
 * jQuery FaceBook album simple gallery
 * Copyright (c) 2010 Shawn Matthew Welch
 * Version: 1.0 (August 31st, 2010)
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 * Requires: jQuery v1.4.2 or later
 */
;(function($) {
	
$.fn.fbgallery = function(options) {
	var $self = $(this);
	
	if(options == undefined) throw "options object is required";
	if(options.albumId == undefined) throw "albumId property of options is required";
	
	var settings = $.extend({}, {
		'offset': 0,
		'limit': 25
	}, options);
	
	var album_id = settings.albumId;
	
	var callback = function(response) {
		var index, href, data, src, next;
		
		data = response.data;
		next = response.paging.next;
		for(index in data) {
			href = data[index].source;
			src = data[index].picture;
			
			$self.append('<a href="' + href + '" rel="thumb"><img src="' + src + '" /></a>');
		}
		
		if (next) {
			settings.offset += settings.limit;
			$.get('https://graph.facebook.com/' + album_id + '/photos?limit=' + settings.limit + '&offset=' + settings.offset + '&callback=?', {}, callback, "json");
		} else if (settings.onLoad != undefined) settings.onLoad.call();
	}
	
	$.get('https://graph.facebook.com/' + album_id + '/photos?limit=' + settings.limit + '&offset=' + settings.offset + '&callback=?', {}, callback, "json");
}
	
})(jQuery);
