$(document).ready(function(){
	$("#ver_menu > li.root.has_childs > a").click(function(){
		var result = $(this).parent().toggleClass("parent_active");
		if ($(this).parent().hasClass('parent_active')){
			$(this).parent().find("ul").slideDown("slow");
		}else{
			$(this).parent().find("ul").slideUp("slow");
		}
		return false;
	});
	
	$("#sortImg").click(
		function(){
			if ($("#sortOrder").val() == "asc"){
				$("#sortOrder").val("desc");
				$(this).attr("src", "/images/sort_desc.png").attr("alt", "По убыванию");
			}else{
				$("#sortOrder").val("asc");
				$(this).attr("src", "/images/sort_asc.png").attr("alt", "По возрастанию");
			}
		}
	);
	
	$("#question_submit").click(function(){
		$(".question_responce").html("");
		var data = $("#question_form").serializeArray();
		
		$.ajax({ type: "post", dataType: "json", url: "/question.php", data: data, success: function(data){
			
			if (data.success == 1) {
				$("#question_form").hide();
				$("#question_form .u_f").val("");
				$(".open_question_form").click(function(){return false;});
			}else{
				$("#captcha_sid").val(data.capcode);
				$("#cap_img").attr("src", '/bitrix/tools/captcha.php?captcha_sid='+data.capcode);
				$("#captcha_word").val("");
			}
			$(data.messages).each(function(){$(".question_responce").append(this.toString())});
			$("#fancy_loading").hide();
		},
		beforeSend:function(){
			$.fn.fancybox.showLoading();
		}});
		return false;
	});
	
	$(".open_question_form").click(function(){$(".question_area").toggle("slow"); return false;});
	$(".fancy").fancybox();
	$(".childitem-selected").parent().find('li.root').click();
	$(".description table tr:nth-child(2n+1)").addClass("even");
});