
// Set IE6 to cache bkg images to prevent flashing
try { document.execCommand('BackgroundImageCache', false, true); } catch (e) { }

var mainMenuTabs = new Array("mainMenuTabHome", "mainMenuTabOptions", "mainMenuTabSizes", "mainMenuTabShowcase", "mainMenuTabFAQ", "mainMenuTabCoolStuff", "mainMenuTabHelp", "mainMenuTabOrder");
var mainMenuDropdowns = new Array(null, "ddlOptions", null, "ddlShowcase", "ddlFAQ", "ddlCool", null, "ddlOrder");
var mainMenuDropdownTimeouts = new Array(0, 0, 0, 0, 0, 0, 0, 0);

function selectMenu(tabSender, dontHighlightTab)
{
	// Get tab index
	var tabIndex = getMenuTabIndex(tabSender.id);

	if (dontHighlightTab == undefined)
	{
		// Set new style (if not sticky)
		if (tabSender.className.indexOf("sticky") == -1)
			tabSender.className = tabSender.className + "Selected";
	}
	
	// Set onmouseout to reset to normal
	tabSender.onmouseout = function()
	{
		if (tabSender.className.indexOf("sticky") == -1)
			tabSender.className = tabSender.className.replace("Selected", "");
		hideDropdown(mainMenuDropdowns[tabIndex]);
	}

	// Hide other dropdowns
	hideAllDropdowns();
	
	// Check for dropdown
	if (mainMenuDropdowns[tabIndex] == null) return;

	// Clear any timeout associated
	cancelDropdownHiding(mainMenuDropdowns[tabIndex]);
	
	// Get this dropdown
	var ddl = document.getElementById(mainMenuDropdowns[tabIndex]);

	// Null? bail
	if (ddl == undefined || ddl == null) return;
	
	// Show dropdown
	ddl.style.display = "block";
	ddl.style.top = findPosY(tabSender) + 19;
	if (tabIndex == (mainMenuDropdowns.length - 1))
		ddl.style.left = findPosX(tabSender) - (ddl.clientWidth - tabSender.clientWidth);
	else
		ddl.style.left = findPosX(tabSender);	
}

function hideAllDropdowns()
{
	for (var i = 0; i < mainMenuDropdowns.length; i++)
	{
		var o = document.getElementById(mainMenuDropdowns[i]);
		if (o != null) o.style.display = "none";
	}
}

function hideDropdown(id)
{
	var index = getDropdownIndex(id);
	if (mainMenuDropdowns[index] == null) return;
	mainMenuDropdownTimeouts[index] = window.setTimeout("document.getElementById('" + id + "').style.display = 'none';", 1000);
}

function cancelDropdownHiding(id)
{
	var index = getDropdownIndex(id);
	var timeout = mainMenuDropdownTimeouts[index];
	if (timeout > 0) window.clearTimeout(mainMenuDropdownTimeouts[index]);
	mainMenuDropdownTimeouts[index] = 0;
}

function getMenuTabIndex(id)
{
	for (var i = 0; i < mainMenuTabs.length; i++)
		if (mainMenuTabs[i] == id) return i;
		
	return 0;
}

function getDropdownIndex(id)
{
	for (var i = 0; i < mainMenuDropdowns.length; i++)
		if (mainMenuDropdowns[i] == id) return i;
		
	return 0;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
		while (1)
	{
		curleft += obj.offsetLeft;
		if (!obj.offsetParent)
			break;
		obj = obj.offsetParent;
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
		while (1)
	{
		curtop += obj.offsetTop;
		if (!obj.offsetParent)
			break;
		obj = obj.offsetParent;
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}