
function FacebookConnect(appId, locale){

  window.fbAsyncInit = function() {
    FB.init({appId: appId, 
        	status: true, 
        	cookie: true,
            xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/'+locale+'/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());


  this.login = function(){
	  FB.login(function(response) {
		  if (response.session) {
		    document.location.reload();
		  } 
	  	},{perms:'email,publish_stream,user_location'});
	  _trackEvent('click', 'user clicked on connect to facebook');
  }
  
  this.logout = function(){
	  FB.logout(function(response) {
		  $.ajax({
			  url: "/en/users/ajaxlogout",
			  success: function(){
				  window.location.reload();
			  }
			});	 
	  });
	  _trackEvent('click', 'user clicked on logout facebook');
  }
  
  this.isLoggedIn = function(){
	  FB.getLoginStatus(function(response) {
		  if (response.session) {
		    return true;
		  } else {
		    return false;
		  }
		});
  }
  
  this.publish = function(image, caption, description){	  
	  FB.ui(
		   {
		     method: 'feed',
		     name: 'De Haagse Studentenpas',
		     link: document.location.href,
		     picture: image,
		     caption: caption,
		     description: description + ' ...',
		     message: 'Leuke kortingen met de Haagse studentenpas!'
		   },
		   function(response) {
		     if (response && response.post_id) {
		      
		     } else {
		       
		     }
		   }
		 );

									
  }
  
}

