type_terms = ["het&middot;er&middot;o&middot;clite",	"i&middot;car&middot;i&middot;an","quo&middot;tid&middot;i&middot;an",	"rec&middot;on&middot;dite"];
type_defs = [
	"Life is never black-or white…so you’ve traded rose colored glasses for a pair of sparkly, oversized rainbow shades that reveal the quirkier side of life. Intrigued by the unusual and driven to the extraordinary, you see the colorful nuances that keep everyone around you on their toes.",
	"Bigger! Better! Faster! More! On a scale of 8 – 10, you still strive for 11. In your myopic world, you see danger around every corner and have built up quite the snarky defenses. Just make sure keeping your eye on the prize doesn’t prevent you from seeing life’s little gems sparkling all around you. ",		
	"You’re genuine salt-of-the-earth…which, if wasn’t toxic to beautiful flowers growing in otherwise healthy soil, would be a compliment! Because always grounded and eternally optimistic, you are determined to see the world with your head on straight heart pumping and arms wide open.",
	"Life has opened your eyes to some hard truths and you’re never afraid to dive under the surface for valuable insights. But don’t let cynicism drown you in the deep end – grab some floaties, remove those cloudy goggles and see that the world still has plenty to offer those that practice what they preach! "
									 
];
			
/*
 * Show the feed form. This would be typically called in response to the
 * onclick handler of a "Publish" button, or in the onload event after
 * the user submits a form with info that should be published.
 *
*/

function facebook_publishFeedStory(result) {
	// form_bundle_id should be set globally on initial page load
	// Load the feed form
  FB.ensureInit(function() {
		FB.Connect.ifUserConnected(function(){
			var template_data = {
				"images":[
						{"src":"http://www.lovehappensmovie.com/inc/images/key_art.jpg", "href":"http://www.lovehappensmovie.com"},
						{"src":"http://www.lovehappensmovie.com/inc/images/badge_"+result+".jpg", "href":"http://www.lovehappensmovie.com"}],
				"type_term":type_terms[result],"type_def":type_defs[result]};
				FB.Connect.showFeedDialog(form_bundle_id, template_data);
      	//FB.Connect.showFeedDialog(form_bundle_id, template_data, null, null, FB.FeedStorySize.shortStory, FB.RequireConnect.promptConnect);
	      // hide the "Loading feed story ..." div
  	    ge('feed_loading').style.visibility = "hidden";
		}, FB.Connect.requireSession);
	});
}

facebook_inviteFriends = function (result) { 
	FB.ensureInit(function() {
	FB.Connect.ifUserConnected(
		function(){
			var myHost = 'http://'+location.host+location.pathname;
			var title = "Invite your Facebook friends to question their perception";

			var content = 'I just completed the <a href=\''+myHost+'\'>Question of Perception</a> visual personality quiz from Love Happens and I\'m a:';
			content += '  <b>'+type_terms[result]+'</b>:  ';
			content += type_defs[result];
			content += 'Think we\'re compatible? <a href=\''+myHost+'\'>Take the quiz now</a> and discover you\'re personality type.';
			content += ' &lt;fb:req-choice url=\'' + myHost + '\' label=\'Love Happens Questions of Perception Quiz\'';
	
			var buttonLabel = 'Quiz';
			var actionText = 'Want to test your compatibility? Invite your Friends to take the quiz.';
			var body = '<fb:request-form action="' +myHost+ '" method="POST" invite="true" type="'+buttonLabel+'" content="'+content+'">'+ 
					 			'<fb:multi-friend-selector showborder="false" rows="4" actiontext="'+actionText+ '" /></fb:request-form>';
					 var inviteIFrame = new FB.UI.FBMLPopupDialog(title,body);
					 inviteIFrame.setContentWidth(590);
					 inviteIFrame.setContentHeight(500);
					 inviteIFrame.show();
				}, FB.Connect.requireSession);
			});
	}	

	

/*
 * The facebook_onload statement is printed out in the PHP. If the user's logged in
 * status has changed since the last page load, then refresh the page to pick up
 * the change.
 *
 * This helps enforce the concept of "single sign on", so that if a user is signed into
 * Facebook when they visit your site, they will be automatically logged in -
 * without any need to click the login button.
 *
 * @param already_logged_into_facebook  reports whether the server thinks the user
 *                                      is logged in, based on their cookies
 *
 */
function facebook_onload(already_logged_into_facebook) {
  // user state is either: has a session, or does not.
  // if the state has changed, detect that and reload.
	FB.ensureInit(function() {
      FB.Facebook.get_sessionState().waitUntilReady(function(session) {
           is_now_logged_into_facebook = session ? true : false;

          // if the new state is the same as the old (i.e., nothing changed)
          // then do nothing
          if (is_now_logged_into_facebook == already_logged_into_facebook) {
            return;
          }

          // otherwise, refresh to pick up the state change
          refresh_page();
        });
    });
}

/*
 * Our <fb:login-button> specifies this function in its onlogin attribute,
 * which is triggered after the user authenticates the app in the Connect
 * dialog and the Facebook session has been set in the cookies.
 */
function facebook_onlogin_ready() {
  // In this app, we redirect the user back to index.php. The server will read
  // the cookie and see that the user is logged in, and will deliver a new page
  // with content appropriate for a logged-in user.
  //
  // However, a more complex app could use this function to do AJAX calls
  // and/or in-place replacement of page contents to avoid a full page refresh.
  refresh_page();
}

/*
 * Do a page refresh after login state changes.
 * This is the easiest but not the only way to pick up changes.
 * If you have a small amount of Facebook-specific content on a large page,
 * then you could change it in Javascript without refresh.
 */
function refresh_page() {
  window.location = 'index.html';
}

/*
 * Prompts the user to grant a permission to the application.
 */
function facebook_prompt_permission(permission) {
  FB.ensureInit(function() {
    FB.Connect.showPermissionDialog(permission);
  });
}

