// Set up Facebook Library Call /////
var holdReportingTitle = new Array(); // reporting eVar33 holder
var currentReportingTitleIndex = 0; // index of currently playing video in playlist - Will always be 0 if this is a single video
var indexOfLikeSubscribe = null;
var facebookInitDone = false;

$(document).ready(function() {
	// Test to make sure facebook div does not already exist & create if it does not
	if ( !$('#fb-root').length ) {
		var fbDiv = document.createElement('div');
		fbDiv.id='fb-root';

		document.body.appendChild(fbDiv);
	} else {
		//fb-root already exists
	}
	
	$('#fb-root').css({
		border : '0px none',
		margin : '0px',
		padding : '0px',
		display: 'none'
	});
	
	facebookInitDone = facebookInit();
	
	FB.Event.subscribe('edge.create', function(href, widget) {
		mtvn.btg.Controller.sendLinkEvent({
			linkName:'share', 
			linkType:'o', 
			eVar9:'shows/ccinsider/blog/post' + href.replace(/http:\/\/[a-z\.\-]*/, "").replace(/\/$/, ""), 
			eVar19:'share_fblike', 
			events:'event9'
		});
	});
});

function facebookInit() {

	// exit if this has already been defined
	if ( facebookInitDone == true || typeof(FB) !='undefined' ) return true;
	
	window.fbAsyncInit = function() { 
		FB.init({
			appId: fbAppId,
			status: true,
			cookie: true,
			xfbml: true
		});
	};
	(function() {
		var e = document.createElement('script');
		e.async = true;
		e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
		document.getElementById('fb-root').appendChild(e);
	}());

	return true;
}
