/**
 * JS_BRAMUS - By Bramus! - bramus@bram.us - http://www.bram.us/
 * CC Attribution-Share Alike 3.0 - http://creativecommons.org/licenses/by-sa/3.0/
 * ------------------------------------------------
 */

	if (!JS_BRAMUS) { var JS_BRAMUS = {}; }

	
	
/**
 * JS_BRAMUS.fbc, Facebook Connect Wrapper (#facebookconnect)
 * ------------------------------------------------
 */


	JS_BRAMUS.fbc = {
		
		
		/**
		 * Init
		 * ------------------------------------------------
		 */

			init	: function() {
				
				// Debug
				// console.log('JS_BRAMUS.fbc.init');
				
				// Init Blog
				// JS_BRAMUS.fbc.initBlog();
				
				// Init News
				// JS_BRAMUS.fbc.initNews();
				
				// Init Guestbook
				// JS_BRAMUS.fbc.initGuestbook();
				
				// Init Contact
				// JS_BRAMUS.fbc.initContact();
				
				// Init (general)
				JS_BRAMUS.fbc.initGeneral();
			
			},
		
		
		/**
		 * initGeneral - Things to be loaded no matter what module we're in
		 * ------------------------------------------------
		 */

			initGeneral		: function() {
				
				// Bind click event on fbc_logout button (if any)
				$('.fbc_logout').click(function(e) {
					e.preventDefault();			// Don't jump to top
					FB.Connect.logout();		// Log out from Facebook
				});
				
			},
		
			
		/**
		 * initGuestbook - Things to be hooked at the guestbook module
		 * ------------------------------------------------
		 */
			initGuestbook	: function() {
				
				if ($('#guestbookform'))
				{
				
					// deprecated, handled via PHP!
					return;	
					
					// on submit of the form
					$('#guestbookform form').bind('submit', function(e) {
					
						// post to facebook is checked (@see http://wiki.developers.facebook.com/index.php/Publishing_Feed_Stories_to_Facebook)
						if ($('#fbconnect_posttoprofile').is(':checked'))
						{
							
							// Don't submit the form just yet!
							e.preventDefault();
							
							// Collect data
							var gb_data = {
								'post-url' 		: window.location.protocol + '//' + window.location.host + window.location.pathname,	// @todo: get from php
								'base-url' 		: window.location.protocol + '//' + window.location.host + '/',	// @todo: get from globals
								'message-short' : encodeURIComponent($('#message').val()), 						// @todo: truncateHtml
								'message-full'	: encodeURIComponent($('#message').val())
							}
							
							// post to facebook (@todo: get bundleid from php)
							FB.Connect.showFeedDialog(50641235582, gb_data, null, null, null, FB.RequireConnect.require, function() {
								
								// uncheck the checkbox
								$('#fbconnect_posttoprofile').attr('checked',false);
								
								// submit the form
								// $('#guestbookform form').get(0).submit(); // <-- Why won't this work anymore? It used to!?
								$('#guestbookform form [type="submit"]').click();
								
							});
							
						}
						
					});
					
				}
				
			},
			
		/**
		 * end of object - Bramus.you.lazy.programmer!
		 * ------------------------------------------------
		 */
		
			_eeo	: true
		
	}

// EOF