function fbPopup(url, useThickbox)
{
	if( useThickbox == true )
		tbPopup(url)
	else
		winPopup(url)
		
	return true;
}

// show regular window popup
var win;	// the popup window handle

function winPopup(url)
{
	win = window.open(url + "&display=popup", 'fb', 'width=500,height=400,directories=no,location=no,resizable=no,menubar=no,toolbar=no,status=no');
	detectWhenPopupCloses();
}

// detects when the popup win closes
function detectWhenPopupCloses()
{
	if (win)
	{
		if (win.closed)
			onFBClose();
		else 
			setTimeout(detectWhenPopupCloses, 250); //check every 250 msec
	}
}

// show thickbox
function tbPopup(url)
{
	var tb_url = url + "&display=popup&TB_iframe=true&height=400&width=500";
	tb_show('Connect to Facebook', tb_url);
	
	onTBClose = onFBClose;
}

// called when facebook window is closed
function onFBClose()
{
	getFlash().onFBClose();
}

// get flash movie
function getFlash()
{
	var movieName = jQuery('embed[src$=swf]').attr('name');
	
	if (navigator.appName.indexOf("Microsoft") != -1)
		return window[movieName];
		
	return document[movieName];
}
