var BubbleSemaphore = 0;
var BubbleStatus = 0;
var TextContainerStatus = 0;
var CurrentVisibleSpecialText = '';

var PropHelpGuideBubbleSemaphore = 0;
var PropHelpGuideBubbleStatus = 0;
var PropHelpGuideTextContainerStatus = 0;
var CurrentVisiblePropHelpGuideText = '';

var PromoPopupBubbleSemaphore = 0;
var PromoPopupBubbleStatus = 0;
var PromoPopupTextContainerStatus = 0;
var CurrentVisiblePromoPopupText = '';

var PitchBubbleStatus = 0;
var PitchBubbleSemaphore = 0;
var isIndexPage = 1;

var isVolvoPentaStore = 0;

// Special/ pitch guide functions

function PreventDestroy()
{
	BubbleSemaphore = 1; 
	return true;
}


function AllowDestroy()
{
	BubbleSemaphore = 0; 
	setTimeout('FadeBubble(300)', 2000);	
}

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

function FadeBubble(TransitionTime)
{
	if (BubbleStatus == 0){
		return true;	
	}
	
	if (BubbleSemaphore == 0){
		var BubbleTarget = $('UpgradeBubbleContainer');
		var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:TransitionTime, transition: Fx.Transitions.Cubic.easeOut}).start(1,0);
		BubbleStatus = 0;
		setTimeout("HideBubble();", TransitionTime);
	}
	else{
		setTimeout("FadeBubble("+TransitionTime+");", 100);
	}
}

function HideBubble()
{
	if (BubbleSemaphore == 0){
		$('UpgradeBubbleContainer').removeClass('UpgradeBubbleVisible');
		$('UpgradeBubbleContainer').addClass('UpgradeBubbleHidden');
		$('UpgradeBubbleContainer').setStyle('top', '-100px');
		CurrentVisibleSpecialText = '';
		BubbleStatus = 0;
		PreventDestroy();
		return true;
	}
}

function FadeOutBubbleText()
{
	if (BubbleStatus == 1 && TextContainerStatus == 1)
	{
		var ElementFader = $('UpgradeTextContainer');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:20}).start(1,0);
		TextContainerStatus = 0;	
	}	
	return true;	
}

function FadeInBubbleText()
{
	if (BubbleStatus == 0){
		ShowBubble();
		var ElementFader = $('UpgradeTextContainer');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:75}).start(0,1);
		TextContainerStatus = 1;	
	}
	else if (BubbleStatus == 1 && TextContainerStatus == 0){
		var ElementFader = $('UpgradeTextContainer');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:75}).start(0,1);
		TextContainerStatus = 1;	
	}	
	return true;	
}

function RealignFloatBox(CallingElement)
{
	var Coords = $(CallingElement).getPosition();
	$('UpgradeBubbleContainer').setStyle('top', Coords.y-28);
	return true;
}



function SwitchText(SpecialToShow)
{
	if (CurrentVisibleSpecialText != SpecialToShow){
		var NewBubbleContents = document.getElementById('Special__'+SpecialToShow);
		ActiveSpecialTextContainerDOM = document.getElementById('UpgradeTextContainer');
		ActiveSpecialTextContainerDOM.innerHTML = NewBubbleContents.innerHTML;
		CurrentVisibleSpecialText = SpecialToShow;	
		FadeInBubbleText();
	}
}

function ShowSpecial(CallingElement, SpecialToShow)
{
	if (SpecialToShow == ''){
		return false;
	}
	PreventDestroy();
	RealignFloatBox(CallingElement);	
	SwitchText(SpecialToShow);
	
	return false;
}



function JS_Window(PageURL, Width, Height)
{
	if (PageURL == '#'){
		return true;	
	}
	
	var screenXAdjust = (screen.width / 2) - (Width / 2);
	var screenYAdjust = (screen.height / 2) - (Height / 2);
	
	window.open(PageURL,'PropellerHelp','scrollbars=1,resizable=1,toolbar=0,status=0,menubar=0,location=0,width='+Width+',height='+Height+',left='+screenXAdjust+',top='+screenYAdjust);
	return false;
}

