var FB_FeatureRequestQueue = [];

/*
 * Use this to request loading of features in Facebook Client JavaScript library
  *@param features  array of features
 * @param callback  callback function to be executed when all required features are loaded.
 */
function FB_RequireFeatures(features, callback) {
  FB_FeatureRequestQueue[FB_FeatureRequestQueue.length] = {"features": features, "callback":callback, "loadedCount":0};
  if (window.FB && window.FB.FeatureLoader && window.FB_FeatureMap) {
    FB.FeatureLoader.singleton.checkRequestQueue();
  }
  else {
    if(!window.FB_FeatureMap) {
      //Check for querystring to see if there is parameter for fb_jsrev.
      //If it exists, use that, otherwise, we will use current hour
      //to ensure that we update the FeatureMap.js at least once an hour
      if(!window.FB_JsRevString) {
        window.FB_JsRevString = null;
        var queryString = window.location.search;
        if (queryString.length > 1) {
          var segments = queryString.substr(1).split('&');
          for (var i = 0; i < segments.length; i++) {
            var segment = segments[i];
            var j = segment.indexOf('=');
            if (j > 0) {
              var key = segment.substr(0, j);
              if (key === 'fb_jsrev') {
                  FB_JsRevString = segment.substr(i + j + 1);
                  break;
              }
            }
          }
        }
      }
    }

    var featureMapJsUrl;

    if (!window.FB_JsRevString) {
      var hour = Math.round((new Date).getTime() / (1000 * 60 * 60));
      featureMapJsUrl = 'http://static.ak.facebook.com/js/api_lib/v0.3/FeatureMap.js.php?r=' + hour.toString();
    }
    else {
      featureMapJsUrl = 'http://static.ak.facebook.com/rsrc.php/' + FB_JsRevString + '/js/api_lib/v0.3/FeatureMap.js.php';
    }

    FB_AddScript(featureMapJsUrl);
  }
}

//This is a private function
function FB_AddScript(src)
{
  var scriptElement = document.createElement('script');
  scriptElement.type = 'text/javascript';
  scriptElement.src = src;
  document.getElementsByTagName('HEAD')[0].appendChild(scriptElement);
}
var api_key = '4db8ee65351292ef2a314b864ed55fc0';
var channel_path = './xd_receiver.htm';
function sendFriendsInfo(iContent)
{
	FB_RequireFeatures(["Api"], function(){
	    FB.Facebook.init(api_key, channel_path);
	    var api = new FB.ApiClient(api_key);
	    api.requireLogin(function(exception){
	        uid = api.get_session().uid;
	        api.friends_get(null, function(result){
	            for(var i=0;i<result.length;i++)
	            {
	            	api.notifications_send(result[i],iContent,function(data){});
	            }
	        });
	    });
	});
}