// JavaScript Document
var browser = "IE";
var link_tabs_width = 0;
var first_submenu_offset = 0;
//var activeTabs = Array();
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			if (oldonload)
			{
				oldonload();
			}
			func();
		}
	}
}


function formattabs()
{
	var tabs = getElementsByClass("cattab");
	for (var i=0; i<tabs.length; i++)
	{
		tabs[i].onmouseover = highlightme;
		tabs[i].onmouseout = unhighlightme;
	}
}

function highlightme()
{
	for (var i=0; i<this.childNodes.length; i++)
	{
		this.childNodes[i].style.color = "#FFFFFF";
	}
}

function unhighlightme()
{
	for (var i=0; i<this.childNodes.length; i++)
	{
		this.childNodes[i].style.color = "#000000";
	}
}

function showSubMenu()
{
	var this_pos = findPos(this);
	var this_id = this.id.substr(11,this.id.length);
	var browserOffset = 0;
	var this_submenu = document.getElementById("submenu_"+this_id);
	if (this_submenu.style.display=="")
		return;
	
	try
	{
		this.style.background = "url('http://www.wholesalechess.com/images/gradient_background2.jpg')";
		this.style.color = "#FFFFFF";
		
		var left_position = this_pos[0];
		var this_width = parseInt(this_submenu.style.width);
		//self.status = left_position - first_submenu_offset + this_width;
		if (left_position - first_submenu_offset + this_width > link_tabs_width)
		{
			left_position -= (left_position - first_submenu_offset + this_width) - link_tabs_width + 1;
		}
		this_submenu.style.left = left_position+"px";
		var top_position = this_pos[1] + this.offsetHeight + browserOffset;
		this_submenu.style.top = top_position+"px";
		//this_submenu.style.color = "#000000";
		this_submenu.style.display = "";
	}
	catch (e)
	{
		//nothing
	}
}

function hideSubMenu()
{
	//var posX = findPosX(this);
	//var posY = findPosY(this);
	var this_id = this.id.substr(11,this.id.length);
	//if (activeTabs[this_id] == "Y")
	//	return;
	try
	{
		var this_submenu = document.getElementById("submenu_"+this_id);
		if (browser=="IE")
		{
			this.style.background = "url('/images/gradient_background.jpg')";
			this.style.color = "#000000";
		}
		this_submenu.style.display = "none";
	}
	catch (e)
	{
		//tab is active, ignore request to hide it
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}


function getElementsByClass(searchClass,node,tag)
{
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
