window.fbAsyncInit = function() {

	var idLoc = '191422744223856';
	var idStage = '180013362042996';
	var idLive = '199758583384390';
	var hostName = getBaseURL();
	var idApp;
	
	switch(hostName){
		case 'http://55dsl.v3.franz.local/':
			idApp = idLoc;
		break;
		case 'http://v3.55dsl.stage.hellomutado.com/':
			idApp = idStage;
		break;
		case 'http://55dsl.com/':
			idApp = idLive;
		break;
	}
    FB.init({appId: idApp, status: true, cookie: true,xfbml: true});

};


(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
  '//connect.facebook.net/it_IT/all.js';
document.getElementById('fb-root').appendChild(e);
}());





//custom function 
function FB_publish_call(f_name, f_description, f_media_src, f_href ){

/*
	console.log( f_name );
	console.log( f_description );
	console.log( f_media_src );
	console.log( f_href );
*/

	var post = {
		 method: 'stream.publish',
	     message: '',
	     attachment: {
	       name: f_name,
	       caption: '',
	       description: (
	         f_description
	       ),
		   media:
		   [
		    	{ 
			        "type": "image", 
			        "src": f_media_src, 
			        "href": f_href
			    }
		   ],
	       href: f_href
	     }
	};
	
	
	
	FB.ui(
	   post,
	   function(response) { }
	 );
}

function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }

}
