var CoverFinderMastheadPopUpBubbleSemaphore = 0;
var CoverFinderMastheadPopUpBubbleStatus = 0;
var cfm_pu_txt_cntStatus = 0;
var CurrentVisibleCoverFinderMastheadPopUpText = '';

// CoverFinder Masthead Popups

function PreventCoverFinderMastheadPopUpDestroy()
{
	CoverFinderMastheadPopUpBubbleSemaphore = 1; 
	return true;
}


function AllowCoverFinderMastheadPopUpDestroy()
{
	CoverFinderMastheadPopUpBubbleSemaphore = 0; 
	setTimeout('FadeCoverFinderMastheadPopUpBubble(300)', 3000);	
}

function ShowCoverFinderMastheadPopUpBubble()
{
	if (CoverFinderMastheadPopUpBubbleStatus == 1)
	{
		return true;	
	}
	
	var BubbleTarget = $('cfm_pu_bbl_cnt');
	BubbleTarget.removeClass('cfm_pubbl_hdn');
	BubbleTarget.addClass('cfm_pubbl_vis');
	
	var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:250, transition: Fx.Transitions.Cubic.easeOut}).start(0,1);
	CoverFinderMastheadPopUpBubbleStatus = 1;	
	return true;	
}


function FadeCoverFinderMastheadPopUpBubble(TransitionTime)
{
	if (CoverFinderMastheadPopUpBubbleStatus == 0)
	{
		return true;	
	}
	
	if (CoverFinderMastheadPopUpBubbleSemaphore == 0)
	{
		var BubbleTarget = $('cfm_pu_bbl_cnt');
		var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:TransitionTime, transition: Fx.Transitions.Cubic.easeOut}).start(1,0);
		CoverFinderMastheadPopUpBubbleStatus = 0;
		setTimeout("HideCoverFinderMastheadPopUpBubble();", TransitionTime);
	}
	else
	{
		//setTimeout("FadeCoverFinderMastheadPopUpBubble("+TransitionTime+");", 1000);
	}
	
	return true;
}

function HideCoverFinderMastheadPopUpBubble()
{
	if (CoverFinderMastheadPopUpBubbleSemaphore == 0)
	{
		$('cfm_pu_bbl_cnt').removeClass('cfm_pubbl_vis');
		$('cfm_pu_bbl_cnt').addClass('cfm_pubbl_hdn');
		$('cfm_pu_bbl_cnt').setStyle('top', '-1000px');
		CurrentVisibleCoverFinderMastheadPopUpText = '';
		CoverFinderMastheadPopUpBubbleStatus = 0;
		PreventCoverFinderMastheadPopUpDestroy();
		return true;
	}
}

function ShowMastheadPopup(CallingElement, CoverFinderMastheadPopUpToShow)
{
	if (CoverFinderMastheadPopUpToShow == ''){
		return false;
	}
	PreventCoverFinderMastheadPopUpDestroy();
	RealignMastheadPopupBox(CallingElement);	
	SwitchCoverFinderMastheadPopUpText(CoverFinderMastheadPopUpToShow);
	
	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)
	}
	
	$('cfm_pu_bbl_cnt').setStyle('top', TopAdjust);
	$('cfm_pu_bbl_cnt').setStyle('right', RightAdjust);
	//$('cfm_pu_bbl_cnt').effect('top', {transition: Fx.Transitions.Elastic.easeOut}).start('top', Coords.y);
	
	return true;
}

function SwitchCoverFinderMastheadPopUpText(CoverFinderMastheadPopUpToShow)
{
	if (CurrentVisibleCoverFinderMastheadPopUpText != CoverFinderMastheadPopUpToShow)
	{
		var NewBubbleContents = document.getElementById('CoverFinderMastheadPopUp__'+CoverFinderMastheadPopUpToShow);
		var ActiveSpecialTextContainerDOM = document.getElementById('cfm_pu_txt_cnt');
		ActiveSpecialTextContainerDOM.innerHTML = NewBubbleContents.innerHTML;
		CurrentVisibleCoverFinderMastheadPopUpText = CoverFinderMastheadPopUpToShow;	
		FadeInCoverFinderMastheadPopUpText();
	}
}

function FadeInCoverFinderMastheadPopUpText()
{
	if (CoverFinderMastheadPopUpBubbleStatus == 0)
	{
		ShowCoverFinderMastheadPopUpBubble();
		var ElementFader = $('cfm_pu_txt_cnt');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:75}).start(0,1);
		cfm_pu_txt_cntStatus = 1;	
	}
	else if (CoverFinderMastheadPopUpBubbleStatus == 1 && cfm_pu_txt_cntStatus == 0)
	{
		var ElementFader = $('cfm_pu_txt_cnt');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:75}).start(0,1);
		cfm_pu_txt_cntStatus = 1;	
	}	
	
	return true;	
}


// Pitch Box Control

function ShowPitchBubble()
{
	var BubbleTarget = $('PitchBubbleContainer');
	BubbleTarget.removeClass('UpgradeBubbleHidden');
	BubbleTarget.addClass('UpgradeBubbleVisible');
	
	if (PitchBubbleStatus == 1)
	{
		return true;	
	}
	
	var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:250, transition: Fx.Transitions.Cubic.easeOut}).start(0,1);
	PitchBubbleStatus = 1;	
	return true;	
}


function HidePitchBubble()
{
	if (PitchBubbleSemaphore == 0)
	{
		$('PitchBubbleContainer').removeClass('UpgradeBubbleVisible');
		$('PitchBubbleContainer').addClass('UpgradeBubbleHidden');
		$('PitchBubbleContainer').setStyle('top', '-100px');
		PitchBubbleStatus = 0;
		CurrentVisibleCoverFinderMastheadPopUpText = '';
		return true;
	}
}

function FadePitchBubble(TransitionTime)
{
	if (PitchBubbleStatus == 0)
	{
		return true;	
	}
	
	if (PitchBubbleSemaphore == 0)
	{
		var BubbleTarget = $('PitchBubbleContainer');
		var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:TransitionTime, transition: Fx.Transitions.Cubic.easeOut}).start(1,0);
		PitchBubbleStatus = 0;
		setTimeout("HidePitchBubble();", TransitionTime);
	}
	else
	{
		setTimeout("FadePitchBubble("+TransitionTime+");", 100);
	}
	
}

function AlignPitchBox(CallingElement, RowOffset)
{
	var Coords = $(CallingElement).getCoordinates();
	var OffsetCalc = 333 + (RowOffset * 30);
	if (Coords.top)
	{
		OffsetCalc = Coords.top - 95;
	}
	$('PitchBubbleContainer').setStyle('top', OffsetCalc);
	return true;
}