"+hint+"
");
			$('#sumNa').addClass('opened');
		}
		
//		el.css('left', left+'px');
//		el.css('top', top+'px');
		
    });*/
	
    $("body").on("click", "#sumNa > div", function() {
		var item_id = $(this).parents('.item').attr('id');
        window.location.href='/case/add/?item_id='+item_id;
		
		
    });
	
	
	$(document).mouseup(function (e){ // событие клика по веб-документу
		var div = $("#sumNa"); // тут указываем ID элемента
		if (!div.is(e.target) // если клик был не по нашему блоку
		    && div.has(e.target).length === 0) { // и не по его дочерним элементам
			div.hide(); // скрываем его
		}
	});
	
		
	
	var mql = window.matchMedia('all and (max-width: 700px)');
	if (mql.matches) {
		$('body').addClass('is_mobile');
	    // размер окна 480px или меньше
	} else {
		$('body').removeClass('is_mobile');
	    // нет, размер окна более 480px 
	}
   
    initXForm();
	
    $("#topMenu li").mouseenter(function(){
        $(this).addClass("over");
    });
    $("#topMenu li").mouseleave(function(){
        $(this).removeClass("over");
    });
    $(".hasOver").mouseenter(function(){
        $(this).addClass("over");
    });
    $(".hasOver").mouseleave(function(){
        $(this).removeClass("over");
    });
    $(".buyCert").click(function() {
        var id = $(this).attr('id');
        $.fancybox({
			'padding'		: 20,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'href'			: '/components/buy_cert.phtml?item_id='+id,
            'type'          : 'ajax'
        });
         
    });
	$(".fbImageGroup").fancybox({
		openEffect	: 'none',
		closeEffect	: 'none'
	});
    $("body").on('click', '.mobileMenuBtn', function() {
		var el = $('.topMenu');
		
		if (el.hasClass('opened')) {
			
			if (el.hasClass('l2')) {
				el.removeClass('l2');
				el.addClass('l1');
			} else 
			if (el.hasClass('l1')) {
				el.removeClass('l1');
			} else {
				el.removeClass('opened');
				$('body').removeClass('mobileMenuOpened');
				$('#overBody').remove();
			}
			el.find('.mBlk.opened').removeClass('opened');
			
			
		} else {
			el.addClass('opened');
			$('body').addClass('mobileMenuOpened');
			$('body').append("
")
			
			
		    $("#overBody").click(function() {
				var el = $('.topMenu');
				if (el.hasClass('opened')) {
						el.removeClass('opened');
						$('body').removeClass('mobileMenuOpened');
						$('#overBody').remove();
				}
	 
				return false;
         
		    });
			
		}
		
		return false;
         
    });
	
    $(".contacts h2").click(function() {
		var el = $(this).parents('li');
		
		if (el.hasClass('opened')) {
			el.removeClass('opened');
			$(this).find('i').removeClass('fa-angle-up');
			$(this).find('i').addClass('fa-angle-down');
		} else {
			el.addClass('opened');
			$(this).find('i').removeClass('fa-angle-down');
			$(this).find('i').addClass('fa-angle-up');
		}
         
    });
        
          
    $("#callBack").click(function() {
        $.fancybox({
			'padding'		: 20,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'href'			: '/components/ajax_callback.phtml',
            'type'          : 'ajax'
        });
         
    });
    $(".searchForm input").focus(function(){
        var txt = 'ПОИСК';
        
        if ($(this).val()==txt) {
            $(this).val('');
        }
    })
    $(".searchForm input").blur(function(){
        var txt = 'ПОИСК';
        
        if ($(this).val()=='') {
            $(this).val(txt);
        }
    })
    var txt = 'ПОИСК';
    var searchControl = $(".searchForm input[type='text']");
    if (searchControl.val()=='') {
        searchControl.val(txt);
    }
	function currentSlide( current ) {
		$(".current_slide").text(current + " of " + $("#slides").slides("status","total") );
	}
    $(".contacts_get").click(function() {
        var addr = $(this).attr('addr');
        var type = $(this).attr('type');
       
        $(".dCont").addClass("hidden");
        $("#map_"+addr).removeClass("hidden");
        $("#descr_"+addr+"_"+type).removeClass("hidden");
        
        return false;
    });
    $(".btn.reserve").click(function() {
        var id = $(this).attr('id');
        
        window.location.href='/reserve/r-'+id;
        return false;
    });
  
    $(".lb li").click(function() {
        $(".lb li.selected").each(function() {
            $(this).removeClass('selected');
        });
    });
    $(".cb li, .lb li").click(function() {
        
        if ($(this).hasClass('selected')) {
            $(this).removeClass('selected');
        } else {
            $(this).addClass('selected');
        }
		var isNew = "";
        if ($(this).parents("ul").hasClass('new')) {
            isNew = 'new/';
        }        
		
        var query = "";
        var npp=0;
        $(".cb li.selected").each(function() {
            
            query = query + 'ids['+$(this).attr('id')+']=1'+'&';
            npp++;
        });
        
        $(".lb li.selected").each(function() {
            query = query + 'ids['+$(this).attr('id')+']=1'+'&';
            npp++;
        });
        
        
        query = query.substring(0, query.length - 1)
        
        var alias = "";
        $(".list li.selected").each(function() {
            alias = $(this).attr('alias');     
        });
		
        var xUrl = "/jewellery/"+isNew+alias+"?"+query;
//        params = $.extend($.url().param(), params);
//        alert(url);
        $.ajax({
            url: xUrl,
            cache: false,
            success: function(html) {
                $("#itemsBody").html(html);
                afterItemUpdate();
                history.pushState(null, null, xUrl);
    
            },
            error: function() {
                alert('error!');
            }
            
        });        
        
        return false;
    });
    $(".nav ul.display li").click(function() {
        var view="";
        if ($(this).hasClass('list')) {
            view = 'list';
        } else {
            view = 'grid';
        }
        $.ajax({
            url: "/setSession.phtml?view="+view,
            cache: false,
            success: function(html) {
                window.location.reload();
    
            },
            error: function() {
                alert('error!');
            }
            
        });        
        return false;
    });
    
	$(".cities ul li").click(function() {
		var self = $(this);
		var id=$(this).attr('id');
        $.fancybox({
			'padding'		: 20,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'href'			: "/templates/ajax_contacts.phtml?id="+id,
            'type'          : 'ajax'
        });
		/*
        $.ajax({
            url: "/templates/ajax_contacts.phtml?id="+id,
            cache: false,
            success: function(html) {
                self.find(".cityDetail").html(html);
            },
            error: function() {
                alert('error!');
            }
            
        });   */     
	});
  
	$(".fancybox").fancybox();
    $("body").on('click', '.fastRequest, .price .req',  function(e) {
		var item_id = $(this).attr('item_id');
		
		if (item_id == undefined) {
			item_id = $(this).parents('.item').attr('id');
		}
		
		var url = '/forms/fastRequest.phtml?item_id='+item_id;
		
        $.fancybox({
			'padding'		: 10,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'href'			: url,
            'type'          : 'ajax',
			'wrapCSS'		: 'white',
			afterShow: function() {
				
			} 
        });
		return false;
				
	});	
	
	$("body").on('click', '.ajax_container .close', function() {
		
		var url = $(".goodItems").attr('currentUrl');
		window.history.replaceState(null, null, url);
		$('.ajax_container').remove();
	
	});	 
	$("body").on('click', '.ajax_container .next, .ajax_container .prev, .variant', function() {
		var id = $(this).attr('id');
		showAjaxItem(id);
		return false;
	});	 
	$(".bxSliderBox .sliderItems").bxSlider({
		minSlides: 1,
  	  	maxSlides: 4,
		slideWidth: 360,
		slideMargin: 0,
		moveSlides: 1,
		touchEnabled: $('body').hasClass('is_mobile')
	});
	$(".bxSliderBox .zoneItems").bxSlider({
		minSlides: 1,
  	  	maxSlides: 3,
		slideWidth: 395,
		slideMargin: 0,
		moveSlides: 1,
		touchEnabled: $('body').hasClass('is_mobile')
	});
	
	$(".topBan > div > .close").click(function() {
		$(".topBan").animate({height: 0}, 600);
		
		$.cookie('topBan_4', 'show', { expires: 1, path: '/' });
		return false;
	});
	
	
	$(".is_mobile #header .topMenu > section > ul > li.catalog_item > a").click(function() {
		var el = $(this).parents("nav.topMenu");
		
		if (el.hasClass('l1')) {
			el.removeClass('l1');
		} else {
			el.addClass('l1');
		}
		return false;
		
	});
	$("#header nav.topMenu > section > ul > li.catalog_item .submenu ul.three_columns .mBlk > b").click(function() {
		var el = $(this).parents("nav.topMenu");
		el.removeClass('l1');
		el.addClass('l2');
		
		var el2 = $(this).parents(".mBlk");
		if (el2.hasClass('opened')) {
			el2.removeClass('opened');
		} else {
			el2.addClass('opened');
		}
		
		return false;
		
	});
	
	
	$(".items #itemInfo .gInfo .seeLink").click(function() {
		var el = $('#seeInSalonPopup');
		
		if (el.hasClass('opened')) {
			el.removeClass('opened');
		} else {
			el.addClass('opened');
		}
	});
	
	$(document).mouseup(function (e){ // событие клика по веб-документу
		var div = $("#seeInSalonPopup"); // тут указываем ID элемента
		if (!div.is(e.target) // если клик был не по нашему блоку
		    && div.has(e.target).length === 0) { // и не по его дочерним элементам
			div.removeClass('opened'); // скрываем его
		}
	});	
	
    $("body").on("click", ".makeMail2", function() {
        var xlsType=$(this).attr("type");
        var order_id=$(this).attr("order_id");
		
		$("#orderEditDialog").dialog('close');
		
        $.fancybox({
			'padding'		: 20,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'href'			: '/forms/mail_comm_form2.phtml?order_id='+order_id+'&type='+xlsType,
            'type'          : 'ajax'
        });
		
               
            return false; 
    });	
	
	
	
	$('.priceOrder').click(function() {
		var order = $(this).attr('order');
		
        $.ajax({
            url: "/setSession.phtml?priceOrder="+order,
            cache: false,
            success: function(html) {
                window.location.reload();
    
            },
            error: function() {
                alert('error!');
            }
            
        });        
		
		
	})
	
          
});    
function submitRequestForm(e) {
    // Initiate Variables With Form Content
    var name = e.find("#name").val();
    var tel = e.find("#tel").val();
    var email = $("#email").val();
    var item_id = $("#item_id").val();
 	var data = {
		name: name,
		tel: tel, 
		email: email,
		item_id: item_id,
		action: 'create'
	}
    $.ajax({
        type: "POST",
        url: "/auth/ajax_order.phtml",
        data: data,
        cache: false,
    	dataType: "json",
        success : function(result){
			if (result.status=='ok') {
				console.log(result);
				if (result.fio!=undefined) {
					window.dataLayer = window.dataLayer || [];
					window.dataLayer.push({
						'ecommerce': {
						'currencyCode': 'RUB',
						'purchase': {
							'actionField': {
							'id': result.order_npp,
							'affiliation': 'Hurtado',
							'revenue': result.order_summ,
							'tax': '0',
							'shipping': '0'
							},
							'products': result.products
						}
						},
						'event': 'gtm-ee-purchase-event',
						'gtm-ee-event-category': 'Enhanced Ecommerce',
						'gtm-ee-event-action': 'Purchase',
						'gtm-ee-event-non-interaction': 'False',
						'fio': result.fio,
						'email': result.email,
						'tel': result.tel,
						'message': result.message,
						'order_id': result.order_id,
						'page_item_id': item_id
					
					});
				}
				$.fancybox("
Спасибо за ваше обращение! 
В ближайшее время мы свяжемся с вами.

");
			}
			
        }
    });
}
function showAR(item_id) {
		
	if ($('#container3d').hasClass('loaded')) {
		var modelViewer = document.querySelector("#container3d model-viewer");
		if (modelViewer.canActivateAR) {
			modelViewer.activateAR();
		} else {
			arNotSupport(item_id);
		}
	} else {
		$.ajax({
			url: "/components/ajax_3dmodelViewer.phtml?item_id="+item_id,
			type: 'GET',
			cache: false,
			async: false,
			success: function(html) {
				$('#container3d .is_container').html(html);
				$('#container3d').addClass('loaded');
				$('#gallery').addClass('loading');
				var modelViewer = document.querySelector("#container3d model-viewer");
				modelViewer.addEventListener('load', (event) => {
					$('#container3d').addClass('loaded');
					$('#gallery').removeClass('loading');
					document.querySelector("#container3d model-viewer").activateAR();
					
					if (!document.querySelector("#container3d model-viewer").canActivateAR) {
						arNotSupport(item_id);
					}
				});
				
				
//						document.querySelector("#container3d model-viewer").activateAR();
			}
		});
	}
}
function arNotSupport(item_id) {
	$.fancybox({
		'padding':20,
		'transitionIn':'none',
		'transitionOut':'none',
		'href':'/forms/arPageQRCode.phtml?item_id='+item_id,
		'type':'ajax'
	});
	return false;
}