function InfoPopupWindow(CallingElement)
{
	var defaultWidth = 800;
	var defaultHeight = 600;
	var gotoURL = '#';
	gotoURL = $(CallingElement).getProperty('href');
	return JS_Window(gotoURL, defaultWidth, defaultHeight);
}

function ChangeSearchVisibility()
{
	var element = document.getElementById("changeSearchControls");
	if (element.className == 'changeSearchHidden'){
		element.className = 'changeSearchVisible';}
	else{
		element.className = 'changeSearchHidden';}
}

function ClosePopupAndRidirect(IsAPopUp, GoToURL)
{
	if (IsAPopUp == '1'){
		window.opener.location.replace(GoToURL);
		window.close();
		return false;
	}
	else{
		return true;
	}
}

// Prop Help Guide

function PreventPropHelpGuideDestroy()
{
	PropHelpGuideBubbleSemaphore = 1; 
	return true;
}


function AllowPropHelpGuideDestroy()
{
	PropHelpGuideBubbleSemaphore = 0; 
	setTimeout('FadePropHelpGuideBubble(300)', 3000);	
}

function ShowPropHelpGuideBubble()
{
	if (PropHelpGuideBubbleStatus == 1){
		return true;	
	}
	
	var BubbleTarget = $('PropHelpGuideBubbleContainer');
	BubbleTarget.removeClass('PropHelpGuideBubbleHidden');
	BubbleTarget.addClass('PropHelpGuideBubbleVisible');
	
	var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:250, transition: Fx.Transitions.Cubic.easeOut}).start(0,1);
	PropHelpGuideBubbleStatus = 1;	
	return true;	
}


function FadePropHelpGuideBubble(TransitionTime)
{
	if (PropHelpGuideBubbleStatus == 0){
		return true;	
	}
	
	if (PropHelpGuideBubbleSemaphore == 0){
		var BubbleTarget = $('PropHelpGuideBubbleContainer');
		var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:TransitionTime, transition: Fx.Transitions.Cubic.easeOut}).start(1,0);
		PropHelpGuideBubbleStatus = 0;
		setTimeout("HidePropHelpGuideBubble();", TransitionTime);
	}
	return true;
}

function HidePropHelpGuideBubble()
{
	if (PropHelpGuideBubbleSemaphore == 0){
		$('PropHelpGuideBubbleContainer').removeClass('PropHelpGuideBubbleVisible');
		$('PropHelpGuideBubbleContainer').addClass('PropHelpGuideBubbleHidden');
		$('PropHelpGuideBubbleContainer').setStyle('top', '-100px');
		CurrentVisiblePropHelpGuideText = '';
		PropHelpGuideBubbleStatus = 0;
		PreventPropHelpGuideDestroy();
		ShowDropDownsPropNumber();
		return true;
	}
}

function ShowHelpGuide(CallingElement, PropHelpGuideToShow)
{
	if (PropHelpGuideToShow == ''){
		return false;
	}
	PreventPropHelpGuideDestroy();
	RealignHelpGuideBox(CallingElement);	
	SwitchPropHelpGuideText(PropHelpGuideToShow);
	
	if (PropHelpGuideToShow == 'PartNumber')
	{
		HideDropDownsPropNumber();	
	}
	
	return false;
}


function RealignHelpGuideBox(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 (isVolvoPentaStore == 1){
		RightAdjust = ((WindowSize-680)/2);
	}
	else if (WindowSize >= 900 ){
		RightAdjust = ((WindowSize-180-340)/2);	
	}
	else if (WindowSize >= 700 ){
		RightAdjust = ((WindowSize-680)/2)
	}
	
	$('PropHelpGuideBubbleContainer').setStyle('top', TopAdjust);
	$('PropHelpGuideBubbleContainer').setStyle('right', RightAdjust);
	//$('PropHelpGuideBubbleContainer').effect('top', {transition: Fx.Transitions.Elastic.easeOut}).start('top', Coords.y);
	
	return true;
}

