var tb_selected = null;
var tb_container = null;
var tb_ppr = 400;
var tb_timeout = 10;
var tb_scroll = 0;
var tb_scrollheight = 0;
var tb_height = 360;
var tb_timer = null;

function tb_init(item_count, item_id_prefix, container_id)
{
	var height = (item_count - 1) * 5;
	for(var i = 0; i < item_count; i++)
	{
		height += ((_$(item_id_prefix + i).getAttribute('height') == 0) ? _$(item_id_prefix + i).getAttribute('height', 2) : _$(item_id_prefix + i).getAttribute('height')).toInt();
		$(item_id_prefix + i).setOpacity(0.7);
	}

	tb_container = _$(container_id);
	tb_scrollheight = height;
}

function tb_item_over(obj)
{
	if(tb_selected != obj) $(obj.id).fade(1.0);
}

function tb_item_out(obj)
{
	if(tb_selected != obj) $(obj.id).fade(0.7);
}

function tb_item_click(obj, pid)
{
	if(tb_selected != null) $(obj.id).fade(0.7);
	$(obj.id).fade(1.0);
	tb_selected = obj;

	_set('project', pid);
}

function tb_scrolldown()
{
	tb_scroll += tb_ppr / (1000 / tb_timeout);
	tb_scroll = (tb_scroll > (tb_scrollheight - tb_height)) ? (tb_scrollheight - tb_height) : tb_scroll;
	tb_container.scrollTop = tb_scroll;
	if(tb_scroll < (tb_scrollheight - tb_height)) tb_timer = window.setTimeout(tb_scrolldown, tb_timeout);
}

function tb_stop_scrolldown()
{
	if(tb_timer != null)
	{
		window.clearTimeout(tb_timer);
		tb_timer = null;
	}
}

function tb_scrollup()
{
	tb_scroll -= tb_ppr / (1000 / tb_timeout);
	tb_container.scrollTop = tb_scroll = (tb_scroll < 0) ? 0 : tb_scroll;
	if(tb_scroll > 0) tb_timer = window.setTimeout(tb_scrollup, tb_timeout);
}

function tb_stop_scrollup()
{
	if(tb_timer != null)
	{
		window.clearTimeout(tb_timer);
		tb_timer = null;
	}
}
