function FBInit()
{ 
	FB.login(function(response) 
	{
		if (response.session) 
		{    
			if (response.perms) 
			{
				FBLoginResult(response.session);
				// user is logged in and granted some permissions.
				// perms is a comma separated list of granted permissions
			} 
			else 
			{
				// user is logged in, but did not grant any permissions
			}
		} else 
		{
			// user is not logged in
		}
	}, {perms:'read_stream, publish_stream, user_photos, user_hometown'});
}

function FBLoginResult(sessionData)
{
	var o = getSWF(attributes.id);
	if (o)
	{
		o.fbLoginResult(sessionData.access_token);
	}
	else
		alert("Can't find swf with id == " + attributes.id);
}

function getSWF(swf) 
{
	if (navigator.appName.indexOf("Microsoft") != -1)
		return window[swf];
	else
		return document[swf];
}

FB.init({
  appId  : '158940397477126',
  status : true, // check login status
  cookie : true, // enable cookies to allow the server to access the session
  xfbml  : true});

FB.Event.subscribe('auth.sessionChange', function (response) 
 {
	if (response.session) 
	{               
	  FBLoginResult(response.session.access_token);
	}
	else 
	{
		// The user has logged out, and the cookie has been cleared
	}
});


