function FBInit()
{
	FB.login(function(response)
	{
        if (response.session)
		{
			if (response.perms)
			{
				FBLoginResult(response.session.access_token);
				// user is logged in and granted some permissions.
			}
			else
			{
				// user is logged in, but did not grant any permissions
			}
		} else
		{
			// user is not logged in
		}
	}, {perms:'user_photos, user_hometown, user_birthday'});
}

function FBLoginResult(access_token)
{
	var swf = getSWF("global");
    if (swf)
    	swf.fbLoginResult(access_token);
    else
    	alert("Can't find swf");
}

function notifyLikeAction()
{
	var swf = getSWF("global");
    if (swf) 
    {
    	//alert("like action");
    	//swf.fbLikeAction(); 
    }
    else 
    	alert("Can't find swf");
}

function getSWF(swf)
{

    //alert (navigator.appName.indexOf("Microsoft"),swf)

    if (navigator.appName.indexOf("Microsoft") != -1) {
		if (typeof(window[swf]) != 'undefined') {
		    return window[swf];
		} else {
    		return document[swf];
    	}
    } else {
        return document[swf];
    }
}

/**
 * param	description		String
 * param 	medias  		Array of Objects {type, src, href}
 * param 	href  			String 
 */
function publishPost(message,qui,link,medias)
{
    //alert (medias + " " + medias[0].src);
	
    FB.ui
	({
	 method: 'stream.publish',
	 attachment: {
	   name: qui,
	   caption: message,
	   media: medias,
	   description: "",
	   href: link
	 },
	 action_links: [
	   { text: 'Code', href: link }
	 ],
	 
	 user_message_prompt:qui
   },
   function(response) 
   {
		var o = getSWF("global");
		if(o)
		{
			if (response && response.post_id) 
			{
				o.fbPublishPost(true);
			} 
            else 
			{
				o.fbPublishPost(false);
			}
		}
	});
}

function openWindow(daUrl, daWidth, daHeight) {
    var daPopup = window.open(daUrl, "daPopup", "menubar=no, status=no, scrollbars=no, menubar=no, width=" + daWidth + ", height=" + daHeight);
    daPopup.focus();

}

var fb_div = document.createElement("div");
fb_div.setAttribute('id', 'fb-root');
document.body.appendChild(fb_div);

FB.init({
  appId  : '175676039123343',
  status : true, // check login status
  cookie : true, // enable cookies to allow the server to access the session
  xfbml  : true});

FB.Event.subscribe('auth.sessionChange', function (response) 
 {
	if (response.session) 
	{               
	  FBLoginResult(response.session.access_token);
	}
	else 
	{
		// The user has logged out, and the cookie has been cleared
	}
});


