//Facebook Connect
function auth_using_fb() {
  //get the users data from FB
  var viewer  = FB.Facebook.apiClient.fql_query(
  
      'SELECT name, pic_square_with_logo,profile_url FROM user WHERE uid='+FB.Facebook.apiClient.get_session().uid,
      
      function(results) {
        update_userbox( results[0].name,
                        results[0].pic_square_with_logo,
                        results[0].profile_url,
                        'FB.Connect.logoutAndRedirect("http://www.airborne.gokartlabs.com/facebook_conn");return false;')
      }
  );
}


//Generic updates #userbox with info retrieved
//from services
function update_userbox(name, image, url, logout) {

  //populate the data in #userbox and show it
  $('#userbox').html( "<img alt='"+name+"' src='"+image+"' />"
                    + "<a href='"+url+"'>"
                    + "" + name + "</a>").show();
  
  //hide name input and service
  //login buttons
  $('#userinfo').hide();
  
  
  //populate the values of the inputs
  //using data from serivce
  $('#name').val(name);
  $('#url').val(url);
  $('#image').val(image);

}

jQuery(document).ready(function($) {
	
	Cufon.replace('#container .box h2', { separate: 'none' })('#primaryContent h2', { separate: 'none' })('#secondaryContent h2', { separate: 'none' })('#footer h2')('h3');
	
	var input = $('#signup');
	for (var a=input.length-1; a >= 0; a--) {
		if (input[a].type != 'text') { continue; } // skips non-text inputs
		input[a].mask = input[a].value;
		input[a].onfocus = function() {
			if (this.value == this.mask) { this.value = ''; }
		};
		input[a].onblur = function() {
			if (this.value == '') { this.value = this.mask; }
		};
	}
	
	$('a[rel*=facebox]').facebox();
	
	$('#supplements a').click(function() {
		$('#supplements a').removeClass('active');
		$(this).addClass('active');
			
	  var toLoad = $(this).attr('href');
	  
    $('#content').fadeOut('fast',loadContent);
    function loadContent() {
    	$('#content').load(toLoad,'',showNewContent())
    }
    function showNewContent() {
    	$('#content').fadeIn('normal');
    }
    return false;
	});
	
	$('.faqs #primaryContent').localScroll();
	
});