CNLT.FB = {
	me: false,
	cbf: false,
	icons: {},
	InitCallBack: false,
	makePanel: function(fbicon) {
		new Ajax.Request('../includes/fb.app.php', {
			parameters: { command:"getPanel", eventid:fbicon.fbeid},
			onSuccess: function(transport) {
				fbicon.panel.innerHTML = transport.responseText;
				ceb = fbicon.panel.getElementsBySelector('.FBceb');
				if (ceb.length == 1) {
					fbicon.ceb = ceb[0];
					fbicon.ceb.observe('click', Capsule.comedyCapsule.app.calendar.makeFBEvent.bind(fbicon));
				}
			}
		});
	},			
	open: function() {
		fbicon = this;
		FB.getLoginStatus(function(response) {
			if (response.status == "connected") {
				fbicon.oc.stopObserving('click', fbicon.obind);
				fbicon.oc.observe('click', fbicon.cbind);
				fbicon.html.style.width = "200px";
				fbicon.html.style.height = "200px";
				fbicon.html.style.border = "1px solid #b3b3b3";
				CNLT.FB.makePanel(fbicon);
			}
			else {
				FB.login(function(response) {
					if (response.status == "connected") {
						CNLT.FB.open.bind(fbicon)();
					}
				});
			}
		});
	},
	close: function() {
		this.html.style.width = "36px";
		this.html.style.height = "36px";
		this.html.style.border = "none";
		this.oc.stopObserving('click', this.cbind);
		this.oc.observe('click', this.obind);
	},
	icon: function(a) {
		this.html = a.html;
		this.oc = a.oc;
		this.index = a.index;
		this.panel = a.panel;
		this.eid = a.eid;
		this.fbevent = a.fbevent;
		this.fbeid = this.html.parentNode.getAttribute('data-fbeid');
		
		this.obind = CNLT.FB.open.bind(this);
		this.cbind = CNLT.FB.close.bind(this);
		this.oc.observe('click', this.obind);
		this.hasPanel = false;
	}
};

window.fbAsyncInit = function() {
	FB.init({
		appId   : '137240249630592',
		status  : true, // check login status
		cookie  : true, // enable cookies to allow the server to access the session
		xfbml   : true // parse XFBML
	});
};

(function() {
	var e = document.createElement('script');
	e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
	e.async = true;
	document.getElementById('fb-root').appendChild(e);
}());	
	