
/*-----------------------------------------------------------------------------

__  __ `__ \  _ \  ___/  __ `/_  __ \  __ \
_  / / / / /  __/ /__ / /_/ /_  / / / /_/ /
/_/ /_/ /_/\___/\___/ \__,_/ /_/ /_/\____/

MSSS Facebook Connect.

version:   1.1
author:    Vincent Martin
email:     vincent@mecano.ca

------------------------------------------------------------------------------*/

facebook = {
	
	/* ActionStack (Toggled by Facebook Connect button)
	------------------------------------------------------------------------- */
	share: function(){
		if(pageTracker)	pageTracker._trackPageview('recherche/share/facebook');	
		
		this._aS = new ActionStack(this);
		var _aS = this._aS;
		var aS = [];
		//---
		aS[aS.length] = {func: this.hideChooseForm};
		aS[aS.length] = {func: this.initSession, param:[_aS], wait:true};
		aS[aS.length] = {func: this.displayShare, param:[_aS], wait:true};
		aS[aS.length] = {func: this.killSession, param:[_aS], wait:true};
		//---
		_aS.setStack(aS);
		_aS.startUp();
	},
	
	
	
	/* Hide the select Facebook lightbox.
	-------------------------------------------------------------- */
	hideChooseForm: function(){
		var tE = $('content').getElement('.choose_form_shadow');
		tE.setStyle('display', 'none');
	},
	
	
	
	/* Init Facebook session.
	------------------------------------------------------------------------------*/
	initSession: function(callnext){
		FB.Connect.requireSession(function(){if(callnext!=null){callnext.next();}});
	},
	
	killSession: function(callnext){
		FB.Connect.logout(function(){if(callnext!=null){callnext.next();}});
	},
	
	
	
	/* Toggles share to a friend popup screen.
	--------------------------------------------------------------------------------------------------*/
	displayShare: function(callnext){
		FB.Connect.showShareDialog(window.location,function(){if(callnext!=null){callnext.next();}});
	},
	
	
	
	/* Init Facebook API Key.
	-------------------------------------- */
	initApi: function(){
		FB.init(this._key, this._xdFile);
	},
	
	
	
	/* Mulitusage
	--------------------------------------------------------------*/
	empty: function(){},
	
	
	
	init: function(){
		if(this._INIT == null){
			this._INIT = true;
			//---
			this._key = window.FACEBOOK_KEY;
			this._xdFile = '../xd_receiver.html';
			//---
			this.initApi();
		}
	},
	
	
	
	startUp: function(){

	},
	
	
	
	onWindowDomReady: function(){
		this.init();
	},
	
	
	
	onWindowLoad: function(){
		this.init();
	}
};


// Window Events ---------------------------------------------
window.addEvent('domready', function() {
	facebook.onWindowDomReady();
});
window.addEvent('load', function() {
	facebook.onWindowLoad();
});