$.fn.to_object = function(){
	var result=new Object();
	$(this).find('input,textarea').each(function(){
		var name=jQuery.trim($(this).attr('name'));
		if(name!=''){
			result[name]=$(this).val();
		}
	});
	return result;
}

/*$.fn.validate = function(){
	var errclass='error';
	
	result=true;
	$(this).find('input[required=required],textarea[required=required]').each(function(){
		console.log($(this).attr('type'));
		if(jQuery.trim($(this).val())==''){
			switch($(this).attr('type')){
				case 'digit_field':
					break;
				case 'float_field':
					break;
				case 'text_field':
					break;
				case 'ru_text_field':
					break;
				case 'phone':
					break;
				case 'email':
					break;
				case 'ru_name':
					break;
				default:
			}
		} else {
			switch($(this).attr('type')){
								case 'digit_field':
					break;
				case 'float_field':
					break;
				case 'text_field':
					break;
				case 'ru_text_field':
					break;
				case 'phone':
					break;
				case 'email':
					break;
				case 'ru_name':
					break;
				default:
			}
		}
	});
	
	return result;
}*/

_.mixin(_.string.exports());

var sss = 0;
var busy = 0;
var default_animat = 1;
var MyTimer;
var close_timer;
var current_image_src = '';


$(document).ready(function(){

	$("a.highslide").bind("click",function(){
		return hs.expand(this);
	});

	$("div.item_description_box_left a.thumbnail").click(function(){
		current_image_src = $(this).children("span").text();
		$("div.description_image a > img").stop(true,true);
		$("div.description_image a > img").fadeOut(function(){
			$("div.description_image a").attr("href",current_image_src);
			$("div.description_image a > img").attr("src",'/p/image.html?path='+current_image_src+'&h=260" alt=""');
			$("div.description_image a > img").fadeIn();
		});	
		return false;
	});
	
	$("a.compare_link").click(function(){
		if($(this).hasClass("clicked")){
			return true;
		}
		else{
			$.get($(this).attr("href"));
			$(this).addClass("clicked");
			$(this).text("Уже в сравнении");
			// $.get($(this).attr("href"));
			//var old_compare_value = parseInt($("a.compare > b").text());
			//var new_compare_value = old_compare_value+1;
			// $("a.compare > b").text(new_compare_value);
			
			
			if($(this).hasClass("no_animation")){
				//$("a.compare > b").text(new_compare_value);
				$("a.compare > b").text(parseInt($("a.compare > b").text())+1);
				$("a.compare > b").animate({opacity: "0.1"},100);
				setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},200);
				setTimeout(function(){$("a.compare > b").animate({opacity: "0.1"},100);},400);
				setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},600);
			}
			else{
				var start_position = $("div.description_image").offset();
				var end_position = $("a.compare").offset();
				
				var element_copy = $("div.description_image").clone();
				element_copy.css("position","fixed");
				element_copy.css("z-index","9999999");
				element_copy.css("top",""+start_position.top-$(window).scrollTop()+"px");
				element_copy.css("left",""+start_position.left+"px");
				element_copy.css("border","none");
				element_copy.find("img").css("bottom","auto");
				
				obj=$("div.description_image");
				objw=$(obj).find("img:first").width();
				objh=$(obj).find("img:first").height();
				
				element_copy.find("img:first").css("width",objw+"px");
				element_copy.find("img:first").css("height",objh+"px");
				
				
				element_copy.find("img").eq(1).remove();
				element_copy.find("div.product_prop").css("display","none");
				element_copy.prependTo($("div.description_image").parent());
				
				//$("div.description_image").eq(0).find("img").animate({height: "hide"},1500);
				$("div.description_image").eq(0).find("img").animate({height: "20px", width:20*objw/objh+"px"},1100);
				$("div.description_image").eq(0).animate({top: "0", left: ""+end_position.left+""},1000,function(){
					$("div.description_image").eq(0).remove();
					$("a.compare > b").text(parseInt($("a.compare > b").text())+1);
					$("a.compare > b").animate({opacity: "0.1"},100);setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},200);
					setTimeout(function(){$("a.compare > b").animate({opacity: "0.1"},100);},400);
					setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},600);	
				});
			}
			
			return false;
		}
	});
	$("a.compare_link_small").click(function(){
		if($(this).hasClass("clicked")){
			$(this).removeClass("clicked");
			$(this).children("ins").text("+");
			$.get($(this).attr("href")+"&clear=current");
			//var old_compare_value = parseInt($("a.compare > b").text());
			//var new_compare_value = old_compare_value-1;
			
			if($(this).hasClass("no_animation")){
				$("a.compare > b").text(parseInt($("a.compare > b").text())-1);
				$("a.compare > b").animate({opacity: "0.1"},100);setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},200);
				setTimeout(function(){$("a.compare > b").animate({opacity: "0.1"},100);},400);
				setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},600);
			}
			else{			
				var end_position = $(this).parent().parent().children("div.image").offset();
				var start_position = $("a.compare").offset();
				
				var element_copy = $(this).parent().parent().children("div.image").clone();
				element_copy.css("position","fixed");
				element_copy.css("z-index","9999999");
				element_copy.css("top",""+start_position.top-$(window).scrollTop()+"px");
				element_copy.css("left",""+start_position.left+"px");
				element_copy.find("img").css("bottom","auto");
				element_copy.find("img").css("height","20px");			
				
				
				
				
				element_copy.find("div.product_prop").css("display","none");
				element_copy.prependTo($(this).parent().parent());
				
				$(this).parent().parent().children("div.image").eq(0).find("img").animate({height: "100%"},1000);
				$(this).parent().parent().children("div.image").eq(0).animate({top: ""+end_position.top-$(window).scrollTop()+"", left: ""+end_position.left+""},1000,function(){
					$(this).parent().children("div.image").eq(0).remove();
					$("a.compare > b").text(parseInt($("a.compare > b").text())-1);
					$("a.compare > b").animate({opacity: "0.1"},100);setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},200);
					setTimeout(function(){$("a.compare > b").animate({opacity: "0.1"},100);},400);
					setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},600);	
				});
			}
			return false;
		}
		else{			
			$(this).addClass("clicked");
			$(this).children("ins").text("-");
			$.get($(this).attr("href"));
			//var old_compare_value = parseInt($("a.compare > b").text());
			//var new_compare_value = old_compare_value+1;
			
			if($(this).hasClass("no_animation")){
				$("a.compare > b").text(parseInt($("a.compare > b").text())+1);
				$("a.compare > b").animate({opacity: "0.1"},100);setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},200);
				setTimeout(function(){$("a.compare > b").animate({opacity: "0.1"},100);},400);
				setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},600);
			}
			else{
				var start_position = $(this).parent().parent().children("div.image").offset();
				var end_position = $("a.compare").offset();
				
				var element_copy = $(this).parent().parent().children("div.image").clone();
				element_copy.css("position","fixed");
				element_copy.css("z-index","9999999");
				element_copy.css("top",""+start_position.top-$(window).scrollTop()+"px");
				element_copy.css("left",""+start_position.left+"px");
				element_copy.find("img").css("bottom","auto");
				
				obj=$(this).parent().parent().children("div.image");
				objw=$(obj).find("img:first").width();
				objh=$(obj).find("img:first").height();
				
				element_copy.find("img:first").css("width",objw+"px");
				element_copy.find("img:first").css("height",objh+"px");
				
				element_copy.find("div.product_prop").css("display","none");
				element_copy.prependTo($(this).parent().parent());
				
				//$(this).parent().parent().children("div.image").eq(0).find("img").animate({height: "hide"},1500);
				$(this).parent().parent().children("div.image").eq(0).find("img").animate({height: "20px", width:20*objw/objh+"px"},1100);
				$(this).parent().parent().children("div.image").eq(0).animate({top: "0", left: ""+end_position.left+""},1000,function(){
					$(this).parent().children("div.image").eq(0).remove();
					$("a.compare > b").text(parseInt($("a.compare > b").text())+1);
					$("a.compare > b").animate({opacity: "0.1"},100);setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},200);
					setTimeout(function(){$("a.compare > b").animate({opacity: "0.1"},100);},400);
					setTimeout(function(){$("a.compare > b").animate({opacity: "1.0"},100);},600);	
				});
			}
			return false;
		}
	});
	$("a.add_to_buy_box").click(function(){
		if($(this).hasClass("clicked")){
			return true;
		}
		else{
			$(this).addClass("clicked");
			$(this).text("Уже в корзине");
			$.get($(this).attr("href"));

			if($(this).hasClass("no_animation")){
				//var old_compare_value = parseInt($("a.buy_box > b").text());
				//var new_compare_value = old_compare_value+1;
				$("a.buy_box > b").text(parseInt($("a.buy_box > b").text())+1);
				$("a.buy_box").animate({opacity: "0.1"},100);setTimeout(function(){$("a.buy_box").animate({opacity: "1.0"},100);},200);
				setTimeout(function(){$("a.buy_box").animate({opacity: "0.1"},100);},400);
				setTimeout(function(){$("a.buy_box").animate({opacity: "1.0"},100);},600);					
				
			}
			else{
				if($(this).hasClass("full")){
					var start_position = $("div.description_image").offset();
					var end_position = $("a.buy_box").offset();
					
					var element_copy = $("div.description_image").clone();
					obj=$("div.description_image");
					
					element_copy.css("position","fixed");
					element_copy.css("z-index","9999999");
					element_copy.css("top",""+start_position.top-$(window).scrollTop()+"px");
					element_copy.css("left",""+start_position.left+"px");
					element_copy.css("border","none");
					//element_copy.find("div#wrap").css({top:"0px",left:"0px"});
					element_copy.find("img").css("bottom","auto");
					element_copy.find("img").css("margin","0px");
					element_copy.find("img").eq(1).remove();
					
					objw=$(obj).find("img:first").width();
					objh=$(obj).find("img:first").height();
					
					element_copy.find("img:first").css("width",objw+"px");
					element_copy.find("img:first").css("height",objh+"px");
					
					element_copy.find("div.product_prop").css("display","none");
					element_copy.prependTo($("div.description_image").parent());
					
					//$("div.description_image").eq(0).find("img").animate({height: "hide"},1500);
					$("div.description_image").eq(0).find("img").animate({height: "20px", width:20*objw/objh+"px"},1100);
					$("div.description_image").eq(0).animate({top: "0", left: ""+end_position.left+""},1000,function(){
						$("div.description_image").eq(0).remove();
						//$("a.buy_box > b").text(new_compare_value);
						$("a.buy_box > b").text(parseInt($("a.buy_box > b").text())+1);
						$("a.buy_box").animate({opacity: "0.1"},100);setTimeout(function(){$("a.buy_box").animate({opacity: "1.0"},100);},200);
						setTimeout(function(){$("a.buy_box").animate({opacity: "0.1"},100);},400);
						setTimeout(function(){$("a.buy_box").animate({opacity: "1.0"},100);},600);	
					});
				}
				else{
					var start_position = $(this).parent().children("div.image").offset();
					var end_position = $("a.buy_box").offset();
					
					obj=$(this).parent().children("div.image");
					var element_copy = $(this).parent().children("div.image").clone();
					element_copy.css("position","fixed");
					element_copy.css("z-index","9999999");
					element_copy.css("top",""+start_position.top-$(window).scrollTop()+"px");
					element_copy.css("left",""+start_position.left+"px");
					
					objw=$(obj).find("img:first").width();
					objh=$(obj).find("img:first").height();
					
					element_copy.find("img").css("bottom","auto");
					element_copy.find("img:first").css("width",objw+"px");
					element_copy.find("img:first").css("height",objh+"px");
					
					element_copy.find("div.product_prop").css("display","none");
					element_copy.prependTo($(this).parent());
					
					//$(this).parent().children("div.image").eq(0).find("img").animate({height: "hide"},1500);
					$(this).parent().children("div.image").eq(0).find("img").animate({height: "20px", width:20*objw/objh+"px"},1100);
					$(this).parent().children("div.image").eq(0).animate({top:"0", left:""+end_position.left+""},1000,function(){
						$(this).parent().children("div.image").eq(0).remove();
						//$("a.buy_box > b").text(new_compare_value);
						$("a.buy_box > b").text(parseInt($("a.buy_box > b").text())+1);
						$("a.buy_box").animate({opacity: "0.1"},100);setTimeout(function(){$("a.buy_box").animate({opacity: "1.0"},100);},200);
						setTimeout(function(){$("a.buy_box").animate({opacity: "0.1"},100);},400);
						setTimeout(function(){$("a.buy_box").animate({opacity: "1.0"},100);},600);	
					});
				}
			}			
			return false;
		}
	});
	
	$("div.menu td").mouseenter(function(){
		clearTimeout(close_timer);
		$("div.menu td").removeClass("current");
		$(this).addClass("current");
		$("div.header div.menu_slide").stop(true,true);
		$("div.header div.menu_slide").hide();
		if($(this).hasClass("shkaf")){
			ChangeSlide("shkaf");
		}
		if($(this).hasClass("stelag")){
			ChangeSlide("stelag");
		}
		if($(this).hasClass("seif")){
			ChangeSlide("seif");
		}
		if($(this).hasClass("med_mebel")){
			ChangeSlide("med_mebel");
		}
		if($(this).hasClass("pr_mebel")){
			ChangeSlide("pr_mebel");
		}
		if($(this).hasClass("items")){
			ChangeSlide("items");
		}
	});
	$("div.menu td").mouseleave(function(){
		clearTimeout(close_timer);
		close_timer = setTimeout(function(){
			$("div.header div.menu_slide").hide();
			$("div.menu td").removeClass("current");
		},200);
	});
	$("div.header div.menu_slide").mouseenter(function(){
		clearTimeout(close_timer);
	});
	$("div.header div.menu_slide").mouseleave(function(){
		$("div.header div.menu_slide").hide();
		$("div.menu td").removeClass("current");
		// clearTimeout(close_timer);
		// close_timer = setTimeout(function(){
			// $("div.header div.menu_slide").hide();
			// $("div.menu td").removeClass("current");
		// },1000);
	});
	$(window).scroll(function(){
		if($(window).scrollTop()==0){
			$("#top_menu").removeClass("shadow");
		}
		else {
			$("#top_menu").addClass("shadow");
		}
	});
	$("div.item_view_mode a").click(function(){
		$("div.item_view_mode a").removeClass("current");
		$(this).addClass("current");
		if($(this).hasClass("block")){
			$("ul.catalog_item_list li.catalog_item").removeClass("list");
		}
		if($(this).hasClass("list")){
			$("ul.catalog_item_list li.catalog_item").addClass("list");
		}
		return false;
	});
	
	
	$('div.product_block div.st').each(function(){
		var cg = document.createElement('canvas');
		$(cg).appendTo(this);
		if (window.G_vmlCanvasManager) G_vmlCanvasManager.initElement(cg);
		cg.width = parseInt($(this).width());
		cg.height = parseInt($(this).height());
		ctx = cg.getContext('2d');
		ctx.save();
		ctx.lineWidth = 1;
		ctx.beginPath();
		ctx.strokeStyle = "#bbbbbb";
		ctx.moveTo(0, 0);
		ctx.bezierCurveTo(0, 0, cg.width/4, cg.height, cg.width, cg.height);
		ctx.stroke();
		ctx.restore();
	});
	
	$('div.product_block div.stb').each(function(){
		var cg = document.createElement('canvas');
		$(cg).appendTo(this);
		if (window.G_vmlCanvasManager) G_vmlCanvasManager.initElement(cg);
		cg.width = $(this).width();
		cg.height = $(this).height();
		ctx = cg.getContext('2d');
		ctx.save();
		ctx.lineWidth = 1;
		ctx.beginPath();
		ctx.strokeStyle = "#bbbbbb";
		ctx.moveTo(cg.width, 0);
		ctx.bezierCurveTo(cg.width, 0, cg.width/4, 0, 0, cg.height);
		ctx.stroke();
		ctx.restore();
	});
	
