(function() {
    var e = document.createElement('script'); e.async = true;
    e.src = 'http://connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
}()); 

	
$(document).ready(function() {
		window.fbAsyncInit = function() {
		var AbsoluteUrlToChannelFile  = "http://www.ohmygas.com/xd_receiver.htm";
		FB.init({appId: '134582273275650', status: true, cookie: true, xfbml: true,channelUrl: AbsoluteUrlToChannelFile});
		};
        
        $('.fb_login').bind('click', function() {

	FB.login(function(response) {
    if (response.session) {
		if (response.perms) {
		  // user is logged in and granted some permissions.
		  // perms is a comma separated list of granted permissions
		  $.ajax({
			   type: "GET",
			   url: "/loginfb",
			   dataType: 'json',
			   success: function(data){
				if (data.res)
				{
					//login success
					location.reload(true);
	
				 }else
				 {
					//login fail
					 window.location="http://www.ohmygas.com/register";
				 }
	
			   }
	
			 });
		} else {
		  // user is logged in, but did not grant any permissions
		   window.location="http://www.ohmygas.com/register";
		}
		
      // A user has logged in, and a new cookie has been saved
    } else {
      // The user has logged out, and the cookie has been cleared
	  window.location="http://www.ohmygas.com/register";
    }
  }, {perms:'read_stream,publish_stream,offline_access,email'}) });

 });

