/*
fb_authorisation.js
Copyright (c) 2010, Custom GIS Limited. All rights Reserved.
Author: Paul Brindle
This source file is proprietary property of Custom GIS Ltd.
It must not be modified in any way. We do not take responsibility for any changes that are made to this source file.
It must not be copied, sold or used for any purpose unless Custom GIS Ltd. has given its explicit permission.
*/

window.fbAsyncInit = function()
{
	FB.init({appId: '126126354097458', status: true, cookie: true, xfbml: true});

	//Listen for events
	FB.Event.subscribe('auth.login', function(response)
	{
		//Re-assess the javascript without loading the Page from the Web server
		//window.location.reload(false);
	});
	FB.Event.subscribe('auth.logout', function(response)
	{
		//Re-assess the javascript without loading the Page from the Web server
		//window.location.reload(false);
	});

	FB.getLoginStatus(function(response)
	{
		if(response.session)
		{
			//The user is logged in using Facebook
			loggedIn();
		}
	});
};
(function()
{
	//Include the javascript API
	var e = document.createElement('script');
	e.type = 'text/javascript';
	e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
	e.async = true;
	document.getElementById('fb-root').appendChild(e);
}());
	
function loggedIn()
{
	//window.location.reload();
	/*FB.api('/me', function(response)
	{
		//alert('Hi ' + response.name + '!!!');
		//document.getElementById('login_button_fb').innerHTML = 'Welcome ' + response.name;
		//window.location = "https://graph.facebook.com/oauth/authorize?client_id=132531122483@client_secret=e6b4f9bb2cd0ad377ea4abab6699f0a1&redirect_uri=http://www.socialrevitalizer.com/test_js_graph.php&type=user_agent&display=popup";
		//Welcome the user to the website.
		//document.getElementById('login_button_fb').innerHTML = 'Welcome ' + response.first_name;

		//Loop through the elements retrieving the key names
		for(key in response)document.write("Key name is  " +"<b>"+key+"</b>"+"<br>");

	});*/

	/*var bodyMess = 'Testing the graph API using Connect!!!';

	FB.api('/me/feed', 'post', { message: bodyMess }, function(response)
	{
		if(!response || response.error)
		{
			alert('Error occured');
		}
		else
		{
			alert('Post ID: ' + response.id);
		}
	});*/
}