FB.init({
 appId  : '127663180585055',//huerta virtual
 status : true, // check login status
 cookie : true, // enable cookies to allow the server to access the session
 xfbml  : false  // parse XFBML
});


var fb_bridge=this;

if(!("console" in window) || !("firebug" in console)) {
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};

    for(var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
}


if (!eval("fb_dest_object")){
	var fb_dest_object={
		fb_error:function(msg){
			log_message("ERROR:"+msg);
		},
		fb_loggedIn:function(){
			log_message("facebook logged in");
		}
	}
}

var _api;


/*** LOGIN TO FACEBOOK ***/
function fb_login(){
	FB.login(
		function(response) {
			if (response.session) {
				if (response.perms) {
					// user is logged in and granted some permissions.
					// perms is a comma separated list of granted permissions
					var v_perms=response.perms.split(",");
					var found=false;
					for (var i=0;i<v_perms.length;i++){
						if (v_perms[i]=="publish_stream") found=true;
					}
					if (found){
						on_login_complete();
					}else{
						on_login_cancel();
					}
				} else {
					// user is logged in, but did not grant any permissions
					on_login_cancel();
				}
			} else {
				// user is not logged in
				on_login_cancel();
			}
			},
		{perms:'publish_stream'}
	);
	return true;
}


function on_login_complete(){
	fb_dest_object.fb_loggedIn();
}

function on_login_cancel(){
	fb_dest_object.fb_error("Not connected to facebook");
}


var APPURL="http://www.huertavirtual.com.uy/";
function fb_publishEvent(evt){
	log_message("fb publish site");
	attachment={
		"name"			: "Huerta Virtual de Fundación Logros",
		"href"			: APPURL,
		"description"	: evt,
		"media"			: [
					{
						"type" 	: "image",
						"src"	: APPURL+"html/img/facebook_logo.jpg",
						"href"	: APPURL
					}
						   ]
	};
		
	FB.api({
		method: 'stream.publish',
		message: '',
		attachment:	attachment
	  },
	  function(response) {
		log_message(response);
	  }
	)
}




function log_message(msg){
	if(console)	console.log(msg);
}
