/**
 * @author Vlad Yakovlev (scorpix@design.ru)
 * @copyright Art.Lebedev Studio (http://www.artlebedev.ru)
 * @version 0.1 (27.03.2009)
 * @requires jQuery
 */
$(function() {
	var rootBlock = $('#main_content .questions');

	var linkAll = rootBlock.find('.section_links .all');

	var links = rootBlock.find('.section_links .item').not('.all');

	var sections = rootBlock.find('.section');

	curIndex = -1;

	init();

	function init() {
		linkAll.addClass('selected');

		linkAll.click(function() {
			change(-1);
		});
		links.each(function(index) {
			$(this).click(function() {
				change(index);
			});
		});
	}

	function change(index) {
		if (index == curIndex) {
			return;
		}

		links.removeClass('selected');
		linkAll.removeClass('selected');

		if (-1 == index) {
			sections.removeClass('hidden');
			linkAll.addClass('selected');
		} else {
			sections.addClass('hidden');
			sections.eq(index).removeClass('hidden');
			links.eq(index).addClass('selected');
		}

		curIndex = index;
	}
});