

<div class="list">
{foreach $training_array as $training}
	{if 
	$training@first ||
	(
	$training_array[$training@index]->get_tr_date()|substr:5:2 != $training_array[$training@index-1]->get_tr_date()|substr:5:2 
	)
	
	}
	{if !$training@first && 
	$training_array[$training@index]->get_tr_date()|substr:5:2 != $training_array[$training@index-1]->get_tr_date()|substr:5:2
	}
	</div>
	{/if}
	<span onclick="block_action('block_{$training->get_tr_date()|substr:0:4}{$training->get_tr_date()|substr:5:2}');" class="date_separator clickable">{$training_array[$training@index]->get_tr_date()|substr:0:4}. 
		{$months[$training_array[$training@index]->get_tr_date()|substr:5:2]}
		<img src="/_image/open_folder.png">
	</span>
	<div id="block_{$training->get_tr_date()|substr:0:4}{$training->get_tr_date()|substr:5:2}" class="month_block">
	{/if}
	<a href="/admin/{if $edit=='edit'}edit_training{elseif $edit=='view'}trainings{else}presence{/if}/{$training->get_tr_id()}">
		<div class="list_item">
			<img src="/_image/training.png">
			{$training->get_tr_date()|substr:0:4}. 
			{$months[$training_array[$training@index]->get_tr_date()|substr:5:2]} 
			{$training->get_tr_date_day()}. 
			{$days[$training->get_tr_date_day_of_week()]} 
			{$training->get_tr_date_time()} 
			{if $training->get_tr_training_type_trt_id()}({$training->get_tr_type_name_by_id()}){/if}
		</div>
	</a>
	{if $training@last}
	</div>
	{/if}
{/foreach}

</div>

<script>

function open_block(block_id) {
	$("#"+block_id).slideDown("slow");
}

function close_block(block_id) {
	$("#"+block_id).slideUp("slow");
}

function block_action(block_id) {
	if ($("#"+block_id).is(':hidden')) {
		open_block(block_id);
	}
	else {
		close_block(block_id);
	}
}


$( document ).ready(function() {
    var divs = $( "div[class=month_block]" );
	$( ".list" ).find( divs ).hide();
	var div_list = $( ".list" ).find( divs );

	open_block(div_list[0].id);
	
});


</script>