function closeBlock(link, block, childBlock) {	
	$.cookie(block.attr('id'), 'gui_closed', { expires: 365, path: '/' });	
	link.addClass('gui_closed');
	deltaH = -childBlock.outerHeight();
	childBlock.hide('blind', 500);
	setTimeout('parent.boxAdjustSize(' + deltaH + ')', 800);
}

function openBlock(link, block, childBlock) {
	$.cookie(block.attr('id'), null, { expires: 365, path: '/' });	
	link.removeClass('gui_closed');
	deltaH = childBlock.outerHeight();
	childBlock.show('blind', 500);	
	setTimeout('parent.boxAdjustSize(' + deltaH + ')', 800);
}

$(function() {
	
	/* ---> ????
	if ($.trim($('.contextual_elements').html()) == '') {
		$('.contextual_elements').prepend($('#gui_synthetique'));
	}
	*/	
	
	$('.contextual_elements .gui_collapsible .gui_legend').click(function() {
		var block = $(this).parents('.gui_box');
		var childBlock = $('.gui_content', block);
		if (childBlock && childBlock.css('display') == 'none') {
			openBlock($(this), block, childBlock);			
		} else {
			closeBlock($(this), block, childBlock);			
		}		
		return false;	
	});
	
	$('.contextual_elements .gui_collapsible .gui_legend').each(function() {
		var block = $(this).parents('.gui_box');
		if (block)
		{		
			try
			{
			   if ($.cookie(block.attr('id'))) {
				$('.gui_legend', block).addClass('gui_closed');
				$('.gui_content', block).hide(0);				
			   }			   			
			}
			catch (ex)
			{				
			}
		}		
	});
});
