		var appId = "105332986172555";
		
		//jQuery('#fb-root').remove();
        jQuery("body").append('<div id="fb-root"><!-- facebook --></div>');
		
		
	    FB.init({  
	          appId  : appId,  
	          status : true, // check login status  
	          cookie : true, // enable cookies to allow the server to access the session  
	          xfbml  : true,  // parse XFBML  
	          oauth : true //enables OAuth 2.0  
	    });  
	        
	        /* All the events registered 
            FB.Event.subscribe('auth.login', function (response) {
                // do something with response
                alert("login success");
            });
            FB.Event.subscribe('auth.logout', function (response) {
                // do something with response
                alert("logout success");
            });
            FB.Event.subscribe('auth.sessionChange', function(response){
				if (response.session) {
			       	// A user has logged in, and a new cookie has been saved
			    } else {
			            // The user has logged out, and the cookie has been cleared
			    }
			});

            FB.getLoginStatus(function (response) {
                if (response.session) {
                    // logged in and connected user, someone you know
                    alert("login success");
                }
            });*/
	     
	      /*(function() {
                var e = document.createElement('script');
                e.type = 'text/javascript';
                e.src = document.location.protocol +
                    '//connect.facebook.net/en_US/all.js#xfbml=1';
                e.async = true;
                document.getElementById('fb-root').appendChild(e);
            }());*/
			    
			    function on_facebook_login(){
			        FB.getLoginStatus(function(response){
			            if (response.status == 'connected') {
			                var url = "http://graph.facebook.com/"+response.authResponse.userID+"?format=json&callback=?";
							jQuery.getJSON(url,
								function(data) {
									openFriendInvites(data.link, data.first_name, "${userId}");												
								}
							);
			            }
			            else {
			                // no user session available, someone you dont know
			            }
			        });
			    }
			    
			    function removeFBAccount(){
			    	var answer = confirm("Are you sure you want to remove the link to your social account?");
					if (answer) {
						changeDataCommand("removeFBAccount");
					}			    				    							
				}
			    
			    /**
			     * Subscribe to 'edge.create' facebook event a callback to award a sweepstakes ticket
			     * 
			     */
			    function edgeCreateSubscribeTicket(){

        			FB.Event.subscribe('edge.create', function(response) {
	        			jQuery.post( 
	        					urlPrefix+"/apispring/awardTicket",
	        		             { numberOfTickets: 1 },
	        		             function(data) {
	        		                jQuery('#stage').html(data);
	        		             }

	        		          );
					});
                    
                  }
                  
			    var openFriendInvites= function(fbLink,fbFirstName,userId){
            		var oldSize = FB.UIServer.Methods["fbml.dialog"].size;
            		
					FB.UIServer.Methods["fbml.dialog"].size = {width:760, height:533};
					
					 
					var dialog = {
						method: 'fbml.dialog',
						display: 'dialog',
						fbml:'<fb:request-form action="'+secureUrlPrefix+'/portal/dashboardAlias" method="post" invite="true" type="Wazzamba" content="<a href=\''+fbLink+'\'>'+fbFirstName+'</a> has invited you to join Wazzamba! Join today and will give you 10 FREE coins to help you win the trip of your dreams! <fb:req-choice url=\''+urlPrefix+'/portal/basicMain?c_code=IR_FB_INVITE&amp;c_redeamer='+userId+'\' label=\'Accept\' />" <fb:multi-friend-selector showborder="true" email_invite="false" bypass="step" import_external_friends="false" actiontext="Invite your friends to Wazzamba" /> </fb:request-form>',
						width:760,
						height:533
					};
					
					FB.ui(dialog, function(result) { return; } );
					
					FB.UIServer.Methods["fbml.dialog"].size = oldSize;
					logPortalEvent( 'INVITATION_START', 'InviteFriends');
				}
