


//create onDomReady Event
window.onDomReady = initReady;

// Initialize event dpending on browser
function initReady(fn)
{
	//W3C-compliant browser
	if (document.addEventListener)
	{
		document.addEventListener("DOMContentLoaded", fn, false);
	}
	//IE
	else
	{
		document.onreadystatechange = function()
			{
			readyState(fn)
		}
	}
}

//IE execute function
function readyState(func)
{
	// DOM is ready
	if (document.readyState == "interactive" || document.readyState == "complete")
	{
		func();
	}
}

var channelPath = window.location.href;
channelPath = channelPath.split('#')[0];
channelPath = channelPath.substr(0, channelPath.lastIndexOf('/') + 1);
channelPath += 'xd_receiver.htm';

window.FB && FB.init('140477185963659', channelPath);

window.onDomReady(init);

function init()
{
	if (!swfobject.hasFlashPlayerVersion('10.0.0'))
	{
		return;
	}
	//hide flash fallback
	document.getElementById('flashcontent').style.display = 'none';

	//init FB
	if (window.FB && window.location.protocol != 'file:')
	{
		FB.ensureInit(function() {
			FB.Connect.get_status().waitUntilReady(
			function( status ) {
				showFlash();
			})});
	}
	else
	{
		showFlash();
	}
}

function isLoggedInToFacebook()
{
	return window.FB && window.FB.Connect && FB.Connect.get_loggedInUser() != null;
}

function attemptFacebookLogin(callback)
{
	if (!callback)
	{
		callback = 'facebookLoginResult';
	}
	if (!(window.FB && window.FB.Connect))
	{
		document.getElementById('flashcontent')[callback](false);
	}
	FB.Connect.requireSession(function()
		{
			document.getElementById('flashcontent')[callback](true);
		},
		function()
		{
			document.getElementById('flashcontent')[callback](false);
		},
		true);
}

function getFacebookUserData()
{
	FB.Facebook.apiClient.users_getInfo(FB.Connect.get_loggedInUser(),
			['first_name', 'pic_big'],
			function(result){fbUserResult(result, 'getUserData_result')});
}

function fbGetUserData(resultCallback)
{
	FB.Facebook.apiClient.users_getInfo(FB.Connect.get_loggedInUser(),
			['first_name', 'pic_big'],
			function(result){fbUserResult(result, resultCallback)});
}

function fbUserResult(result, callback)
{
	document.getElementById('flashcontent')[callback](result[0]);
}

function fbCreateEvent(eventInfo, callback)
{
	var win = window.open('html/popups/createevent.html', 'createevent', "width=655,height=570");
	win.channelPath = channelPath;
	win.eventInfo = eventInfo;
	win.resultCallback = function(success)
	{
		document.getElementById('flashcontent')[callback](success);
	}
}

function fbInviteToEvent(eventid, callback)
{
	var win = window.open('html/popups/invitetoevent.html', 'invitetoevent', "width=655,height=570");
	win.channelPath = channelPath;
	win.eventid = eventid;
	win.resultCallback = function(success)
	{
		document.getElementById('flashcontent')[callback](success);
	}
}


function showFlash()
{
	if (swfobject.hasFlashPlayerVersion("10.0.0"))
	{
		var cloudDataPath = '/modules/contentcloud';
		var teaserDataPath = '/data/teaser';
		if (window.location.protocol == 'file:')
		{
			cloudDataPath = 'modules/contentcloud/temp_data';
			teaserDataPath = 'data/teaser';
		}
		var flashvars =
		{
			css_url:'attach://Assets/razzStyles',
			cloudDataPath:cloudDataPath,
			teaserDataPath: teaserDataPath,
			prm_partyinvator_folder: 'modules/partyeinlader/',
			prm_facebookinfo_folder: 'modules/partyeinlader/',
			prm_razzepte_folder:'modules/razzepte/data/',
			prm_partytour_folder:'modules/partytour/data/',
			prm_partystadt_folder: 'modules/partystadt/'
		};

		var params =
		{
			bgcolor:"#950E24"
		};

		var attributes =
		{
		};

		document.getElementById('flashcontent').style.display = 'block';

		swfobject.embedSWF("razz.swf", "flashcontent", "100%", "100%", "10.0.0",
				"expressInstall.swf", flashvars, params, attributes);
		// Overwrite regular CSS used for alternative content to enable Full Browser Flash
		swfobject.createCSS("#flashcontent", "margin:0; width:100%; height: 100%; display: block; min-width:1000px; min-height:770px;");
	    swfobject.createCSS("body", "overflow:hidden; height:100%;");
	}
}
