
Table_Cnt = 8;

Table_Top = new Array();
Subtable_Array = new Array();
Subtable_Top = new Array();
Subtable_Height = new Array();


Table_Top[0] = 140;
Table_Top[1] = 175;
Table_Top[2] = 210;
Table_Top[3] = 245;
Table_Top[4] = 280;
Table_Top[5] = 315;
Table_Top[6] = 350;
Table_Top[7] = 360;

Subtable_Array[0] = "null";
Subtable_Array[1] = "sub_1";
Subtable_Array[2] = "sub_2";
Subtable_Array[3] = "sub_3";
Subtable_Array[4] = "sub_4";
Subtable_Array[5] = "null";
Subtable_Array[6] = "null";
Subtable_Array[7] = "null";

Subtable_Top[0] = 0;
Subtable_Top[1] = 210;
Subtable_Top[2] = 245;
Subtable_Top[3] = 280;
Subtable_Top[4] = 315;
Subtable_Top[5] = 0;
Subtable_Top[6] = 0;
Subtable_Top[7] = 0;

Subtable_Height[0] = 0;
Subtable_Height[1] = 135;
Subtable_Height[2] = 160;
Subtable_Height[3] = 200;
Subtable_Height[4] = 95;
Subtable_Height[5] = 0;
Subtable_Height[6] = 0;
Subtable_Height[7] = 0;




//START: TIMER STUFF
var timer = new Object();
var lock_functions = false;
var Speed = 13;
var next_table = -1;



function Activate_Table(active_index)
{
	if(!lock_functions)
	{
		found_open_table = false;
		
		for(i=1; i<5; i++)
		{
			if(document.getElementById("sub_" + i).style.visibility == "visible" && i != active_index)
			{
				document.getElementById("td_" + active_index).className = "out";
				Prep_Table(i);
				next_table = active_index;
				found_open_table = true;
			}
		}
		
		if(!found_open_table)
		{
			Prep_Table(active_index);
		}
	}
}


function Prep_Table(index)
{
	if(!lock_functions)
	{
		INDEX = index;
		OVERLAY = document.getElementById("overlay_" + INDEX);
		OFFSET = 0;
		DIRECTION = 1;
		
		TARGET_HEIGHT = 0;
		TARGET_TOP = Subtable_Top[INDEX] + Subtable_Height[INDEX];
		
		OVERLAY.style.visibility = "visible";
		document.getElementById("sub_" + INDEX).style.visibility = "visible";
		
		if(OVERLAY.style.height == "0px")
		{
			TARGET_HEIGHT = Subtable_Height[INDEX];
			TARGET_TOP = Subtable_Top[INDEX];
			DIRECTION = -1;
		}
	
		if(DIRECTION == 1)
		{
			document.getElementById("td_" + INDEX).className = "s_over";
		}
		else
		{
			document.getElementById("td_" + INDEX).className = "out";
		}
		
		lock_functions = true;
		
		Expand_Table();
	}
}




function Expand_Table()
{
	
		
	if(DIRECTION == 1)
	{		
		OFFSET += Speed;
		
		current_height = Subtable_Height[INDEX] - OFFSET;
		current_top = Subtable_Top[INDEX] + OFFSET;
		
		
		if(current_height <= TARGET_HEIGHT)
		{
			OFFSET = Subtable_Height[INDEX];
			current_height = TARGET_HEIGHT;
			current_top = TARGET_TOP;			
		}
	
		OVERLAY.style.height = current_height + "px";
		OVERLAY.style.top = current_top + "px";
		
		for(i=INDEX+1; i<Table_Cnt; i++)
		{
			document.getElementById("cell_"+i).style.top = (Table_Top[i] + OFFSET) + "px";
		}
		
		if(current_height <= TARGET_HEIGHT + 0)
		{
			lock_functions = false;
		}
		else
		{
			Activate_Timer();
		}
	}
	
	else if(DIRECTION == -1)
	{
		OFFSET += Speed;
		
		current_height = OFFSET;
		current_top = Subtable_Top[INDEX] + Subtable_Height[INDEX] - OFFSET;
		
		
		if(current_height >= TARGET_HEIGHT)
		{
			OFFSET = Subtable_Height[INDEX];
			current_height = TARGET_HEIGHT;
			current_top = TARGET_TOP;			
		}
	
		OVERLAY.style.height = current_height + "px";
		OVERLAY.style.top = current_top + "px";
		
		for(i=INDEX+1; i<8; i++)
		{
			document.getElementById("cell_"+i).style.top = (Table_Top[i] + Subtable_Height[INDEX] - OFFSET) + "px";
		}
		
		if(current_height >= TARGET_HEIGHT)
		{
			OVERLAY.style.visibility = "hidden";
			document.getElementById("sub_" + INDEX).style.visibility = "hidden";
			lock_functions = false;
			
			if(next_table != -1)
			{
				table_index = next_table;
				next_table = -1;
				Prep_Table(table_index);
			}
			
			next_table = -1;
		}
		else
		{
			Activate_Timer();
		}
	}
}




function Activate_Timer()
{
	timer = window.setTimeout("Expand_Table();", 10);
}














function Activate_Subtable(index,over)
{
	subtable = document.getElementById("sub_" + index);
	document.getElementById("overlay_" + index).style.height = "0px";
	
	if(subtable.style.visibility == "hidden")
	{		
		for(i=0; i<Subtable_Array.length; i++)
		{
			if(Subtable_Array[i] != "null")
			{
				document.getElementById(Subtable_Array[i]).style.visibility = "hidden";
				document.getElementById("td_" + i).className = "out";
			}
		}

		subtable.style.visibility = "visible";	
		
		document.getElementById("td_" + index).className = "s_over";
		
		for(i=0; i<Table_Cnt; i++)
		{	
			if(i <= index)
			{
				document.getElementById("cell_"+i).style.top = Table_Top[i] + "px";
			}
			else
			{
				document.getElementById("cell_"+i).style.top = (Table_Top[i]+Subtable_Height[index]) + "px";
			}
		}
	}

	else
	{
		subtable.style.visibility = "hidden";
		if(over == 1)
		{
			document.getElementById("td_" + index).className= "over";
		}
		else
		{
			document.getElementById("td_" + index).className= "out";
		}
		
			
		for(i=index; i<Table_Cnt; i++)
		{
			document.getElementById("cell_"+i).style.top = Table_Top[i] + "px";
		}
	}
}



function Update_Style(td, style)
{
	if(td.className == "out" || td.className == "over")
	{
		td.className = style;
	}
	else
	{
		td.className = "s_" + style;
	}

}


function Update_Sub_Style(td, style)
{	
	if(td.className == "out2" || td.className == "over2")
	{
		td.className = style;
	}
	else
	{
		td.className = "s_" + style;
	}
}


function Highlight_Page(cell,page)
{
	document.getElementById("page_"+cell+page).className = "s_out2";
}


