<!-- Facebook connect block -->

<div id="fb-root"></div>
<script type="text/javascript">
//<![CDATA[
var responsive_template = {if $tpl_settings.type == 'responsive_42'}true{else}false{/if};
{literal}

window.fbAsyncInit = function() {
	FB.init({
		appId: '{/literal}{$config.facebookConnect_appid}{literal}', // App ID from the app dashboard
		channelUrl : '{/literal}{$config.bookmarks_fb_box_url}{literal}', // Channel file for x-domain comms
		cookie: true, // Check Facebook Login status
		xfbml: true, // Look for social plugins on the page
		version: 'v2.2'
	});

	// bookmarks
	if ($('#fl-facebook-funs').length > 0) {
		FB.Event.subscribe('xfbml.render', function(response) {
			var width = $('#fl-facebook-funs').width();
			$('.fb_iframe_widget iframe, .fb_iframe_widget > span').width(width);
		});
	}
};

if (!document.getElementById('fb-nav-bar')) {
	var fcDOM = '<img style="cursor:pointer;" alt="" title="{/literal}{$lang.fConnect_login_title}{literal}" src="{/literal}{$smarty.const.RL_PLUGINS_URL}{literal}facebookConnect/static/fb_login.png" onclick="fcLogin();" />';
	$('input[value=login]:first').parent().find('input[type=submit]').after(fcDOM);
}
else {
	// move FB icon
	if ( $('form[name="userbar_login"]').length ) {
		$('input[name=username]').before($('img[onclick="fcLogin();"]'));
		$('img[onclick="fcLogin();"]').css('margin-right', '5px');
	}
}

if ( responsive_template && $('img#fb-nav-bar').length ) {
	$('img#fb-nav-bar').after('<a title="{/literal}{$lang.fConnect_login_title}{literal}" class="fb-connect" href="javascript:fcLogin()">{/literal}{$lang.fConnect_connect}{literal}</a>');
	$('img#fb-nav-bar').remove();
}

function fcLogin() {
	var seoUrl = rlConfig['libs_url'].replace('libs', 'plugins');
	window.location.href = seoUrl + 'facebookConnect/request.php';
}

(function(d) {
	var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
	js = d.createElement('script'); js.id = id; js.async = true;
	js.src = "//connect.facebook.net/en_US/all.js";
	d.getElementsByTagName('head')[0].appendChild(js);
}(document));

{/literal}
//]]>
</script>

<!-- Facebook connect block end -->