var collapse_timer = new Array();
var delay = 50;
var expanding = new Array();
var step = 20;

function px_to_int( value )
{
	value = value.substr( 0, ( value.length - 2 ) );
	if ( value == '' ) return 0; // if none set yet, return "0"
	
	return parseInt( value );
}

function get_submenu_height( menu_id )
{
	current_height = px_to_int( document.getElementById( menu_id + "_submenu" ).style['height'] ); // get current height
	
	return current_height;
}

function expand_init( menu_id, desired_height )
{
	if ( collapse_timer[menu_id] ) clearTimeout( collapse_timer[menu_id] );
	
	expanding[menu_id] = true;
	menu_expand( menu_id, desired_height );
}

function menu_expand( menu_id, desired_height )
{
	if ( expanding[menu_id] == true )
	{
		current_height = get_submenu_height( menu_id );
		
		if ( current_height < desired_height )
		{
			current_height += step;
			document.getElementById( menu_id + "_submenu" ).style['height'] = current_height + 'px';
			setTimeout( "menu_expand( '" + menu_id + "', " + desired_height + " );", delay );
		}
	}
}

function collapse_countdown( menu_id )
{
	collapse_timer[menu_id] = setTimeout( "menu_collapse( '" + menu_id + "' );", 50 );
}

function menu_collapse( menu_id )
{
	expanding[menu_id] = false;
	document.getElementById( menu_id + "_submenu" ).style['height'] = '0px';
}

