// agreement
$(function($){$('.agreement-checkbox').change(function(){if($(this).prop('checked')){$('.'+$(this).attr('agreement-sub')).attr('disabled',null);}else{$('.'+$(this).attr('agreement-sub')).attr('disabled','disabled');}});$(".agreement").click(function(){$.get('',{"agreement":true},function(data){$("body").append("<div class=\"agreement-custom\"><div class=\"agreement-custom__container\"><div class=\"agreement-custom__title_box\"><h3 class=\"agreement-custom__title\">Политика конфиденциальности</h3><div/></div><div class=\"agreement-custom__content\">"+data+"</div><div class=\"agreement-custom__close\"><div class=\"agreement-custom__close_box\"><span class=\"agreement-custom__line1\"></span><span class=\"agreement-custom__line2\"></span></div></div></div>");$("body").append("<div class=\"agreement-custom__bg\"></div>");var heightInside=$(".agreement-custom__container").outerHeight();var heightTitle=$(".agreement-custom__title_box").height();var heightContent=$(".agreement-custom__content");heightContent.height(heightInside-heightTitle);$(".agreement-custom__bg, .agreement-custom__close").click(function(){$(".agreement-custom__bg, .agreement-custom").remove();});});});$(window).resize(function(){var heightInside=$(".agreement-custom__container").outerHeight();var heightTitle=$(".agreement-custom__title_box").height();var heightContent=$(".agreement-custom__content");heightContent.height(heightInside-heightTitle);});});

