// Load Twitter JS-API asynchronously
function loadTwitter(){
    (function(){
      var twitterWidgets = document.createElement('script');
      twitterWidgets.type = 'text/javascript';
      twitterWidgets.async = true;
      twitterWidgets.src = 'http://platform.twitter.com/widgets.js';

      // Setup a callback to track once the script loads.
      twitterWidgets.onload = _ga.trackTwitter;

      document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
    })();
};

// FB Libraries / Google Analytics

function FB_GA(lang,appid){
	
if(!lang || lang == "undefined" ){
	lang ="en_US"
};
	(function() {
	  var e = document.createElement('script'); e.type = 'text/javascript';
	  e.src = document.location.protocol + '//connect.facebook.net/'+ lang +'/all.js';
	  e.async = true;
	  document.getElementById('fb-root').appendChild(e);
	}());	

};

window.fbAsyncInit = function(appid) {
	FB.init({
		appId  : appid,
		status : true, // check login status
		cookie : true, // enable cookies to allow the server to access the session
		xfbml  : true  // parse XFBML
	});

	_ga.trackFacebook();
	
};

function gplusone(lang){
	(function(lang){
	var gplusone = document.createElement('script');
	gplusone.type = 'text/javascript';
	gplusone.async = true;
	gplusone.src = 'https://apis.google.com/js/plusone.js';
	
	if(lang="esp"){
		gplusone.textContent = "{lang: 'es-419'}";
	}else if(!lang){};
	// Setup a callback to track once the script loads.
	gplusone.onload = _ga.trackTwitter;
	
	document.getElementsByTagName('head')[0].appendChild(gplusone);
	})();
};
