var sAppKey = "08ff67559fb92180a4586e10fdae030e";
var appPath = "http://mp1.diageoprojects.com/REDGEN/sharecomponents/";
var sAppURL = "http://mp1.diageoprojects.com/REDGEN/sharecomponents/xd_receiver.htm";
//
var oFlash = null;
var isFlashReady = false;
var sKey;
var uid;
var api;

function hideLayer () {
	document.getElementById("highlayer").style.left = -5000;	
}
function showLayer () {
	document.getElementById("highlayer").style.left = 0;
}
function showFacebook () {
	FBFlashBridgeFlashDispatcher("showFacebook",null);	
}
function showTwitter () {
	FBFlashBridgeFlashDispatcher("showTwitter",null);	
}
					
					
function embed () {
	var ap = (autoPlay) ? "true" : "false";
	var flashVars = {
	as_swf_name: "flashContent",lkcat:lkcat,autoPlay:ap
	};
	var attributes = {id: "flash_flash"};
	var params = {wmode: "transparent"};
	swfobject.embedSWF(flashFile, "flashContent", flashWidth, flashHeight, "10.0.0", "../sharecomponents/expressInstall.swf", flashVars, params,attributes);
}
function delayedFBFlashBridgeInit()
{
		isFlashReady = true;
		init(swfobject.getObjectById("flash_flash"));
}
function windowMessageHandler (msg) {
	
	var type = msg.split("=")[0];
	var data = msg.split("=")[1];
	if(type == "session") {
		//login session
		var d = eval('(' +unescape(data)+')');
		sKey = d.session_key;
		uid = d.uid;
		FBFlashBridgeFlashDispatcher("onLoggedIn",d);
	} else if (type == "permission") {
		FBFlashBridgeFlashDispatcher("onGetPermission", null);
	}
}


function FBFlash_promptPermission (permissions) {
	var path = "http://www.facebook.com/connect/prompt_permissions.php?api_key="+sAppKey+"&v=1.0&next="+appPath+"login_success.html?permission=xxRESULTTOKENxx&display=popup&ext_perm="+permissions;
	var w = window.open(path,'permission','height=400,width=500,status=no,toolbar=no,menubar=no,resizable=no,scrollbars=no');

}
function doLogIn () {
	var path = "http://www.facebook.com/login.php?api_key="+sAppKey+"&connect_display=popup&v=1.0&next="+appPath+"login_success.html&cancel_url="+appPath+"login_success.html&fbconnect=true&return_session=true&req_perms=publish_stream";
	var w = window.open(path,'login','height=400,width=500,status=no,toolbar=no,menubar=no,resizable=no,scrollbars=no');
}

function dispatchEvent (eventType,data) {
	$(document).trigger(eventType, data);
}
function init (flashObj)
{

	oFlash = flashObj;
	
	FB.init(sAppKey, sAppURL);
	FB.ensureInit(function() {
      FB.Facebook.get_sessionState().waitUntilReady(function(session) {
          var is_now_logged_into_facebook = session ? true : false;

          if (is_now_logged_into_facebook) {
			FBFlashBridgeFlashDispatcher("onLoggedIn",session);
            return;
          }

        });
    });


}

function FBFlashBridgeFlashDispatcher(func)
{
	if(oFlash && isFlashReady) // && typeof obj.JStoASviaExternalInterface != "undefined")
	{		
	
		if(arguments.length > 1) {
		
			oFlash[func](Array.prototype.slice.call(arguments).slice(1)[0]);
		}else {
			oFlash[func]();
		}
	}
}
