﻿/************
DOM Ready Code
************/

$(function ()
{
	//Add hoverIntent functionality to hotSpots. Controls everything but tooltip
	$("#divHotSpot_1").hoverIntent(hoverIntentConfig)
	$("#divHotSpot_2").hoverIntent(hoverIntentConfig)
	$("#divHotSpot_3").hoverIntent(hoverIntentConfig)
	$("#divInstruction").hoverIntent(hoverIntentConfig)

	$("#divHotSpot_4").hoverIntent(hoverIntentConfig).click(function ()
	{
		window.location = 'SalesExecutives.aspx?Source=Bubble';
	});

	//Add tooltips to hot spots
	$("#divHotSpot_1").tooltip({ relative: true });
	$("#divHotSpot_2").tooltip({ relative: true });
	$("#divHotSpot_3").tooltip({ relative: true });
	$("#divHotSpot_4").tooltip({ relative: true });

	//Set up cycle text
	$('#textCycle').cycle({
		cleartype: false,
		timeout: 20000
	});
});

/************
Global Variables
************/

var hoverIntentConfig = {
	timeout: 0, // number = milliseconds delay before onMouseOut    
	over: HotSpotHoverIn, // function = onMouseOver callback (REQUIRED)    
	out: HotSpotHoverOut, // function = onMouseOut callback (REQUIRED)
	interval: 250
};

var exposeConfig = {
	loadSpeed: 'normal',
	opacity: .6,
	color: "#000"
};

/************
Functions
************/

//Adjust zIndexes so arrows expose correctly
function AdjustZIndexForSingleArrow()
{
	var aryHotSpots = GetArrowArray();

	for (var i = 0; i < aryHotSpots.length; i++)
	{
		for (var i = 0; i < aryHotSpots.length; i++)
		{
			aryHotSpots[i].style.zIndex = "1";
		}
	}

	document.getElementById("divInstruction").style.zIndex = 1;
	document.getElementById("instruction-box").style.zIndex = 1;
}

//Reset zIndexes so arrows expose correctly
function ResetZIndexForSingleArrows()
{
	var aryHotSpots = GetArrowArray();

	for (var i = 0; i < aryHotSpots.length; i++)
	{
		aryHotSpots[i].style.zIndex = "";
	}

	document.getElementById("divInstruction").style.zIndex = "";
	document.getElementById("instruction-box").style.zIndex = "";
}

function HotSpotHoverIn()
{
	if ($(this).attr('id') == "divInstruction")
	{
		//HighlightArrows();
		ResetZIndexForSingleArrows();
		$(this).expose(exposeConfig);
	}
	else
	{
		AdjustZIndexForSingleArrow();
		$(this).expose(exposeConfig);
		$(this).show();
	}
}
function HotSpotHoverOut()
{
	if ($(this).attr('id') == "divInstruction")
	{
		//HighlightArrows();
	}
	else
	{
		ResetZIndexForSingleArrows();
	}

	$.mask.close();
}

function HighlightArrows()
{
	var aryHotSpots = GetArrowArray();

	for (var i = 0; i < aryHotSpots.length; i++)
	{
		if (aryHotSpots[i].style.backgroundImage.search("blue") != -1)
		{
			aryHotSpots[i].style.backgroundImage = "";
		}
		else
		{
			aryHotSpots[i].style.backgroundImage = "url('Assets/Images/small-arrow-blue.png')";
		}
	}
}

function GetArrowArray()
{
	var hotSpotCount = 4;
	var aryHotSpots = new Array();

	for (var i = 1; i <= hotSpotCount; i++)
	{
		aryHotSpots.push(document.getElementById("divHotSpot_" + i));
	}

	return aryHotSpots;
}
