var s = document.createElement("script");
s.setAttribute("type","text/javascript");
s.setAttribute("src","/js/bigspaceship/oauthbridge_iframe.js");

document.getElementsByTagName("head")[0].appendChild(s);

var facebookApi = {};
	facebookApi.scope = {};
	facebookApi.initialize = function($scope) { 
		if($scope) facebookApi.scope = $scope;
	}

	facebookApi.login = function(loginFunction,cancelFunction) {
		com.bigspaceship.api.facebook.OAuthBridge.login(facebookApi.getAuthorizationURL(),loginFunction);
	}

	facebookApi.logout = function() {
		FB.logout(function() {});
		com.bigspaceship.api.facebook.OAuthBridge.logout();
	}
	
	facebookApi.getAuthorizationURL = function()
	{
		var i = facebookApi.scope.length;
		var scope = '';
		if(i) {
			while( i-- ) { scope += facebookApi.scope[i] + ","; }
			// sk: remove last comma
			scope = scope.slice( 0, -1 );
		}
		

		var http = document.location.protocol + "//";
		
		var real_redirect = http+window.location.host+'/facebook/international_facebook_authorization_complete';
		var fb_redirect = http+'apps.facebook.com/taste_the_rainbow/authorization_complete?real_redirect=' + escape(real_redirect);
//		var fb_redirect = http+'apps.facebook.com/com-skittles-testbed/authorization_complete?real_redirect=' + escape(real_redirect);
		
		https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=email,read_stream&response_type=token
		
		return "https://graph.facebook.com/oauth/authorize"
                + "?client_id=" + FB._apiKey 
                + "&redirect_uri=" + fb_redirect
                + "&scope=" + scope
                + "&response_type=token";
	}
