
c8.Fb = {
		_loggedIn: false,
		_init: false,
		
		Init: function() {
			c8.Utils.Debug('Initialising Facebook');
			FB.Bootstrap.requireFeatures(["Connect"], function() {
				FB.init(c8.Config.Facebook.AppKey, c8.Config.Facebook.XdRcvr, function() { 
				c8.Fb._init = true; 
				});
			});
		},
	
		Login: function(f) {
			FB.Bootstrap.requireFeatures(["Connect"], function() {
				FB.init(c8.Config.Facebook.AppKey, c8.Config.Facebook.XdRcvr, function() { 
					FB.Connect.requireSession(function() {
						c8.Fb._init = true;
						c8.Utils.Debug('got Session');
						if(f && typeof f == 'function') {
							f(); 
						}
					});
				});
			});
		},
		
		Stream: {
			usertext: '',
			actionlink: [],
			attachment: { },
			
			Publish: function(o) {
				
				this.attachment = {
						'name': o.Title ? o.Title : 'No Title Specified',
						'caption': o.Text ? o.Text : 'No Text Specified',
						media: []
				};
				
				if(o.Description) {
					this.attachment.description = o.Description;
				}
				
				if(o.Image && o.Image.src && o.Image.href) {
						this.attachment.media = [ { type: 'image', src: o.Image.src, href: o.Image.href } ];
				}
				if(o.Link && o.Link.text && o.Link.href) {
					this.actionlink = [ { text: o.Link.text, href: o.Link.href } ];
				}
				if(o.UserText) {
					this.usertext = o.UserText;
				}
				
				c8.Utils.Debug('Facbeook Login');
				c8.Utils.Debug(c8.Fb.Stream.attachment);
				c8.Utils.Debug(c8.Fb.Stream.actionlink);

				//c8.Fb.Login(function() {
					c8.Utils.Debug('Callback to Publish');
					FB.Connect.streamPublish(c8.Fb.Stream.usertext, c8.Fb.Stream.attachment, c8.Fb.Stream.actionlink, null, null );
					c8.Fb.Stream.usertext = '';
					c8.Fb.Stream.attachment = { };
					c8.Fb.Stream.actionlinks = [];
				//});
			}
		}
}

