
	function mm(item) {
		var self = this;
		this.item = $(item);
		this.selected = "item_s_"+$(item).attr('class').match(/\d+/);
		this.sub = this.item.find(".submenu");
		this.time = 0;
		this.item.mouseover(function(){self.over()});
		this.item.mouseout (function(){self.outtimer()});
	}
	mm.prototype.over = function() {
		clearTimeout(this.time);
		this.item.addClass(this.selected);
		this.sub.show(100);
	}
	mm.prototype.outtimer = function(){
		var self = this;
		this.time = setTimeout(function(){self.out()}, 100);
	}
	mm.prototype.out = function() {
		this.item.removeClass(this.selected);
		this.sub.hide(100);
	}
	
	ms_open = false;
	function ms(item) {
		var self = this;
		this.item = $(item);
		this.selected = "item_s_"+$(item).attr('class').match(/\d+/);
		this.sub = this.item.find(".submenu");
		this.time = 0;
		if (this.item.is('.selected')) this.open();
		this.item.find('p').click (function(){self.open(); return false;});
	}
	ms.prototype.open = function() {
		if(ms_open) {
			if(ms_open === this) return false;
			ms_open.close();
		}
		ms_open = this;
		this.item.addClass(this.selected);
		this.sub.show(200);
	}
	ms.prototype.close = function() {
		this.item.removeClass(this.selected);
		this.sub.hide(200);
	}
	
	var r={};
	r.proc=function(){
		if (!r.obj) r.obj = $('#bg_table .center');
		if(r.obj.width()>=1300) r.obj.width('1300px');
		else r.obj.css({width: ''});
	}
	
	var prof = function(){
		var items = $('.professions .item');
		var abc = $('<div class="abc"></div>');
		var item, a=new Array(), show;
		
		if (items.length<1) return false;
		for(var i=0;i<items.length;i++){
			items[i] = $(items[i]);
			a[i] = $('<a href="#">'+items[i].find("input").val()+'</a>');
			a[i][0].i = i;
			abc.append(a[i]);
		}
		show = 0;
		items[show].show();
		a[show].addClass('selected');
		$('.professions').prepend(abc);
		$('.professions .abc a').click(function(){
			if(this.i==show) return false;
			a[this.i].addClass('selected');
			a[show].removeClass('selected');
			items[show].hide(100);
			items[this.i].show(400);
			show=this.i;
			return false;
		});
	}
	
	/* form checker */
	function checker (form) {
		var checks = $(form).find(".check_isset, .check_mail, .check_phone"), obj, i, j, isset, bg;
		for (i=0 ; i<checks.length ; i++){
			isset=0;
			obj=$(checks[i]);
			inps = obj.find("select, input");
			for (j=0 ; j<inps.length ; j++){
				if (inps[j].nodeName.toLowerCase() == "select" && inps[j].value) isset=1; 
				if (inps[j].nodeName.toLowerCase() == "input" && inps[j].type == "text"){
					if (obj.is(".check_isset") && inps[j].value) isset=1;
					if (obj.is(".check_mail")  && inps[j].value && inps[j].value.match(/^[a-zA-Z0-9\-_.+]+\@[a-zA-Z0-9.]+\.[a-zA-Z]{2,4}$/i)) isset=1;
					if (obj.is(".check_phone") && inps[j].value && inps[j].value.match(/^[+\-\s0-9]+$/)) isset=1;
				}
				if (inps[j].nodeName.toLowerCase() == "input" && inps[j].type == "radio" && inps[j].checked) isset=1;
			}
			if (isset==0) {
				alert(obj.find(".error").text());
				inps[0].focus();
				return false;
			}
		}
	}
$(function(){
	var menus = $("#menu .item");
	for (var i=0 ; i<menus.length ; i++){
		menus[i].obj = new mm(menus[i]); 
	}
	
	var menus = $("#menu_sub .item");
	for (var i=0 ; i<menus.length ; i++){
		menus[i].obj = new ms(menus[i]);
	}
	
	$(".faq_cat input[type=button]").toggle(
		function() {$(this).parents("form").find(".cat").show(300); this.value="Скрыть результаты"},
		function() {$(this).parents("form").find(".cat").hide(300); this.value="Посмотреть результаты"}
	);
	
	r.proc();
	$(window).resize(r.proc);
	
	$('.faq .open').toggle(
		function() {
			$(this).parents(".faq").find('.answer').show("fast");
		},
		function() {
			$(this).parents(".faq").find('.answer').hide("fast");
		}
	);
	
	prof();
});
