function toggleBranch(cid, options)
{
	var expand = $(cid+'_control').hasClass('expanded');
	if ($type(options) && $type(options.force))
		expand = options.force;

	if (!expand)
	{
		$(cid).removeClass('hidden');
		$(cid+'_control').addClass('expanded');
		$(cid+'_control').getFirst().src = '/resources/images/tree_collapse.gif';
		Cookie.set(cid + '_expanded', 1, {path: '/', duration: 1});
	}
	else
	{
		$(cid).addClass('hidden');
		$(cid+'_control').removeClass('expanded');
		$(cid+'_control').getFirst().src = '/resources/images/tree_expand.gif';
		Cookie.set(cid + '_expanded', 0, {path: '/', duration: 1});
	}

	return false;
}

function toggleTree()
{
	$('catalog').getElements('a.tree_control').each(function(element){
		toggleBranch(element.id.replace('_control', ''), {force: false});
	});

	// var expand = $(document).getElement('p a.catalog_expand').hasClass('expand');
	// var forceValue = expand;
	// 
	// $('catalog').getElements('a.tree_control').each(function(element){
	// 	toggleBranch(element.id.replace('_control', ''), {force: forceValue});
	// });
	// 
	// if (expand)
	// {
	// 	$(document).getElements('p a.catalog_expand').each(function(element){
	// 		element.removeClass('expand');
	// 		element.innerHTML = 'Свернуть каталог';
	// 	});
	// } else
	// {
	// 	$(document).getElements('p a.catalog_expand').each(function(element){
	// 		element.addClass('expand');
	// 		element.innerHTML = 'Развернуть каталог';
	// 	});
	// 
	// }
}

function unToggleTree()
{
	$('catalog').getElements('a.level2').each(function(element){
		toggleBranch(element.id.replace('_control', ''), {force: true});
	});

}
