// put this into the global website header
//<script src="http://static.ak.connect.facebook.com/connect.php/de_DE" type="text/javascript"></script>

var FBConnect = {
	login : function(register) {
		var params = {};
		if(register) {
			params.perms = 'user_birthday';
		}
	
		FB.login(function(rsp) {
			if(rsp.session) {
				var invitation = null;
				var list = null;
				var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
				for(var i = 0; i < hashes.length; i++)
				{
					hash = hashes[i].split('=');
					if(hash[0] == 'invitation') {
						invitation = hash[1];
					}
					if(hash[0] == 'list') {
						list = hash[1];
					}
				}
		
		        // redirect to our fb connect gateway
				var loc = 'fbconnect.php';
				if(invitation != null) {
					loc += '?invitation=' + invitation;
				}
				if(list != null) {
					loc += '?list=' + list;
				}
		        document.location = loc;
			}
			else {
				
			}
		}, params);
	}
};

