var TopFinderMastheadPopUpBubbleSemaphore = 0;
var TopFinderMastheadPopUpBubbleStatus = 0;
var TopFinderMastheadPopUpTextContainerStatus = 0;
var CurrentVisibleTopFinderMastheadPopUpText = '';

// TopFinder Masthead Popups

function PreventTopFinderMastheadPopUpDestroy()
{
	TopFinderMastheadPopUpBubbleSemaphore = 1; 
	return true;
}


function AllowTopFinderMastheadPopUpDestroy()
{
	TopFinderMastheadPopUpBubbleSemaphore = 0; 
	setTimeout('FadeTopFinderMastheadPopUpBubble(300)', 3000);	
}

function ShowTopFinderMastheadPopUpBubble()
{
	if (TopFinderMastheadPopUpBubbleStatus == 1)
	{
		return true;	
	}
	
	var BubbleTarget = $('TopFinderMastheadPopUpBubbleContainer');
	BubbleTarget.removeClass('TopFinderMastheadPopUpBubbleHidden');
	BubbleTarget.addClass('TopFinderMastheadPopUpBubbleVisible');
	
	var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:250, transition: Fx.Transitions.Cubic.easeOut}).start(0,1);
	TopFinderMastheadPopUpBubbleStatus = 1;	
	return true;	
}


function FadeTopFinderMastheadPopUpBubble(TransitionTime)
{
	if (TopFinderMastheadPopUpBubbleStatus == 0)
	{
		return true;	
	}
	
	if (TopFinderMastheadPopUpBubbleSemaphore == 0)
	{
		var BubbleTarget = $('TopFinderMastheadPopUpBubbleContainer');
		var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:TransitionTime, transition: Fx.Transitions.Cubic.easeOut}).start(1,0);
		TopFinderMastheadPopUpBubbleStatus = 0;
		setTimeout("HideTopFinderMastheadPopUpBubble();", TransitionTime);
	}
	else
	{
		//setTimeout("FadeTopFinderMastheadPopUpBubble("+TransitionTime+");", 1000);
	}
	
	return true;
}

function HideTopFinderMastheadPopUpBubble()
{
	if (TopFinderMastheadPopUpBubbleSemaphore == 0)
	{
		$('TopFinderMastheadPopUpBubbleContainer').removeClass('TopFinderMastheadPopUpBubbleVisible');
		$('TopFinderMastheadPopUpBubbleContainer').addClass('TopFinderMastheadPopUpBubbleHidden');
		$('TopFinderMastheadPopUpBubbleContainer').setStyle('top', '-1000px');
		CurrentVisibleTopFinderMastheadPopUpText = '';
		TopFinderMastheadPopUpBubbleStatus = 0;
		PreventTopFinderMastheadPopUpDestroy();
		return true;
	}
}

function ShowMastheadPopup(CallingElement, TopFinderMastheadPopUpToShow)
{
	if (TopFinderMastheadPopUpToShow == ''){
		return false;
	}
	PreventTopFinderMastheadPopUpDestroy();
	RealignMastheadPopupBox(CallingElement);	
	SwitchTopFinderMastheadPopUpText(TopFinderMastheadPopUpToShow);
	
	return false;
}


function RealignMastheadPopupBox(CallingElement)
{
	var Coords = $(CallingElement).getPosition();
	var WindowSize = document.body.clientWidth;
	var RightAdjust = 1;
	var TopAdjust = Coords.y+25;
	
	if( typeof( document.documentElement.clientWidth) == 'number' && document.documentElement.clientWidth != 0){
		WindowSize = document.documentElement.clientWidth;
	}
	
	if( typeof( window.innerWidth ) == 'number' &&  window.innerWidth != 0){
		WindowSize = window.innerWidth;
	}
	if (WindowSize >= 900 ){
		RightAdjust = ((WindowSize-180-100)/2);	
	}
	else if (WindowSize >= 700 ){
		RightAdjust = ((WindowSize-420)/2)
	}
	
	$('TopFinderMastheadPopUpBubbleContainer').setStyle('top', TopAdjust);
	$('TopFinderMastheadPopUpBubbleContainer').setStyle('right', RightAdjust);
	//$('TopFinderMastheadPopUpBubbleContainer').effect('top', {transition: Fx.Transitions.Elastic.easeOut}).start('top', Coords.y);
	
	return true;
}

function SwitchTopFinderMastheadPopUpText(TopFinderMastheadPopUpToShow)
{
	if (CurrentVisibleTopFinderMastheadPopUpText != TopFinderMastheadPopUpToShow)
	{
		var NewBubbleContents = document.getElementById('TopFinderMastheadPopUp__'+TopFinderMastheadPopUpToShow);
		var ActiveSpecialTextContainerDOM = document.getElementById('TopFinderMastheadPopUpTextContainer');
		ActiveSpecialTextContainerDOM.innerHTML = NewBubbleContents.innerHTML;
		CurrentVisibleTopFinderMastheadPopUpText = TopFinderMastheadPopUpToShow;	
		FadeInTopFinderMastheadPopUpText();
	}
}

function FadeInTopFinderMastheadPopUpText()
{
	if (TopFinderMastheadPopUpBubbleStatus == 0)
	{
		ShowTopFinderMastheadPopUpBubble();
		var ElementFader = $('TopFinderMastheadPopUpTextContainer');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:75}).start(0,1);
		TopFinderMastheadPopUpTextContainerStatus = 1;	
	}
	else if (TopFinderMastheadPopUpBubbleStatus == 1 && TopFinderMastheadPopUpTextContainerStatus == 0)
	{
		var ElementFader = $('TopFinderMastheadPopUpTextContainer');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:75}).start(0,1);
		TopFinderMastheadPopUpTextContainerStatus = 1;	
	}	
	
	return true;	
}