function SwitchPropHelpGuideText(PropHelpGuideToShow)
{
	if (CurrentVisiblePropHelpGuideText != PropHelpGuideToShow){
		var NewBubbleContents = document.getElementById('PropHelpGuide__'+PropHelpGuideToShow);
		var ActiveSpecialTextContainerDOM = document.getElementById('PropHelpGuideTextContainer');
		ActiveSpecialTextContainerDOM.innerHTML = NewBubbleContents.innerHTML;
		CurrentVisiblePropHelpGuideText = PropHelpGuideToShow;	
		FadeInPropHelpGuideText();
	}
}

function FadeInPropHelpGuideText()
{
	if (PropHelpGuideBubbleStatus == 0){
		ShowPropHelpGuideBubble();
		var ElementFader = $('PropHelpGuideTextContainer');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:75}).start(0,1);
		PropHelpGuideTextContainerStatus = 1;	
	}
	else if (PropHelpGuideBubbleStatus == 1 && PropHelpGuideTextContainerStatus == 0){
		var ElementFader = $('PropHelpGuideTextContainer');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:75}).start(0,1);
		PropHelpGuideTextContainerStatus = 1;	
	}	
	
	return true;	
}

function HideDropDownsPropNumber()
{
	if (window.ie6){
		if ($chk($('Index_IO_Rotation'))){
			$('Index_IO_Rotation').setStyle('visibility', 'hidden');
		}	
		if ($chk($('Index_Part_Rotation'))){
			$('Index_Part_Rotation').setStyle('visibility', 'hidden');
		}
	}
}

function ShowDropDownsPropNumber()
{
	if (window.ie6){
		if ($chk($('Index_IO_Rotation'))){
			$('Index_IO_Rotation').setStyle('visibility', 'visible');
		}
		if ($chk($('Index_Part_Rotation'))){
			$('Index_Part_Rotation').setStyle('visibility', 'visible');
		}
	}
}


// 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;
		CurrentVisiblePropHelpGuideText = '';
		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;
}


// PromoPopup

function PreventPromoPopupDestroy()
{
	PromoPopupBubbleSemaphore = 1; 
	return true;
}

function AllowPromoPopupDestroy()
{
	PromoPopupBubbleSemaphore = 0; 
	setTimeout('FadePromoPopupBubble(300)', 1);	
}

function ShowPromoPopupBubble()
{
	if (PromoPopupBubbleStatus == 1){
		return true;	
	}
	
	var BubbleTarget = $('PromoPopupBubbleContainer');
	BubbleTarget.removeClass('PromoPopupBubbleHidden');
	BubbleTarget.addClass('PromoPopupBubbleVisible');
	
	var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:250, transition: Fx.Transitions.Cubic.easeOut}).start(0,1);
	PromoPopupBubbleStatus = 1;	
	return true;	
}


function FadePromoPopupBubble(TransitionTime)
{
	if (PromoPopupBubbleStatus == 0){
		return true;	
	}
	
	if (PromoPopupBubbleSemaphore == 0){
		var BubbleTarget = $('PromoPopupBubbleContainer');
		var myFx = new Fx.Style(BubbleTarget, 'opacity', {duration:TransitionTime, transition: Fx.Transitions.Cubic.easeOut}).start(1,0);
		PromoPopupBubbleStatus = 0;
		setTimeout("HidePromoPopupBubble();", TransitionTime);
	}
	return true;
}

