/*--------------------------------------------------------------

__  __ `__ \  _ \  ___/  __ `/_  __ \  __ \
_  / / / / /  __/ /__ / /_/ /_  / / / /_/ /
/_/ /_/ /_/\___/\___/ \__,_/ /_/ /_/\____/

--------------------------------------------------------------*/

facebook = {
	
	share: function(pUrl){
		this._aS = new ActionStack(this);
		var _aS = this._aS;
		var aS = [];
		//---
		aS[aS.length] = {func: this.initSession, param:[_aS], wait:true};
		aS[aS.length] = {func: this.displayShare, param:[pUrl,_aS], wait:true};
		//---
		_aS.setStack(aS);
		_aS.startUp();
	},

	initSession: function(callnext){
		FB.Connect.requireSession(function(){if(callnext!=null){callnext.next();}});
	},
	
	displayShare: function(pUrl,callnext){
		pUrl = 'http://www.avenirensante.com/fr/'+pUrl;
		FB.Connect.showShareDialog(pUrl,function(){if(callnext!=null){callnext.next();}});
	},
	
	
	initApi: function(){
		FB.init(this._key, this._xdFile);
	},
	
	/* Main initiation function
	--------------------------------------------------------------*/
	init: function(){
		if(this._INIT == null){
			this._INIT = true;
			//---
			this._key = window.FACEBOOK_KEY;
			this._xdFile = '../xd_receiver.html';
			//---
			this.initApi();
		}
	},
	
	/* Window events handling
	--------------------------------------------------------------*/
	onWindowDomReady: function(){
		this.init();
	},
	
	onWindowLoad: function(){
		this.init();
	}
};


// Window Events ---------------------------------------------
window.addEvent('domready', function() {
	facebook.onWindowDomReady();
});
window.addEvent('load', function() {
	facebook.onWindowLoad();
});