Your IP : 3.144.206.120


Current Path : /home/bitrix/ext_www/shuft.com.ua/bitrix/templates/shuft/_inc/js/
Upload File :
Current File : /home/bitrix/ext_www/shuft.com.ua/bitrix/templates/shuft/_inc/js/index.js

function declOfNum(number, titles)  
{  
    cases = [2, 0, 1, 1, 1, 2];  
    return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];  
}


window.lastClickedItemPos = 0;
function setFilterLabelTop(result) {
	$('#modef').css('top', window.lastClickedItemPos+'px');
}

$(document).ready(function(){
//выравнивание заголовков партнеров
	var mh = 0;
	    $(".catalog_content-category_link").each(function () {
		    var h_block = parseInt($(this).height());
		    if(h_block > mh) {
			   mh = h_block;
		    };
	    });
	    $(".catalog_content-category_link").height(mh);
	   
	   


//вид кнопок переключалок
	$(".bunner_item").on('click', function(e) {
		e.preventDefault();
		if (!$(this).hasClass("active-bunner")) {
			$(".bunner_item").removeClass("active-bunner");
			$(this).addClass("active-bunner");
			$('.bunners_body-wrap').toggle().toggleClass('bunner-visible');	 //переключаем баннеры
		}
		$('html, body').stop().animate({ scrollTop: Math.floor($('.bunners_body-wrap.bunner-visible').offset().top)+'px' }, 400);
	});

//скролл
	// var paneElement = $('.scroll-pane').jScrollPane({
		// showArrows:true,
	// });
	
	$('.catalog_filter .isFromTo').each(function() {
		var selects = $('select', this);
		var inputs = $('input', this);
		var values = [];
		// $('.checkbox', this).addClass('hide');	// moved to template
		var selectedID = 0;
		var from_val = '';
		var to_val = '';
		inputs.addClass('no_styler').each(function() {
			var is_checked = $(this).is(':checked');
			values.push([$(this).attr('id'), $('label', $(this).parents('.bx-filter-input-checkbox')).text(), is_checked]);
			if (selectedID == 0 && is_checked) {
				from_val = values[values.length-1][0];
				selectedID++;
			} else if (selectedID == 1 && !is_checked) {
				to_val = values[values.length-2][0];
				selectedID++;
			}
		});
		if (values.length) {
			if (from_val == '') {
				from_val = values[0][0];
			}
			if (to_val == '') {
				to_val = values[values.length-1][0];
			}
		}
		$.each(values, function(key, val) {
			selects.append('<option value="'+val[0]+'">'+val[1]+'</option>');
		});
		if (values.length > 0) {
			selects.filter('.from').val(from_val);
			selects.filter('.to').val(to_val);
		}
		selects.on('change', function() {
			var from_el = selects.filter('.from').val();
			var to_el = selects.filter('.to').val();
			var selectIt = false;
			inputs.each(function(index) {
				var id = $(this).attr('id');
				if (id == from_el) {
					selectIt = true;
				}
				$(this).attr('checked', selectIt);
				if (id == to_el) {
					selectIt = false;
				}
			});
			eval(inputs.eq(0).attr('onclick'));
			window.lastClickedItemPos = selects.eq(0).offset().top - $('.catalog_filter').offset().top - 10;
		});
	});
	
	$('input:not(.no_styler), select').styler();
	
	$('.catalog_filter .jq-checkbox input').on('change', function() {
		$(this).trigger('click');
		window.lastClickedItemPos = $(this).offset().top - $('.catalog_filter').offset().top - 10;
	});
	
	$('.popup-gallery').magnificPopup({
		delegate: 'a',
		type: 'image',
		tLoading: 'Loading image #%curr%...',
		mainClass: 'mfp-img-mobile',
		gallery: {
			enabled: true,
			navigateByImgClick: true,
			preload: [0,1] // Will preload 0 - before current, and 1 after the current image
		},
		image: {
			tError: '<a href="%url%">The image #%curr%</a> could not be loaded.'
		}
	});
	
	var open_speed = 0;
	if ($(".catalog_menu .active").length) {
		open_speed = 500;
	}
	$(".catalog_menu").accordion({
		accordion:false,
		// speed: 500,
		speed: open_speed,
		closedSign: '&darr;',
		openedSign: '&uarr;'
	});
	$(".catalog_menu.activate_all > li a").addClass('active');
	$(".catalog_menu .active_subgroup").each(function() {
		$(this).parents('ul').parents('li').find('> a').addClass('active');
	});
	$(".catalog_menu .active").each(function() {
		$(this).trigger('click').parents('li').addClass('active_a');
	});
	$(".catalog_menu > li:not(.active_a) ul").remove();
	$(".catalog_menu .active_a > a").unbind();
	
	$(".documents_menu").accordion({
		 accordion:true,
		 speed: 500,
		 closedSign: '&darr;',
		 openedSign: '&uarr;'
	 });
	 //
	$(function(){			
        $('.documents_menu a').click(function(){
			$('.documents_menu a').removeClass('active')
            $(this).toggleClass("active");
			$(this).parent("li").toggleClass("select");				
        });
    });
		
//блоки
	$( '.subgroup_greed, .dealers_greed' ).masonry( { 
		itemSelector: '.catalog_content-category_subgroup_link, .dealer_item'
	});

	$('.catalog_filter-selected_li').click(function(){
		$(this).hide();		
	});
	
	//scroll	
	$(window).scroll(function () {
        if ($(this).scrollTop() > 0) {
            $('#scroller').fadeIn();
        } else {
            $('#scroller').fadeOut();
        }
    });
    $('body').on('click', '#scroller', function () {
        $('body,html').stop().animate({
            scrollTop: 0
        }, 400);
        return false;
    });
	
	//tabs	
	$("#dealersTab").tabs();

	//колонки
	$(function () {
       $('#dealersList').autocolumnlist({
            columns:7
        });
    });
	
	// Carousel
	$("#carouselSearch").sliderkit({
		auto:false,
		autospeed:4000,
		shownavitems:5,
		circular:true,
		fastchange:false,
		scrolleasing:"easeOutExpo", //"easeOutBounce, easeOutBack"
		scrollspeed:500
	});
	if ($('#carouselSearch .sliderkit-nav-clip ul li').length < 6) {
		$('#carouselSearch .sliderkit-nav-btn').hide();
		$('#carouselSearch .sliderkit-nav').css('padding', 0);
		$('#carouselSearch .sliderkit-nav-clip').css('width', 'auto');
	}

	//галерея в карточке товара
	$(".photosgallery-captions").sliderkit({
		navscrollatend: true,
		/* mousewheel:true, */
		/* keyboard:true, */
		shownavitems:4,
		auto:false,
		fastchange:true
		/* start:6 */
	});
	//popup в карточке	
	$('.image-popup-vertical-fit').magnificPopup({
		type: 'image',
		// closeOnContentClick: true,
		mainClass: 'mfp-img-mobile',
		fixedContentPos: false,
		gallery: {
			enabled: true,
			navigateByImgClick: true,
			preload: [0,1] // Will preload 0 - before current, and 1 after the current image
		},
		image: {
			verticalFit: true
		}
		
	});  
	
	//callback
	$('.popup-with-zoom-anim').magnificPopup({
		type: 'inline',

		fixedContentPos: false,
		fixedBgPos: true,

		overflowY: 'auto',

		closeBtnInside: true,
		preloader: false,
		
		midClick: true,
		removalDelay: 300,
		mainClass: 'my-mfp-zoom-in'
	});

	$('.callback_input').bind("change keyup input click", function() {
 		if (this.value.match(/[^\d+]/g)) {
 			this.value = this.value.replace(/[^\d.]/g, '');
 		}
 	});

	$(".callback_button-send").on('click', function(event) {
		event.preventDefault();
		$("form.callback .callback_error-massage").hide();
		var name = $("form.callback input[name=NAME]").val();
		var company = $("form.callback input[name=COMPANY]").val();
		var phone = $("form.callback input[name=PHONE]").val();
        error = false;
		if (name.length == 0){
			error = true;
    		$("form.callback .callback_error-massage.name").show();
		}else if (phone.length == 0){
			error = true;
    		$("form.callback .callback_error-massage.phone").show();
		}else if(!phone.match(/^\+3\d{10}$/)){
			error = true;
    		$("form.callback .callback_error-massage.phone").show();
		}
		if (!error){
			$.post("/bitrix/ajax/callback.php", {name:name, company:company, phone:phone}, function(data){
				if (data=='ok'){
            		$("form.callback .callback_box-massage").hide();
            		$("form.callback .callback_success").show();
					$("form.callback input[type=text], form.callback input[type=phone]").val('');
				}
			});
		}
	});
	//end callback

		
	//прокрутка к якорям
	$('body').on('click', '.catalog_item_section_list li a[href^="#"]', function(e){
		e.preventDefault();
        var el = $(this).attr('href');
        $('html, body').stop().animate({ scrollTop: Math.floor($(el).offset().top)+'px' }, 400);
	});
	
	
	
	$(window).load(function() {
		setTimeout(function() {
			$('.header_menu-1_li_a, .footer_menu-1_li_a').each(function() {
			  $(this).width($(this).width());
			});
		}, 1);
	});
	
	if ($('#card_link_changer').length) {
		$('#card_link_changer').on('change', function() {
			window.location.href = $(this).val();
		});
	}
	
	if ($('#filter_news_select').length) {
		$('#filter_news_select').on('change', function() {
			if ($(this).val() == '') {
				window.location = $(this).parents('form').attr('action');
			} else {
				$(this).parents('form').submit();
			}
		});
	}
});