<script type="text/javascript">
var jQueryScriptOutputted = false;
function initJQuery() {
    
    //if the jQuery object isn't available
    if (typeof(jQuery) == 'undefined') {
    
    
        if (! jQueryScriptOutputted) {
            //only output the script once..
            jQueryScriptOutputted = true;
            
            //output the script (load it from google api)
            document.write("<scr" + "ipt type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js\"></scr" + "ipt>");
        }
        setTimeout("initJQuery()", 50);
    } else {
                        
        $(function() {  
            //do anything that needs to be done on document.ready
        });
    }
            
}

initJQuery();

window.fbAsyncInit = function () {

	FB.init({
		appId: 		'<?php echo $fbjsconnect["appid"];?>',
		cookie: 	true,
		oauth:		true
	});
	
	var fb_busy = false;
	$('#fb-login').click(function () {
		if (fb_busy) return;
		fb_busy = true;

		$('#login-fb-waiting-text').text('Connecting with Facebook...');

		$('#login-btr').hide('fade', 300);
		$('#login-fb-waiting').delay(300).show('fade', 250).delay(400);

		FB.login(function (res) {
			$('#login-fb-waiting').queue(function (next) {
				if (res.status == 'connected' && res.authResponse != null) {
					$('#login-fb-waiting-text').hide('fade', 250, function () {
						$(this).text('<?php echo $logging_text;?>').show('fade', 250).delay(400).queue(function (next2) {
							//$('#mode').val('facebook-auto');
							document.location.href='<?php echo $fbjsconnect["redirect_uri"];?>';
							//$('#login-btr').submit();

							next2();
						});
					});
				}
				else {
					$('#login-fb-waiting-text').hide('fade', 300, function () {
						$(this).text('<?php echo $canclled_text;?>').show('fade', 250).delay(400).queue(function (next2) {
							$('#login-fb-waiting').hide('fade', 300, function () {
								$('#login-btr').show('fade', 400, function () { fb_busy = false; });
							});

							next2();
						});
					});
				}

				next();
			});
		}, {
			scope: '<?php echo $fbjsconnect["scope"];?>'
		});
	});
};

$(function () {
	var e = document.createElement('script'); e.type = 'text/javascript'; e.async = true;
	e.src = 'https:' + '//connect.facebook.net/en_US/all.js';
	$('#fb-root').append(e);
});
</script>
<div id="fb-root"></div>

 
  <div class="box-content"> <a class="box-fbconnect-a" href="javascript:void(0);" id="fb-login"><?php echo $fbjsconnect_button; ?></a> </div>

<form id="login-fb-waiting" style="display: none; height: 40px; margin-top: 10px;">
    <div style="margin-top: 60px; text-align: center;">
        <img src="<?php echo $base;?>catalog/view/theme/default/image/fb_loader.gif" style="margin-right: 10px; vertical-align: middle;"> <span id="login-fb-waiting-text"></span>
    </div>
</form>