$(document).ready(function(){

	$(".main-slider").slick({
		autoplay: true,
		autoplaySpeed: 3000,
		dots: true,
		fade: true,
		arrows: false,
	});


	// if($(window).width() <= 960){
	// 	var heightSlider = $(".main-slider");
	// 	var heightVideo = $(".main-slider__video");

	// 	heightVideo.height(heightSlider.height());
	// };

	// $(window).resize(function(){
	// 	if($(window).width() <= 960){
	// 		var heightSlider = $(".main-slider");
	// 		var heightVideo = $(".main-slider__video");

	// 		heightVideo.height(heightSlider.height());
	// 	}
	// });

	// Махинации с видео в главном слайдере
	
	


	

	// Слайдер клиенты
	$(".clients-slider").slick({
		autoplay: true,
		autoplaySpeed: 3000,
		slidesToShow: 4,
  		slidesToScroll: 1,
  		arrows: true,
  		responsive: [{
      		breakpoint: 1211,
      		settings:{
        		slidesToShow: 3
      		}},
      		{
      		breakpoint: 1024,
      		settings:{
        		slidesToShow: 3
      		}},
      		{
      		breakpoint: 800,
      		settings:{
        		slidesToShow: 2
      		}},
      		{
      		breakpoint: 640,
      		settings:{
        		slidesToShow: 1
      		}},
    	]
	});


	// Слайдер клиенты на странице детализации продукции
	$(".products-page__descrip-list").slick({
		autoplay: true,
		autoplaySpeed: 3000,
		slidesToShow: 3,
  		slidesToScroll: 1,
  		arrows: true,
  		responsive: [{
      		breakpoint: 640,
      		settings:{
        		slidesToShow: 2
      		}},
      		{
      		breakpoint: 412,
      		settings:{
        		slidesToShow: 1
      		}},	
    	]
	});




	// Слайдер продукции на странице детализации
	$(".products-page__slider, .news-inpage__slider").slick({
		autoplay: true,
		autoplaySpeed: 2500,
		slidesToShow: 3,
		responsive: [{
      		breakpoint: 1211,
      		settings:{
        		slidesToShow: 2
      		}},
      		{
      		breakpoint: 641,
      		settings:{
        		slidesToShow: 1
      		}},
      	]
	});

	// Слайдер персонала на странице о компании
	// $(".about-page__slider").slick({
	// 	autoplay: true,
	// 	autoplaySpeed: 3000,
	// 	slidesToShow: 4,
	// 	responsive: [{
 //      		breakpoint: 1211,
 //      		settings:{
 //        		slidesToShow: 3
 //      		}},
 //      		{
 //      		breakpoint: 960,
 //      		settings:{
 //        		slidesToShow: 2
 //      		}},
 //      		{
 //      		breakpoint: 640,
 //      		settings:{
 //        		slidesToShow: 1
 //      		}},
 //      	]
		
	// });




	if($(window).width() > 1209){
		$(".menu__link_sub").click(function(){
			if($(".menu__sub-list").css("display") == "none"){
				$(".menu__sub-list").css("display", "block");
				$(".header__arrow").css("transform", "rotate(180deg)");
			}else{
				$(".menu__sub-list").css("display", "none");
				$(".header__arrow").css("transform", "rotate(0deg)");
			}
		});
	}

	if($(window).width() <= 1209){
		$(".menu__link_sub").click(function(){
			if($(".menu__sub-list").css("display") == "none"){
				$(".menu__sub-list").slideToggle(500);
				$(".header__arrow").css("transform", "rotate(180deg)");
			}else{
				$(".menu__sub-list").slideToggle(500);
				$(".header__arrow").css("transform", "rotate(0deg)");
			}
		});
	}

	$(".menu__link_sub").click(function(a){
		a.preventDefault();
	});

	$(".order-call__tel").mask("+7 (999) 999-99-99");

	$(document).ready(function(){
		setTimeout(function(){
			$('.sent-event-messed').fadeOut(1000);
		}, 3000);
		$('.bg-dark').click(function(){
			$('.sent-event-messed').fadeOut(1000);
		});
	});


	$(document).mouseup(function(e){
		var subList = $(".menu__sub-list");
		var link = $(".menu__link_sub");
		if(!subList.is(e.target)
			&& subList.has(e.target).length === 0
			&& !link.is(e.target)){
				$(".menu__sub-list").css("display", "none");
				$(".header__arrow").css("transform", "rotate(0deg)");
			}
		});

		$(".tel-block__button").click(function(){
			if($(".order-call").css("display") == "none"){
				$(".order-call").css("display", "block");
				$(".bg").css("display", "block");
			}
		});

		$(".order-call__close, .bg").click(function(){
			if($(".order-call").css("display") == "block"){
				$(".order-call").css("display", "none");
				$(".bg").css("display", "none");
			}
		});




	
	if($(window).width() >= 1210){
		// добавить линии к ссылкам
		$(".menu__item").append("<div class=\"line-box\"><span class=\"link-line\"></span><span class=\"link-line2\"></span></div>");
	
		//НАВЕДЕНИ НА ПУНКТ МЕНЮ
		$(".menu__link").mouseenter(function(){
			$(".menu__link").css("opacity", "0.5");
			$(".menu__link").css("right", "0");
			$(this).css({"opacity": "1", "right": "20px"});
			$(".sub-menu").css("display", "none");
			$(this).siblings("div").find(".sub-menu").css("display", "inline-block");
			$(this).siblings("div").find(".sub-menu").animate({"top": "0", "opacity": "1"}, 200);

			$(".line-box:not(this)").css("right", "-300px");
			$(".link-line:not(this)").css("height", "0px");

			$(this).parent("li").find(".line-box").css("right", "-20px")
			$(this).parent("li").find(".link-line").css("height", "1px");
		});

		// СВЕДЕНИЕ С ПУНКТА МНЮ
		$(".menu__link").mouseleave(function(){
			$(".sub-menu").css({"top": "50px", "opacity": "0"});
			$(this).siblings("div").find(".sub-menu").css({"display": "inline-block", "top": "0", "opacity": "1"});


			$(".line-box:not(this)").css("right", "-300px");
			$(".link-line:not(this)").css("height", "0px");

			$(this).parent("li").find(".line-box").css("right", "-20px")
			$(this).parent("li").find(".link-line").css("height", "1px");

		});




	}else{
		// добавить крестик к ссылкам
		$(".sub-menu__box").parent("li").append("<div class=\"line-box\"><span class=\"link-line\"></span><span class=\"link-line2\"></span></div>");
	
		$(".line-box").click(function(){
			if($(this).siblings(".sub-menu__box").css("display") == "none"){
				$(this).siblings(".sub-menu__box").slideToggle(400);
				$(this).find(".link-line2").css("transform", "rotate(90deg)");
			}else{
				$(this).siblings(".sub-menu__box").slideToggle(400);
				$(this).find(".link-line2").css("transform", "rotate(0deg)");
			}
		})



	};
	
	
	




	if($(window).width() >= 640){
		// ОТКРЫТЬ/ЗАКРЫТЬ МЕНЮ
		$(".menu__square").click(function(){
			$(".menu__box").css("left", "0px");
			$(".new-burger__line2").css("display", "none");
			$(".new-burger__line1").css("transform", "rotate(45deg)");
			$(".new-burger__line1").css("top", "10px");
			$(".new-burger__line3").css("transform", "rotate(-45deg)");
			$(".new-burger__line3").css("top", "10px");
			$(".menu__square").css("background", "#2b2b2b");
			$(".menu__square").css("box-shadow", "none");
			$(".new-burger__line").css("background", "#fff");
			$(".menu__name").css("color", "#fff");
			
			if($(".menu__box").css("left") == "0px"){
				$(".menu__box").css("left", "-100%");
				$(".new-burger__line2").css("display", "inline-block");
				$(".new-burger__line1").css("transform", "rotate(0deg)");
				$(".new-burger__line1").css("top", "0");
				$(".new-burger__line3").css("transform", "rotate(0deg)");
				$(".new-burger__line3").css("top", "18px");
				$(".menu__square").css("background", "#41464c");
				$(".menu__square").css("box-shadow", "0 0 10px 0px #4444");
				$(".new-burger__line").css("background", "#fff");
				$(".menu__name").css("color", "#fff");
			};
		});
	}else{
		$(".menu__square, .menu__close").click(function(){
			$(".menu__box").css("left", "0px");
	
			if($(".menu__box").css("left") == "0px"){
				$(".menu__box").css("left", "-100%");
			};
		});
	}
	







	// Добавить класс container к кнопкам слайдера
	$(".main-slider .slick-dots").addClass("container");


	//// Удаление HOVER
	$(window).width(function(){
	  if($(window).width() <= 1024){
	    $("body, html").removeClass("hover");
	  }else{
	    $("body, html").addClass("hover");
	  }
	});

if ($(window).width() >= 640 ) {
// фиксация и уменьшение шапки при скролле
var headerHeight = $('.header').outerHeight(),
	headerBottomTouch = headerHeight,
	scroll = $(window).scrollTop(); 
	$('.container.common').css({'paddingTop' : headerHeight + 'px'});


	if(scroll != 0){
		$(".header").addClass("header_bottom");
		$(".menu__square").addClass("menu__square_bottom");
	}


	$(window).scroll(function(){
		if(scroll > (headerBottomTouch + 100)){
			$(".header").addClass("header_bottom");
			$(".menu__square").addClass("menu__square_bottom");
		}else{
			$(".header").removeClass("header_bottom");
			$(".menu__square").removeClass("menu__square_bottom");
		}
		scroll = $(window).scrollTop(); 
	});
// конец скрипта фиксации шапки
}



// Перенос лейбла вверх (форма в футере)

$(".footer__field").focus(function(){
	$(this).next(".footer__label").addClass("footer__label_top");
	$(this).change(function(){
		if($(this).val() != ""){
			$(this).next(".footer__label").removeClass("footer__label_top");
		}else{
			$(this).next(".footer__label").addClass("footer__label_top");
		}
	});
});

$(".footer__field").blur(function(){
	if($(this).val() == ""){
		$(this).next(".footer__label").removeClass("footer__label_top");
	}else{
		$(this).next(".footer__label").addClass("footer__label_top");
	}
});

for(var numberField = $(".footer__field").length, i = 0; i < numberField; i++){
	if($($(".footer__field")[i]).val() == ""){
		$($(".footer__field")[i]).next(".footer__label").removeClass("footer__label_top");
	}else{
		$($(".footer__field")[i]).next(".footer__label").addClass("footer__label_top");
	}
}




// Показать больше сотрудников при клике на кнопку
$(".workers__button").click(function(){
	if($(".workers__sub-list").css("display") == "none"){
		$(".workers__sub-list").slideToggle(500);
		$(".workers__button").text("скрыть сотрудников");
	}else{
		$(".workers__sub-list").slideToggle(500);
		$(".workers__button").text("все сотрудники");
	}
});


// Отмена перехода по ссылками телефона и почты на странице О компании
// if ($(window).width() >= 1210){
// 	$(".workers__tel, .workers__mail").click(function(k){
// 		k.preventDefault();
// 	});
// }
// $(window).resize(function(){
// 	if ($(window).width() >= 1210){
// 		$(".workers__tel, .workers__mail").click(function(k){
// 			k.preventDefault();
// 		});
// 	}
// });



// Добавить класс к видео в слайдере и убираем атрибуты width, height

$(".main-slider__slide iframe").addClass("main-slider__video");
$(".main-slider__slide iframe").removeAttr("width");
$(".main-slider__slide iframe").removeAttr("height");







});
