(function($) {
    $.fn.reza_header = function() {


        if ($('[class*="rd-toolbar-"],header').hasClass('rd-sticky')) {
            var main_sticky = jQuery('.rd-sticky').offset().top + 100;

            function masthead_sticky(main_sticky) {
				
                var top = jQuery(window).scrollTop();
                var height_sticky = main_sticky;
                if (top > height_sticky) {
                    jQuery('.rd-sticky').addClass('rd-sticky-start');
                    jQuery('.rd-sticky').show(1, function() {
                        jQuery('.rd-sticky').addClass('rd-sticky-enable');

                         var wpadminbar_height = jQuery("#wpadminbar").height();
						if(wpadminbar_height!== undefined){
                        jQuery('.rd-sticky-enable').css({
                            "--rd-sticky-mg": wpadminbar_height + "px"
                        });
						}
                    });

                } else {

                    if ($('.rd-all-header').hasClass('rd-header-transparent')) {
                        jQuery('.rd-sticky').addClass('rd-nav-transparent');
                    }
                    


                    jQuery('.rd-sticky').css({
                        "--rd-sticky-mg": ""
                    });
                    jQuery('.rd-sticky').removeClass('rd-sticky-enable');
                    jQuery('.rd-sticky').removeClass('rd-sticky-start');


                }



            }
            $(window).on('scroll', function() {
                masthead_sticky(main_sticky);


            });

        }


        $('[class*="rd-nav"]  .rd-drop').parent().on({
            mouseenter: function() {
                var body_width = $('body').width();
                var boxed_width = $('.rd-body-boxed .rd-body-warp').width();
                var difference = (body_width - boxed_width) / 2;
                var ul_first = $(this).find('> .rd-drop');
                if ($.isNumeric(difference)) {
                    var right = ul_first.offset().left - difference;
                } else {
                    var right = ul_first.offset().left;
                }

                if (right < 0) {
                    ul_first.addClass('rd-menu-inverse').css({
                        '--rd-menu-rt': right + 'px'
                    });
                }
				ul_first.removeClass('rd-none-pointer');
 				
              },
            mouseleave: function() {
                var ul_first = $(this).find('> .rd-drop');
					ul_first.addClass('rd-not-pointer');
 	
                setTimeout(function() {
				ul_first.removeClass('rd-not-pointer');
 
                    ul_first.removeClass('rd-menu-inverse').css({
                        '--rd-menu-rt': ''
                    });
                }, 350);
             }
        });


        jQuery('.rd-nav-search[class*="-dropdown-"]').on("click", "li > a", function() {

            if (jQuery(this).parents('.rd-nav-search').hasClass('rd-nav-active')) {
                jQuery(this).parents('.rd-nav-search').removeClass('rd-nav-active');

            } else {
                jQuery(this).parents('.rd-nav-search').addClass('rd-nav-active');


            }
        });




        $(document).on('added_to_wishlist removed_from_wishlist', function() {
            var counter = $('.rd-nav-mobile-wish .rd-count,.rd-nav-wish .rd-count span');

            $.ajax({
                url: yith_wcwl_l10n.ajax_url,
                data: {
                    action: 'yith_wcwl_update_wishlist_count'
                },
                dataType: 'json',
                success: function(data) {
                    counter.html(data.count);
                },
                beforeSend: function() {
                    counter.block();
                },
                complete: function() {
                    counter.unblock();
                }
            })
        });


        jQuery(document).on("click", ".rd-nav-cat-menu > li > a", function() {
            if (jQuery(this).parents('.rd-nav-cat-menu').hasClass('rd-cat-active')) {
                jQuery(this).parents('.rd-nav-cat-menu').removeClass('rd-cat-active');
            } else {
                jQuery(this).parents('.rd-nav-cat-menu').addClass('rd-cat-active');

            }
        });

          jQuery(document).on("keyup", ".rd-search input", function() {
 			var val = $(this).val();
	 		 var data_val= $(this).attr('data-search');
		
			if(val !== data_val){	
				var data_key = Math.floor(Math.random() * 9999999999);
	
				var product_cat = $(this).parent().find('select').val();
				
				var element = $(this).parents('.rd-nav-search');
				var search_ajax = element.find('.rd-search-ajax');
				search_ajax.attr('data-key',data_key);
				search_ajax.find('.rd-el-search-ajax').remove();
				$(this).attr('data-search',val);
	
	
	
				if(val !== ''){
					
					search_ajax.addClass('rd-ajax-loading');
					$('body').addClass('rd-search-ajax-show');
					var dataajax = {};
					dataajax['action'] = 'reza_search_ajax';
					dataajax['search'] = val;
					dataajax['cats'] = product_cat;
						 
						 
						 
					setTimeout(function(){  
					if(search_ajax.attr('data-key') ==data_key){
						$.ajax({
							type: "POST",
							dataType: "html",
							url: reza_js.ajaxurl,
							data: dataajax,
							success: function(data) {
								var $data = $(data);
								search_ajax.find('.rd-el-search-ajax').remove();
								if ($data.length) {
										 
									element.find('.rd-search-ajax[data-key="'+data_key+'"]').append($data);
								}
								element.find('.rd-search-ajax[data-key="'+data_key+'"]').removeClass('rd-ajax-loading');
				 
							},
							error: function(jqXHR, textStatus, errorThrown) {
									$loader.html(jqXHR + " :: " + textStatus + " :: " + errorThrown);
							}
						});
					}}, 500); 
		
				}else{
					$('body').removeClass('rd-search-ajax-show');
					search_ajax.removeClass('rd-ajax-loading');
		
						
				}
			}

        });
 		
		
        jQuery(document).on("click",function (event) {
	  		if ($(event.target).closest(".rd-search-ajax,.rd-search").length === 0) {
				$('.rd-search-ajax').removeClass('rd-ajax-loading ');
				$('body').removeClass('rd-search-ajax-show');
 				$('.rd-search-ajax').find('.rd-el-search-ajax').remove();
			}
		});

		jQuery(document).on("click",'.rd-search-ajax-close',function () {
			var element = $(this).parents('[class*="-search-fixed-"]');
			var search_ajax = element.find('.rd-search-ajax');
			$('body').removeClass('rd-search-ajax-show');
			search_ajax.removeClass('rd-ajax-loading');
		 });
		
		 		
		
		 
		  $('.rd-element-menu').parents('[class*="sao-col-"],[class*="sao-sc-"],.elementor-element,.elementor-widget-wrap').each(function(index, element) {
               
				$(this).addClass('z-index');
 				
             
           
        });

		
		
		
	$('.rd-element-menu').each(function(index, element) {
 		var number = jQuery(this).attr('data-number');
		var number2 = parseInt(number);
		
  		 if(isNaN(number2)){} else{
				var count = jQuery(this).find('.rd-cat-drop > li').length;
     			if( number2  >= count){
					$(this).find('.rd-element-menu-more').remove();
				}else{
					$(this).addClass('rd-element-menu-has-more');

					$(this).find('.rd-cat-drop > li:nth-child(1n+'+number+')').each(function() {	
						 $(this).hide(0);
					});
				}
  		}
  			
 	});  
		
		
		
		

	jQuery(document).on("click", ".rd-element-menu-more" , function(){
   		var number = jQuery(this).parents('.rd-element-menu').attr('data-number');
		var number2 = parseInt(number);
		if(isNaN(number2)){} else{
			 
			var height = jQuery(this).parents('.rd-element-menu-warp').height();
				
			
			if(jQuery(this).parents('.rd-element-menu').hasClass('rd-element-menu-more-active')){
	 				 
					jQuery(this).parents('.rd-element-menu').find('.rd-cat-drop > li:nth-child(1n+'+number+')').each(function(index, block) {	
						$(this).slideUp( 500, function() {
							 jQuery(this).parents('.rd-element-menu-warp').attr('style','');
							jQuery(this).parents('.rd-element-menu').removeClass('rd-element-menu-more-active');
	
						});
					 });
		 
				
			} else{ 
				jQuery(this).parents('.rd-element-menu').addClass('rd-element-menu-more-active');
				jQuery(this).parents('.rd-element-menu-warp').height(height);
				jQuery(this).parents('.rd-element-menu').find('.rd-cat-drop > li:nth-child(1n+'+number+')').each(function(index, block) {	
		  
						
					$(this).slideDown( 500, function() {
						$(this).show(0);
					 });
				});	
			
			 } 
			 
			
			 
		 }
		 
		
  	});  
	 		
		
		
    };
}(jQuery));