if(typeof jQuery != 'undefined') {
	jQuery(function($) {
		$.fn.extend({
			fb_login: function(options) {
				var settings = $.extend({}, $.fn.fb_login.defaults, options);

				function showProfilePic($loginContainer) {
					$loginContainer.html("Connected to Facebook as <fb:name uid=loggedinuser useyou='false'></fb:name> | <a href=\"" + window.location.href + "\" id=\"fb-logout\">Sign Out</a>");
					FB.XFBML.parse();
				}

				function showLoginBox($loginContainer) {
					$loginContainer.html('<fb:login-button show-faces="false" width="50" max-rows="1" scope="rsvp_event"></fb:login-button>');
					FB.XFBML.parse();
				}

				return this.each(function () {
					var $$ = $(this),
					o = $.metadata ? $.extend({}, settings, $$.metadata()) : settings;

					FB.Event.subscribe('auth.login', function(response) {
						showProfilePic($$);
						$('#fb-logout').click(function() {
							FB.logout();
						});
					});

					FB.getLoginStatus(function(response) {
						if (response.authResponse) {
							showProfilePic($$);
							$('#fb-logout').click(function() {
								FB.logout();
							});
						} else {
							showLoginBox($$);
						}
					});

				});
			}
		});

		$.fn.fb_login.defaults = {
			
		};

	}(jQuery));
}
