jQuery( document ).ready(function($) {

var $header = $(".site_header"),
$clone = $header.before($header.clone().addClass("clone"));


$(window).on("scroll", function() {
	var fromTop = $(window).scrollTop();
	$("body").toggleClass("down", (fromTop > 400));
});

// responsive menu


$('body').on('click', '.menu_responsive_icon', function() {	
	$('body').toggleClass('responsive_menu_open');
});
$( ".menu_header .menu-item-has-children" ).append( '<div class="arrow_down_menu"></div>' );
$('body').on('click', '.arrow_down_menu', function() {
	$(this).parent('.menu-item-has-children').toggleClass('active_submenu_responsive');	
});

// slider header
if(jQuery('.slider_content').length){

	$('.slider_content').slick({dots: false,infinite: true,speed: 1600,fade:true,slidesToShow: 1,autoplay: true,autoplaySpeed:10000,slidesToScroll: 1,pauseOnHover:false,arrows: false,
	//adaptiveHeight: true
	});
}

//go to id 
jQuery(function($) {
  jQuery('a[href*="#"]:not([href="#"])').click(function() {
	  if($(this).closest('.wc-tabs').length){
		 // console.log('aaa');
		  //return false;
	  }else{
		 // console.log('bbb');
		   if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
		  var target = jQuery(this.hash);
		  target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
		if (target.length) {
			jQuery('html, body').animate({
			  scrollTop: target.offset().top - 60
			}, 1000);
			return false;
		  }
		}
	  }
   
  });
});

//go to id 


/* $('.popup_image_top').each(function() { // the containers for all your galleries
    $(this).magnificPopup({
        delegate: 'a', // the selector for gallery item
        type: 'image',
        gallery: {
          enabled:true
        },

    });
}); */



/*gallery magnific*/
function iniate_gal_pop (){
    if($('.pop_gal_portf').length){
         $('.pop_gal_portf').each(function() { // the containers for all your galleries
    $(this).magnificPopup({
        delegate: 'a', // the selector for gallery item
        type: 'image',
        image: {
       titleSrc: function(item) {
          return item.el.find('img').attr('title');
       }
   },
        gallery: {
          enabled:true
        },

    });
});
    }
}
/*gallery magnific*/

jQuery(window).on("resize load",function(e){
    iniate_gal_pop();
});



$('.gallery').magnificPopup({type:'image',
	 delegate: 'a', // the selector for gallery item
        type: 'image',
        gallery: {
        enabled:true
   },
});

//validate example code multiple forms on page
$('.mailchimp_frm').each(function () {
	var id_form = $(this).attr('id');
	
	var url_submit = theme_path+'/add_funnel.php';
	
	$(this).validate({
		rules: {
			email: {	required: true,	email: true	},
			//your_name: {	required: true	}
		},
		messages: {				 
			email: "E-mail field is invalid."
		},
		submitHandler: function(form) {
		
		jQuery.ajax({
			type: 'POST',
			url: url_submit,
			data: $('#'+id_form).serialize(),
			success: function(data) {
				var mydata= jQuery.parseJSON(data);
				// alert(mydata.raspuns);
				$('#'+id_form).find(".msg_form_home").hide();
				$('#'+id_form).find(".msg_form_home").show();
				$('#'+id_form).find(".msg_form_home").html(mydata.raspuns);
				setTimeout(function(){
					$('#'+id_form).find(".msg_form_home").hide();
					$('#'+id_form).find(".msg_form_home").html('');
				},6000); 
				$('#'+id_form)[0].reset();
				
			}
		});	
			return false;			
		}
	});
});
//validate example code multiple forms on page


//gallewry carousel
//.gallery_row .gallery-columns-4

//slider related posts
if($('.gallery_row .gallery').length){
    $('.gallery_row .gallery').slick({
		slidesToShow: 4,
		slidesToScroll: 1,
		dots: false,
		arrows: false,
		focusOnSelect: true,
		speed: 1000,
		autoplay: true,
		autoplaySpeed:3000,
	    responsive: [
		{
		  breakpoint: 1023,
		  settings: {
			slidesToShow: 2,
		
		  }
		},
		{
		  breakpoint: 400,
		  settings: {
			slidesToShow: 1,
		
		  }
		},

	  ]
});

}
// testimonial slider
if($('.row_all_testimonials').length){
$('.row_all_testimonials').slick({
	 arrows:true,
	 dots:true,
	  fade: false,
	  focusOnSelect:true,
	  slidesToShow: 1,
	  slidesToScroll: 1,
	  infinite: true,
	  autoplay:true,
	  autoplaySpeed:9500,
	prevArrow:'<div class="slick_prev_slider slick-arrow"><img src="'+theme_path+'/img/prev_ar.png" /></div>',
	nextArrow:'<div class="slick_next_slider slick-arrow"><img src="'+theme_path+'/img/next_ar.png" /></div>',
	
});
}


// slider partners
if($('.content_partners').length){
    $('.content_partners').slick({
		slidesToShow: 4,
		slidesToScroll: 1,
		dots: false,
		arrows: false,
		focusOnSelect: true,
		speed: 1000,
		autoplay: true,
		autoplaySpeed:3000,
	    responsive: [
		{
		  breakpoint: 1023,
		  settings: {
			slidesToShow: 3,
		
		  }
		},
		{
		  breakpoint: 400,
		  settings: {
			slidesToShow: 2,
		
		  }
		},

	  ]
});

}

/*
(function ($) {

    $(document).on('click', '.single_add_to_cart_button', function (e) {
        e.preventDefault();

        var $thisbutton = $(this),
                $form = $thisbutton.closest('form.cart'),
                id = $thisbutton.val(),
                product_qty = $form.find('input[name=quantity]').val() || 1,
                product_id = $form.find('input[name=product_id]').val() || id,
                variation_id = $form.find('input[name=variation_id]').val() || 0;

        var data = {
            action: 'woocommerce_ajax_add_to_cart',
            product_id: product_id,
            product_sku: '',
            quantity: product_qty,
            variation_id: variation_id,
        };

        $(document.body).trigger('adding_to_cart', [$thisbutton, data]);

        $.ajax({
            type: 'post',
            url: wc_add_to_cart_params.ajax_url,
            data: data,
            beforeSend: function (response) {
                $thisbutton.removeClass('added').addClass('loading');
            },
            complete: function (response) {
                $thisbutton.addClass('added').removeClass('loading');
            },
            success: function (response) {

                if (response.error && response.product_url) {
                    window.location = response.product_url;
                    return;
                } else {
                    $(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash, $thisbutton]);
                }
            },
        });

        return false;
    });
})(jQuery);
     * 
 */


});