/*	правка tradesu $("div.group_descr").each(function(){
			if($(this).outerHeight()>100){
			$(this).css("position","relative");
			$(this).css("overflow","hidden");
			$(this).append('<div class="hide_block"><span class="hide_switcher">&darr; Развернуть текст</span></div>');
			//$(this).wrap('<div class="group_hider"></div>');
			//$(this).parent().parent().append('<div class="hide_block"><span class="hide_switcher">&darr; Развернуть текст</span></div>');
			$(this).find("div.hide_block").css("width",$(this).outerWidth());
			$(this).find("div.hide_block span.hide_switcher").data("hidden","1");
			//$(this).parent().css("height",94);
			$(this).css("height",112);
		}
	})
	
	$("div.hide_block span.hide_switcher").bind("click",function(){
		if($(this).data("hidden")=="1" && $(this).html()!=""){
			$(this).data("hidden","0");
			$(this).html("&uarr; Свернуть текст");
			$(this).parent().parent().css("height","auto");
			obj=$(this).parent().parent();
			//$(obj).animate({"height":$(obj).data("max_height")},400);
			
		} else {
			$(this).data("hidden","1");
			$(this).html("&darr; Развернуть текст");
			$(this).parent().parent().css("height",112);
		}
	});
*/


	$(".navi_filter").attr('unselectable','on').css({
                   '-moz-user-select':'none',
                   '-webkit-user-select':'none',
                   'user-select':'none'
               });
	
	$(".navi_filter").bind("click",function(e){
		e.stopPropagation();
	});
	
	$("a.brand").bind("click",function(e){
		x=$(this).parent().width();
		y=$(this).width();
		z=$(this).parent().find("ul.brand_list").outerWidth();
		
		//console.log($(this).width());
		//console.log($(this).parent().find("ul.brand_list").outerWidth());
		$(this).parent().find("ul.brand_list").css("left",x-y/2-z/2+"px");
		$(this).parent().find("ul.brand_list").fadeToggle(200);
	});
	
	$("body").bind("click",function(){
		//if($(this).closest('.navi_filter').length==0){
			$('ul.brand_list').fadeOut(200);
			$('#prices').hide();
		//}
	});

	
	$('.img_tmb').bind('click',function(){
		img_number=$(this).attr('href').replace('#','');
		obj=$('div.item_description_box_left div.description_image');
		if($(obj).find(':animated').length==0){
			$(obj).find('a.img_current').removeClass('img_current').fadeOut(450,function(){
				$(obj).find('a').eq(img_number).addClass('img_current').fadeIn(450);
			});
		}
	});
	
	
	$('ul.catalog_item_list').each(function(){
		children=$(this).children();
		group=[];
		for(i=0;i<children.length;i++){
			if($(children[i]).is('.catalog_item')){
				group[group.length]=children[i];
			} else {
				heights=[];
				for(j=0;j<group.length;j++){
					heights[heights.length]=$(group[j]).outerHeight();
				}
				max_height=_.max(heights,function(h){return h;});
				if(max_height!=0){
					for(j=0;j<group.length;j++){
						$(group[j]).css({'height':max_height+'px'});
					}
				}
				group=[];
			}
		}
		if(group.length!=0){
			heights=[];
			for(j=0;j<group.length;j++){
				heights[heights.length]=$(group[j]).outerHeight();
			}
			max_height=_.max(heights,function(h){return h;});
			if(max_height!=0){
				for(j=0;j<group.length;j++){
					$(group[j]).css({'height':max_height+'px'});
				}
			}
			group=[];
		}
	});
	
	$('ul#prices').find('li:not(.active)').each(function(){
		$(this).clone(true).appendTo($(this).parent());
		$(this).remove();
	});
	
	$('ul#prices').bind('click',function(e){
		e.stopPropagation();
	});
	
	$('ul#prices li').bind('click',function(e){
		if($(this).hasClass('active')){
			$(this).parent().hide();
		} else {
			new_txt=$(this).find('.label').text();
			new_price=$(this).find('span.price_value').text();
			$(this).parent().parent().find('span.label:first').html(new_txt);
			$('#current_price_value').html(new_price);
			$(this).parent().children().removeClass('active');
			$(this).addClass('active');
			$(this).parent().hide();
			$(this).parent().find('li:not(.active)').each(function(){
				$(this).clone(true).appendTo($(this).parent());
				$(this).remove();
			});
		}
	});
	
	$('span#current_price').bind('click',function(e){
		e.stopPropagation();
		$(this).find('ul#prices').show();
	});
	
	var ctrl_down=false;
	var shift_down=false;
	var ctrl_key=17;
	var shift_key=16;
	$(document).keydown(function(e){
        if (e.keyCode == ctrl_key) ctrl_down = true;
		if (e.keyCode == shift_key) shift_down = true;
    }).keyup(function(e){
        if (e.keyCode == ctrl_key) ctrl_down = false;
		if (e.keyCode == shift_key) shift_down = false;
    });
	
