﻿function movie() {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window["content_swf"]
	}
	else {
		return document["content_swf"]
	}
}

function connectToFacebook() {
	//console.log("connectToFacebook");
	FB.Connect.requireSession(function(){loggedIn();}, null, true); 
}

function connectedToFacebook() {
	alert("connected to facebook and flash knows about it !");
}

function loggedIn() {
	try
	{
	movie().onLoggedIn();
	
	}
	catch(err)
	{
		/*if(err){
			txt="There was an error on this page.\n\n";
			txt+="Error description: " + err.description + "\n\n";
			txt+="Click OK to continue.\n\n";
			alert(txt);
		}*/
	}
}

function getUserID(){
	var monID = FB.Connect.get_loggedInUser()
	movie().getUserID(monID);
}

function getUserPic(userID)
{
	FB.Facebook.apiClient.fql_query("SELECT pic, pic_big, pic_small FROM user WHERE uid="+userID,
							function(rows) {
							if(rows[0].pic_big != null && rows[0].pic_big != undefined && rows[0].pic_big != '')
								movie().getUserPicURL(rows[0].pic_big);
							else if(rows[0].pic != null && rows[0].pic != undefined && rows[0].pic != '')
								movie().getUserPicURL(rows[0].pic);
							else if(rows[0].pic_small != null && rows[0].pic_small != undefined && rows[0].pic_small != '')
								movie().getUserPicURL(rows[0].pic_small);
							});
}

function streamPublish(message, urlImage, urlVisu){
	var attachment = {'name':'c-zero.citroen.com', 'href':'c-zero.citroen.com', 'description':'Source: www.c-zero.citroen.com', 'media':[{'type': 'image', 'src': urlImage, 'href': urlVisu}]};
	var actionLinks = [{ "text": "Citroen", "href": "http://www.citroen.com"}];
	FB.Connect.streamPublish(message, attachment, actionLinks, null , null, function(){facebookStatusUpdated();});//, attachment, action_links, target_id, user_message_prompt, callback, auto_publish, actor_id);
}

function facebookStatusUpdated() {
	movie().onStreamPublish()
}

//var APIKEY = "575528e84f329d2fabdb1c963a83fd6f";
var APIKEY = "444144c6f6b3844221c6fc285794be4d";
FB.init(APIKEY, "/preproduction/xd_receiver.htm");
