function fbcIsLoggedIn(){
	var status = FB.Connect.get_loggedInUser();
	return (status) ? true : false;
}

function fbcOnLogin(){
	window.location = BASE_HTTPS +'/my-garage/fbconnect/connect';
}

function fbcPostItem(type, title, href, thumb){
	fbcQueueAction('fbcPost', 1000, 'added a new '+ type +' "'+ title +'"', href, thumb);
}

function fbcPost(message, href, thumb){

	// Clear timer
	if(fbc_queue_timer) clearTimeout(fbc_queue_timer);
	
	var data = {
		'caption':	"{*actor*} just "+ message +" over at Alpine's Underground Garage!",
		'href':		href
	};
	
	// If an image was specified then add it to the data object
	if(thumb){
		data['media'] = [{
			'type':		'image',
			'src':		thumb,
			'href':		href
		}];
	}

	Facebook.users_hasAppPermission('status_update', function(allowed){
		if(allowed){
			fbcPublishToWall(data, true);
		}else{
			FB.Connect.showPermissionDialog('status_update', function(allowed){
				if(allowed){
					fbcPublishToWall(data, false);
				}else{
					alert('You must grant permission to update your Facebook status before you can post Alpine Underground Garage updates to your Wall.');
				}
			});
		}
	});
}

var fbc_queue_timer = false;
function fbcQueueAction(func, timer){
	var func_string = func +'(';

	for(var i=2; i < arguments.length; i++){
		func_string += "'"+ arguments[i] +"'";
		if(i < (arguments.length - 1)){
			func_string += ", ";
		}
	}

	func_string += ')';

	fbc_queue_timer = setTimeout(func_string, timer);
}

function fbcPublishToWall(data, auto_post){
	//FB.Connect.streamPublish('', data);
	FB.Connect.streamPublish('', data, null, '', '', null, auto_post);
}