window.fbAsyncInit = function() {
	FB.init({
		appId		: '170445096304754', // App ID
		channelUrl	: '//www.fittrends.ru/channel.html', // Channel File
		status		: true, // check login status
		cookie		: true, // enable cookies to allow the server to access the session
		xfbml		: true  // parse XFBML
	});
// Additional initialization code here
};

// Load the SDK Asynchronously
(function(d){
	var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
	js = d.createElement('script'); js.id = id; js.async = true;
	js.src = "//connect.facebook.net/ru_RU/all.js";
	js.charset = "windows-1251";
	d.getElementsByTagName('head')[0].appendChild(js);
}(document));

$(function(){
	$("div#form_login_div .social_network .fb").click(function(){

		FB.login(function(response) {
			if (response.authResponse) {
				//console.log('Welcome!  Fetching your information.... ');
				FB.api('/me', function(response) {					window.location = "https://www.facebook.com/dialog/oauth?client_id=170445096304754&redirect_uri=http://www.fittrends.ru/register_social_fb&scope=email,read_stream";
					//console.log('Good to see you, ' + response.name + '.');
				});
			} else {
				//console.log('User cancelled login or did not fully authorize.');
			}
		}, {scope: 'email,read_stream'});
	});
});
