window.fbAsyncInit = function() {
	FB.init({appId: '116066741810189',status: true,cookie:true, xfbml:true });
};
(function () {
	var e = document.createElement('script');
	e.type = 'text/javascript';
	e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
	e.async = true;
	document.getElementById('fb-root').appendChild(e);
} ());

function do_facebook_login(redirectTo)
{
	FB.login(function(response) {
		facebook_login(response, redirectTo);
	}, {perms: 'publish_stream,user_location,email'});
}

function facebook_login(response, redirectTo)
{
	if (response.session !== undefined && response.session.uid !== undefined) {
		window.location.href = "/account/sign_in_facebook";
	} else {
		(redirectTo) ? (window.location.href = redirectTo) : window.location.reload(true);
	}
}

function publish_feed(){
	FB.ui(
	   {
		 method: 'feed',
		 name: 'Free Domain Name With DNS Support From CO.VU',
		 link: 'http://www.co.vu',
		 picture: 'http://www.co.vu/img/logotop.png',
		 caption: 'Free domain name from CO.VU',
		 description: 'Dialogs provide a simple, consistent interface for applications to interface with users.',
		 message: 'Hay just movied!'
	   },
	   function(response) {
		 if (response && response.post_id) {
		   alert('Post was published.');
		 } else {
		   alert('Post was not published.');
		 }
	   }
	 );
}
