 /**
  * The callback on the myaccount page when the user connects their account
  */
 function facebook_authorize_callback(permissions) {
 	$(document).ready(function() { 
		    
	    if(permissions == 'offline_access,publish_stream') {
	    	$('input[name=linkFacebook]').attr('checked', true);

			// Store the session key for offline access with our app
			var session = FB.Facebook.apiClient.get_session();
			$('input[name=inputFacebookId]').val(session.session_key);	    		    	
	    }else{
	    	$('input[name=linkFacebook]').attr('checked', false);
	    } 	
	 	
	 	// Submit the form
	 	$('#networks_form').submit();
 	});
 }
 
 /**
  * Authorize Thoora to access Facebook profile when user is not logged in
  */
 function facebook_authorize() { 
    // Has the checkbox been changed from off to on?
    if($('input[name=linkFacebook]').attr('checked') && $('input[name=origLinkFacebook]').val() == 0) {
        // The callback will submit the form for us
 		FB.Connect.showPermissionDialog("offline_access,publish_stream", facebook_authorize_callback);
 	}else{
 		// Just submit the form
 		$('#networks_form').submit();
 	}	
 } 
 
 /**
  * Post to the user's Facebook wall
  */
 function facebook_post(title, description, thoora_link, src, user_message, callback) {
 
 	// Publish to facebook
    var comment_data = {
    	'name': title, 
    	'href':thoora_link,
    	'description':description,  
    	'media':[{'type':'image','src':src,'href':thoora_link}]
    };
    
    if(!FB.Connect.get_loggedInUser()){
    	//FB.Connect.forceSessionRefresh();
    }
      
	FB.Connect.streamPublish(user_message, comment_data,null,null,'Your thoughts?',callback,false,null);
		
 }