/**
 * @author Vlad Yakovlev (scorpix@design.ru)
 * @copyright Art.Lebedev Studio (http://www.artlebedev.ru)
 */
$(function() {
	var root = $('#main_content');

	var years  = root.find('.years .year');

	var sections = root.find('.events');

	var curIndex = -1;

	init();

	function init() {
		root.find('.years').removeClass('hidden');
		root.find('h2').addClass('hidden');

		sections.addClass('hidden');

		changeSection(0);

		root.find('.years .year .pseudo_link').each(function(index) {
			$(this).click(function() {
				index == curIndex || changeSection(index);
			});
		});
	}

	function changeSection(index) {
		if (-1 < curIndex) {
			years.eq(curIndex).removeClass('selected');
			sections.eq(curIndex).addClass('hidden');
		}

		curIndex = index;

		years.eq(curIndex).addClass('selected');
		sections.eq(curIndex).removeClass('hidden');
	}
});