function HidePromoPopupBubble()
{
	$('PromoPopupBubbleClickPad').removeClass('PromoPopupBubbleVisible');
	$('PromoPopupBubbleClickPad').addClass('PromoPopupBubbleHidden');
	$('PageData').removeEvent('click');
	
	if (PromoPopupBubbleSemaphore == 0)
	{
		$('PromoPopupBubbleContainer').removeClass('PromoPopupBubbleVisible');
		$('PromoPopupBubbleContainer').addClass('PromoPopupBubbleHidden');
		$('PromoPopupBubbleContainer').setStyle('top', '-100px');
		CurrentVisiblePromoPopupText = '';
		PromoPopupBubbleStatus = 0;
		PreventPromoPopupDestroy();
		ShowDropDowns();
		
		return true;
	}
}

function HideDropDowns()
{
	if (window.ie6){
		if ($chk($('Index_IO_Manufacturer'))){
			$('Index_IO_Manufacturer').setStyle('visibility', 'hidden');
		}	
		if ($chk($('Index_IO_Rotation'))){
			$('Index_IO_Rotation').setStyle('visibility', 'hidden');
		}	
		if ($chk($('Index_Part_Manufacturer'))){
			$('Index_Part_Manufacturer').setStyle('visibility', 'hidden');
		}
		if ($chk($('Index_Part_Rotation'))){
			$('Index_Part_Rotation').setStyle('visibility', 'hidden');
		}
	}
}

function ShowDropDowns()
{
	if (window.ie6){
		if ($chk($('Index_IO_Manufacturer'))){
			$('Index_IO_Manufacturer').setStyle('visibility', 'visible');
		}	
		if ($chk($('Index_IO_Rotation'))){
			$('Index_IO_Rotation').setStyle('visibility', 'visible');
		}
		if ($chk($('Index_Part_Manufacturer'))){
			$('Index_Part_Manufacturer').setStyle('visibility', 'visible');
		}
		if ($chk($('Index_Part_Rotation'))){
			$('Index_Part_Rotation').setStyle('visibility', 'visible');
		}
	}
}

function ShowPromoPopup(CallingElement, PromoPopupToShow)
{
	if (PromoPopupToShow == ''){
		return false;
	}
	PreventPromoPopupDestroy();
	RealignPromoPopupBox(CallingElement);	
	SwitchPromoPopupText(PromoPopupToShow);
	
	HideDropDowns();
	
	return false;
}

function RealignPromoPopupBox(CallingElement)
{
	var Coords = $(CallingElement).getPosition();
	var WindowSize = document.body.clientWidth;
	var Scrolled = window.pageYOffset;
	var RightAdjust = 1;
	var TopAdjust = 13;
	
	if (typeof(Scrolled) == 'number' && Scrolled != 0){
		TopAdjust =  TopAdjust + Scrolled;
	}
	
	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-340)/3.5);	
	}
	
	$('PromoPopupBubbleContainer').setStyle('top', TopAdjust);
	$('PromoPopupBubbleContainer').setStyle('right', RightAdjust);
	return true;
}

function SwitchPromoPopupText(PromoPopupToShow)
{
	FadeInPromoPopupText();
}

function FadeInPromoPopupText()
{
	if (PromoPopupBubbleStatus == 0){
		ShowPromoPopupBubble();
		var ElementFader = $('PromoPopupTotalTextContainer');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:75}).start(0,1);
		PromoPopupTextContainerStatus = 1;	
	}
	else if (PromoPopupBubbleStatus == 1 && PromoPopupTextContainerStatus == 0){
		var ElementFader = $('PromoPopupTotalTextContainer');
		var myFx = new Fx.Style(ElementFader, 'opacity', {duration:75}).start(0,1);
		PromoPopupTextContainerStatus = 1;	
	}
	
	$('PromoPopupBubbleClickPad').removeClass('PromoPopupBubbleHidden');
	$('PromoPopupBubbleClickPad').addClass('PromoPopupBubbleVisible');
	$('PageData').addEvent('click', function(){setTimeout("AllowPromoPopupDestroy()", 50);});
	
	return true;	
}