//-- check if anything is open
//    -- check if already open 
//        -- ifopen then close it
//        -- return true;   
//    -- else 
//        -- then open selected
//        -- close the one that's currently open
//-- else
//	-- open the selected element

var attr = "";
var attr2 = "";

function animate_table(id){
	

	
	var selected = 'historical_table_'+id;
	var current_open = YAHOO.util.Dom.getElementsByClassName('current');
	
	
	
	if (current_open.length==0)
	{
	// if current_open == nothing 
		open_table(selected);
	} else {
		//if an element does == current
		//check if the current one open == the one selected
		if (YAHOO.util.Dom.hasClass(selected, 'current')){
			//if they are the same, then close it.
			close_table(selected);
			
		} else {
			//if they arn't the same, then open selected and close current_open
			open_table(selected, current_open[0].id);
			}
		}		
	}




function open_table(id, closeId)
{

	switch(id)
	{
		case 'historical_table_1': case 'historical_table_3': case 'historical_table_4': case 'historical_table_5': case 'historical_table_6': case 'historical_table_8': case 'historical_table_10': case 'historical_table_11':
			attr = {height: { from:18 ,to: 350 }};
			break;
		default:
			attr = {height: { from:18 ,to: 670 }};
	}

		var myAnim = new YAHOO.util.Anim(id, attr, 1, YAHOO.util.Easing.easeOut);
		if (closeId){ myAnim.onComplete.subscribe(function() {close_table(closeId);})}
		myAnim.animate();
		
		YAHOO.util.Dom.addClass(id, 'current');
}


function close_table(id2)
{
	switch(id2)
	{
		case 'historical_table_1': case 'historical_table_3': case 'historical_table_4': case 'historical_table_5': case 'historical_table_6': case 'historical_table_8': case 'historical_table_10': case 'historical_table_11':
			attr2 = {height: { from:310 ,to: 18 }};
			break;
		default:
			attr2 = {height: { from:620 ,to: 18 }};
	}
	
		var myAnim2 = new YAHOO.util.Anim(id2, attr2, 1, YAHOO.util.Easing.easeOut);
		myAnim2.animate();
		
		YAHOO.util.Dom.removeClass(id2, 'current');
	
}


