﻿    var appID = "350474838314968";
    var web = location.host;
    var fb=document.getElementById('fb-root');
    if (!fb) {
        fb = document.createElement('div');
        fb.id = 'fb-root';
        document.body.insertBefore(fb, document.body.firstChild);
    }

    document.writeln('<p id="userName"></p>');

    /* data-width="500" */
    document.writeln('<div class="fb-comments" data-href="' + location + '" data-num-post="4" data-colorscheme="light"> </div>')

  window.fbAsyncInit = function() {
    FB.init({
      appId      : appID,           // App ID
      channelUrl : '//' + web + '/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
    });
    // alert('fb init ended');
    // 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/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));


     function displayUser(user) {
        var userName = document.getElementById('userName');
        var greetingText = document.createTextNode('Greetings, ' + user.name + '.');
        userName.appendChild(greetingText);
    }

     function requestLogin(){
     if (window.location.hash.length == 0) {
            var path = 'https://www.facebook.com/dialog/oauth?';
            var queryParams = ['client_id=' + appID, 'redirect_uri=' + window.location, 'response_type=token'];
            var query = queryParams.join('&');
            var url = path + query;
            window.open(url);
        } else {
            var accessToken = window.location.hash.substring(1);
            var path = "https://graph.facebook.com/me?";
            var queryParams = [accessToken, 'callback=displayUser'];
            var query = queryParams.join('&');
            var url = path + query;
            // use jsonp to call the graph
            var script = document.createElement('script');
            script.src = url;
            document.body.appendChild(script);        
    }

}
