var api_key = 'beee6656415cb590e0548d880fd1ff6d';
var channel_path = 'xd_receiver.htm';

function publishStory( theMessage ) {
	
	//FB_RequireFeatures(["Api"], function(){
	    
		//FB.Facebook.init(api_key, channel_path);
	    
	    	// require user permissions
	    	FB.Connect.showPermissionDialog("publish_stream", function() { 
	       		
		   var attach = {
	   			"name": "Equinox's My Body My Biography",
			   "href": "http: //www.mybodymybiography.com",
			   "caption": "",
			   "description": "I was inspired by Equinox's MyBodyMyBiography.com to submit my own story. Read remarkable stories of personal triumph and share your own.",
			   'media': [
			       {
			           'type': 'image',
			           'src': 'http://www.mybodymybiography.com/eq_logo.jpg',
			           'href': 'http://www.mybodymybiography.com' 
			       } 
			   ]
			};


	       		
	       		FB.Connect.streamPublish(theMessage, attach, null, null, 'My Body My Story', onPublishComplete );
		});
	    	
	//});
}

function onPublishComplete() {
	
}

function fb_connect() {
	FB_RequireFeatures(["Api"], function(){
	    // Create an ApiClient object, passing app's API key and 
	    // a site relative URL to xd_receiver.htm
	    FB.Facebook.init(api_key, channel_path);
	    
	    var api = FB.Facebook.apiClient;
	    // require user to login 
	    FB.Connect.requireSession(function(exception){
	       
	       //
	       //alert(FB.Facebook.apiClient.get_session().uid)
			FB.Facebook.apiClient.users_getInfo( new Array(FB.Facebook.apiClient.get_session().uid), ["first_name", "last_name", "pic_square", "current_location"], handleConnectComplete );
	        
	        // api.friends_get(new Array(), function(result, exception){
	        //      FB.FBDebug.dump(result, 'friendsResult from non-batch execution ');
	        // });
	    });
	});
}

function getFlashMovieObject( movieName ){
	if (window.document[movieName] ){
		return window.document[movieName];
	}
	
	if ( navigator.appName.indexOf( 'Microsoft Internet' ) == -1 ){
		if ( document.embeds && document.embeds[movieName] ) {
			return document.embeds[movieName];
		}
	} else {
		return document.getElementById( movieName );
	}
}

function handleConnectComplete( result, exception ){
	//alert("connect complete: " + exception + " " + result[0].pic_square );
	
	var flashMovie = getFlashMovieObject( 'Equinox' );
	flashMovie.setFacebookInfo( result[0].first_name, result[0].last_name, result[0].pic_square, result[0].current_location );
	
	
}