/*	$("input[name=phone]").keydown(function(e){
		console.log(e.keyCode);
		if(e.keyCode>=48 && e.keyCode<=57 && shift_down==false){
		} else if(e.keyCode==48 || e.keyCode==57 || e.keyCode==187 && shift_down==true){
		} else if(e.keyCode==189 || e.keyCode==32 || e.keyCode==109 ||  e.keyCode==107){
		} else if((e.keyCode>=37 && e.keyCode<=40) || e.keyCode==9){
			//arrows,tab
		} else if(e.keyCode==46 || e.keyCode==8){
			//backspace, del
		} else if(e.keyCode==35 || e.keyCode==36){
			//home,end
		} else if(ctrl_down==true && (e.keyCode==67 || e.keyCode==86)){
			e.preventDefault();
		} else {
			e.preventDefault(); 
		}
    });*/

	$.tools.validator.localize("ru", {
		'[required]':'Обязательно для заполнения',
		':email':'Некорректный e-mail'
	});
	
	$.tools.validator.fn("[type=name]", function(el, value){
		return /^[абвгдеёжзийклмнопрстуфхцчшщьыъэюя]{2,}$/i.test(value) ? true : "Некорректное имя";
	});
	
	$.tools.validator.fn("[type=phone]", function(el, value){
		return /^\+?\d{11,20}?$/.test(value.replace(/\s+/g,'')) ? true : "Некорректный телефон";
	});
	
	$.tools.validator.fn("[type=address]", function(el, value){
		r=value.match(/[абвгдеёжзийклмнопрстуфхцчшщьыъэюя]/g);
		return r!=null && r.length>=5 ? true : "Некорректный адрес";
	});
	
	$.tools.validator.fn("[type=captcha]", function(el, value){
		return /^\+?\d{5}?$/.test(value) ? true : "Неверный код";
	});
	
	$('#izd_other_value').hide();
	$('input[name=izd_radio]').bind('click',function(){
		if($('#izd_other').is(':checked')){
			$('#izd_other_value').show();
		} else {
			$('#izd_other_value').hide();
		}
	});
	
	$('#ind').attr('novalidate', 'novalidate');
	$('#ind').my_validator({
		rules:{
			'4digits':{
				check:function(value){
					if(jQuery.trim(value)==''){
						return 'Обязательно для заполнения';
					} else {
						return /^\d\d\d\d$/.test(value.replace(/\s+/g,'')) ? true : "Введите 4-хзначное число";
					}
				}
			},
			'material':{
				check:function(value){
					if(jQuery.trim(value)==''){
						return 'Обязательно для заполнения';
					} else {
						return (/^\d+$/.test(value.replace(/\s+/g,'')) && parseInt(value)<=3 && parseInt(value)>=1) ? true : "Введите число не более 3";
					}
				}
			},
			'max100':{
				check:function(value){
					if(jQuery.trim(value)==''){
						return 'Обязательно для заполнения';
					} else {
						return (/^\d+$/.test(value.replace(/\s+/g,'')) && parseInt(value)<=100) ? true : "Введите число не более 100";
					}
				}
			},
			'textarea':{
				check:function(value){
					if(jQuery.trim(value)==''){
						return 'Обязательно для заполнения';
					} else {
						r=value.match(/[абвгдеёжзийклмнопрстуфхцчшщьыъэюя]/ig);
						return (r!=null && r.length>=5) ? true : "Введите хотя бы 5 русских символов";
						//return (/^\d+$/.test(value.replace(/\s+/g,'')) && parseInt(value)<=100) ? true : "Введите число не более 100";
					}
				}
			}
		},
		failure:function(){
			alert('Проверьте все поля');
		},
		success:function(){
			var form=$('#ind');
			if($('#izd_other').is(':checked') && _.trim($('#izd_other_value').val())!=''){
				$('#izd_other').val(_.trim($('#izd_other_value').val()));
			}

			var form_data=JSON.stringify($(form).my_validator('get_fields'));
			$.ajax({
				url: '/ajax.php?module=check_captcha',
				data: {fields:form_data},
				type: 'POST',
				success:function(msg){
					resp=JSON.parse(msg);
					if(resp.msg=='ok'){
						$.ajax({
							url: '/ajax.php?module=submit_ind',
							data: {fields:form_data},
							type: 'POST',
							success:function(msg){
								resp=JSON.parse(msg);
								if(resp.code=='ok'){
									alert(resp.msg);
									$('#ind').my_validator('reset');
								}
							}
						});
					} else {
						$(form).my_validator('invalidate',resp.errors);
					}
				}
			});
		},
		reset:function(){
			$('#ind').find('img.captcha_img').attr('src','/p/captcha.php');
			$('#ind').find('ul.qq-upload-list').html('');
			$('#ind').find('#attachment').val('');
			$('#ind').find('input[name=izd_type]:first').trigger('click');
			$('#ind').find('input[name=izd_radio]:first').trigger('click');
		}
	});
	
	if($('#file_uploader').length>0){
		var uploader = new qq.FileUploader({
			element: document.getElementById('file_uploader'),
			action: '/scripts/uploader.php',
			allowedExtensions: ['jpg','gif','doc','docx','txt','pdf'],
			sizeLimit: 1024*1024*5,
			multiple: false,
			params: {},
			onSubmit: function(id, fileName){
				$(uploader._listElement).html('');
			},
			onComplete: function(id, fileName, resp){
				if(resp.success){
					$('input#attachment').val(resp.path);
				}
			},
		});
	}
	
	
});
function ChangeSlide(type){
		$("div.header div.menu_slide div.ugolok").removeClass("shkaf");
		$("div.header div.menu_slide div.ugolok").removeClass("stelag");
		$("div.header div.menu_slide div.ugolok").removeClass("skami");
		$("div.header div.menu_slide div.ugolok").removeClass("mebel");
		$("div.header div.menu_slide div.ugolok").removeClass("mailbox");
		$("div.header div.menu_slide div.ugolok").removeClass("seif");
		$("div.header div.menu_slide div.ugolok").removeClass("items");
		$("div.header div.menu_slide div.ugolok").addClass(type);
		$("div.header div."+type+"").show();
}
