var hide_timeout;
var data = new Array;
var max_lines = 18;
/*
function showmenu(catindex)
{
	freezemenu();
	c0 = document.getElementById('col0');
	c1 = document.getElementById('col1');
	c2 = document.getElementById('col2');
	c3 = document.getElementById('col3');
	var cols = new Array(c0, c1, c2, c3);
	for (i=0;i<4;i++)
	{
		cols[i].innerHTML = data[catindex][i];
	}
	a = document.getElementById('dropdown');
	a.style.display="block";
}
*/

function showmenu(catindex){
	setTimeout("showmenu_real('" + catindex + "');", 300);
}

function showmenu_real(catindex)
{
	freezemenu();
	c0 = document.getElementById('col0');
	c1 = document.getElementById('col1');
	c2 = document.getElementById('col2');
	c3 = document.getElementById('col3');
	var cols = new Array(c0, c1, c2, c3);
	var line_counter = 0;
	var col_counter = 0;
	var current_col_html = '';
	
	if (!data[catindex]['menu'][0]['header'])
		return;
	
	if (!show_separate(catindex))
	{
		
		for (i = 0; data[catindex]['menu'][i]; i++)
		{
			if (col_counter >= 4)
			{
				break;
			}
			++line_counter;
			if (line_counter <= data[catindex]['max_lines'])
			{
				current_col_html = current_col_html + data[catindex]['menu'][i]['header'];
			}
			else
			{
				cols[col_counter].innerHTML = current_col_html;
				col_counter++;
				current_col_html = '';				
				line_counter = 0;
				if (col_counter >= 4)
				{
					break;
				}
				i -= 1;
				continue;
			}
			for (j = 0; data[catindex]['menu'][i][j]; j++)
			{
				++line_counter;
				if (line_counter <= data[catindex]['max_lines'])
				{
					current_col_html = current_col_html + data[catindex]['menu'][i][j];
				}
				else
				{
					cols[col_counter].innerHTML = current_col_html;
					col_counter++;
					current_col_html = '';
					line_counter = 0;
					if (col_counter >= 4)
					{
						break;
					}
					j -= 1;
					continue;
				}
			}
		}
		
		if (col_counter <= 3)
		{
			cols[col_counter].innerHTML = current_col_html;
			col_counter++;
		}
		for (k = col_counter; k < 4; k++)
		{
			cols[k].innerHTML = '&nbsp;';
		}
		
		/*
		for (i = 0; data[catindex]['menu'][i]; i++)
		{
			current_col_html = current_col_html + data[catindex]['menu'][i]['header'];
			for (j = 0; data[catindex]['menu'][i][j]; j++)
			{
				current_col_html = current_col_html + data[catindex]['menu'][i][j];
			}
			alert(current_col_html);
			cols[col_counter].innerHTML = current_col_html;
			if (col_counter == 3)
			{
				break;
			}
			++col_counter;
			current_col_html = '';
		}
		*/
	}
	else
	{
		//show each cat separately...
		for (i=0; data[catindex]['menu'][i]; i++)
		{
			current_col_html = current_col_html + data[catindex]['menu'][i]['header'];
			for (j = 0; data[catindex]['menu'][i][j]; j++)
			{
				current_col_html = current_col_html + data[catindex]['menu'][i][j];
			}
			cols[col_counter++].innerHTML = current_col_html;
			current_col_html = '';
		}
	}
	a = document.getElementById('dropdown');
	a.style.display="block";
}

function hidemenu()
{
	hide_timeout = setTimeout("hidemenu_helper()", 900);
}
function hidemenu_helper()
{
	a = document.getElementById('dropdown');
	a.style.display="none";
	freezemenu();
}
function freezemenu()
{
	clearTimeout(hide_timeout);
}
function show_separate(catindex)
{
	if (data[catindex]['menu'].length > 4)
	{
		return false;
	}
	//now go thru all of the subcats and check their lengths	
	for (i=0; i<data[catindex]['menu'].length; i++)
	{
		if (data[catindex]['menu'][i].length > max_lines - 1)
		{
			return false;
		}
	}
	return true;
}

function doOnLoad()
{
//	tbl_cats = document.getElementById('TabBar');
//	tbl_dropdown = document.getElementById('dropdown');
//	tbl_dropdown.style.top = (tbl_cats.offsetHeight + tbl_cats.offsetTop) + "px";
}

