/*
	Context menu script file
*/

/* Global Variables */
var _productCategoryCount;
var _productMenuTimer;

/* Event Handlers */
function productCategoryCell_over(cell)
{
	// Get the index of the category representing this cell
	var cellIndex = cell.id.replace("productCategoryCell_", "");
	
	// RenderMenus
	displayProductCategoryMenu(cellIndex);
	
	// Clear the timer
	clearProductCategoryMenuTimer();
}

function productCategoryCell_out(cell)
{
	// Set the timer
	setProductCategoryMenuTimer();
}

function productCategoryMenuCell_over(cell)
{
	cell.style.backgroundColor = "#FF6600";
}

function productCategoryMenuCell_out(cell)
{
	cell.style.backgroundColor = "#01A8FF";
}

function productCategoryMenu_over(menu)
{
	// Clear the timer
	clearProductCategoryMenuTimer();
}

function productCategoryMenu_out(menu)
{
	// Set the timer
	setProductCategoryMenuTimer();
}

function contextCell_over(cell)
{
	changeContextCell("over", cell);
}

function contextCell_out(cell)
{
	changeContextCell("out", cell);
}

/* Methods */
function displayProductCategoryMenu(menuIndex)
{
	// Hide all menus except for menuIndex menu
	for (var i = 0; i < _productCategoryCount; i++)
	{
		var menu = document.getElementById("productCategoryMenu_" + i);
		var cell = document.getElementById("productCategoryCell_" + i);
		
		if (menu != null)
		{
			if (i == menuIndex)
			{
				menu.style.display = "block";
				changeContextCell("over", cell);
			}
			else
			{
				menu.style.display = "none";
				changeContextCell("out", cell);
			}
		}
	}
}

function changeContextCell(state, cell)
{
	if (state == "over")
	{
		cell.style.backgroundImage = "url(http://www.chyron.com/images/contextmenu_cell_over.gif)";
	}
	else
	{
		cell.style.backgroundImage = "url(http://www.chyron.com/images/contextmenu_cell_out.gif)";
	}
}

function setProductCategoryMenuTimer()
{
	_productMenuTimer = setTimeout("displayProductCategoryMenu(-1)", 100);
}

function clearProductCategoryMenuTimer()
{
	clearTimeout(_productMenuTimer);
}


