/**
 * @author Vlad Yakovlev (scorpix@design.ru)
 * @copyright Art.Lebedev Studio (http://www.artlebedev.ru)
 * @requires jQuery 1.2.6
 */
$(function() {
	var els = [];

	$('#main_content .prices').each(function() {
		els.push({
			isSelected: false,
			sections: $(this).find('.prices_section'),
			changer: $(this).find('.changer input')
		});

		var index = els.length - 1;
		var el = els[index];

		if (el.changer.attr('checked')) {
			changeSection(index);
		}

		el.changer.click(function() {
			changeSection(index);
		});
	});

	function changeSection(index) {
		var el = els[index];

		if (el.isSelected) {
			el.sections.eq(0).removeClass('jhidden');
			el.sections.eq(1).addClass('jhidden');
		} else {
			el.sections.eq(0).addClass('jhidden');
			el.sections.eq(1).removeClass('jhidden');
		}

		el.isSelected = !el.isSelected;
	}
	
	first_par = location.href.split('?')[1]
	if (first_par=='?ops=1') {
		$('#main_content .prices').find('.changer input').click();
	}
});

$(function() {
	var objects = [];

	var curSection = -1;
	
	init($('#main_content'));
	
	function init(root) {
	
		root.find('.sub_types').removeClass('hidden');

		var types = root.find('.sub_types li');
		var sections = root.find('.sections .section');

		if (!types.size()) {
			return;
		}

		types.each(function(index) {
			var link = $(this).find('.pseudo_link');
			var section = sections.eq(index);

			objects.push({
				link: $(this),
				section: section
			});

			if ($(this).hasClass('selected')) {
				curSection = index;
			}

			link.click(function() {
				if (curSection == index) {
					return;
				}

				openSection(index);
			});
		});
	}

	function openSection(index) {
		if (-1 < curSection) {
			objects[curSection].link.removeClass('selected');
			objects[curSection].section.addClass('jhidden');
		}

		curSection = index;

		objects[curSection].link.addClass('selected');
		objects[curSection].section.removeClass('jhidden');
	}
});