jQuery("#searchShow").click(function($){
  jQuery(".searchBar").toggle();
  console.log(jQuery(".top-header").hasClass("searchWrap"));
  if(jQuery(".top-header").hasClass("searchWrap")) {
  	jQuery(".top-header").removeClass("searchWrap");
  }else {
  	jQuery(".top-header").addClass("searchWrap");
  }
  

jQuery(".searchClickHide").toggle();
});
jQuery("#searchHide").click(function($){
  jQuery(".searchBar").toggle();
  jQuery(".top-header").removeClass("searchWrap");
  jQuery(".searchClickHide").toggle();
});


/* Home Service Carousal Script */
jQuery('.related_carousal').slick({
  dots: false,
  infinite: false,
  arrows: true,
  speed: 300,
  slidesToShow: 3,
  slidesToScroll: 1,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 767,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1,
        dots: true
      }
    },
    {
      breakpoint: 480,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1,
        dots: true
      }
    }
  ]
});



/* Home Articles Carousal Script */
jQuery('.front_articles_carousal').slick({
  dots: false,
  infinite: false,
  arrows: true,
  speed: 300,
  slidesToShow: 3,
  slidesToScroll: 1,
  autoplay: true,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 767,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1,
        dots: true
      }
    },
    {
      breakpoint: 480,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1,
        dots: true
      }
    }
  ]
});

/**** Ajax for Reesource Starts here ***/
var offst = '2';
jQuery( document ).on( 'click', '#loadResourceBtn', function(e) {
  e.preventDefault();
  
  var ajax_url = jQuery('#ajax_url').val();
  jQuery.ajax({

    url : ajax_url,
    dataType: "json",
    type : 'post',
    data : {
      action : 'resource_post_load_more',
      offset : offst
    },
    success : function( response ) {
      
      if(response[1] > 6) {
        
        jQuery('#loadAjaxContent').append(response[0]);
        offst++;
      } else {
        
        jQuery(".loadmore_div").css('display','none');
        jQuery('#loadAjaxContent').append(response[0]);
        offst++;
      }
      
    },
    error: function (jqXhr, textStatus, errorMessage) { // error callback 
      console.log('insie');
    }
  });


})

/****************************************************************/

/**** Ajax for Article Starts here ***/
	var ajax_url = jQuery('#ajax_url').val();
	var limit = 5;
	var cat_id = localStorage.getItem('cat_id');
	var total = localStorage.getItem('total');
	if(cat_id){
		cat_id = cat_id;
	}
	else{
		cat_id = '';
	}
	jQuery('body').on('click', '#loadArticleBtn', function(e) {
		e.preventDefault();
		jQuery.ajax({
			url:  ajax_url,
			data: {'action':'article_post_load_more','limit': limit, 'cat_id' : cat_id}, 
			type: 'POST',           
			success: function (data) {
				var result = JSON.parse(data);
               
				jQuery("#loadAjaxContent").append(result.articles);
				if(limit+3 >= total)
				{					
					jQuery("#loadArticleBtn").remove();
				}
				limit = parseInt(limit) + parseInt(3);
			}
		});	
	});


/* var offst = '3';
jQuery( document ).on( 'click', '#loadArticleBtn', function(e) {
  e.preventDefault();
  
  var ajax_url = jQuery('#ajax_url').val();
  jQuery.ajax({

    url : ajax_url,
    dataType: "json",
    type : 'post',
    data : {
      action : 'article_post_load_more',
      offset : offst
    },
    success : function( response ) {
      
      if(response[1] > 4) {
        
        jQuery('#loadAjaxContent').append(response[0]);
        offst++;
      } else {
        
        jQuery(".loadmore_div").css('display','block');
        jQuery('#loadAjaxContent').append(response[0]);
        offst++;
      }
      
    },
    error: function (jqXhr, textStatus, errorMessage) {
      console.log('insie');
    }
  });


}); */

/****************************************************************/

/* Mobile Collapsable accordian menu Scripts */

( function( $ ) {
jQuery( document ).ready(function() {
jQuery('#at__mob_menu li.menu-item-has-children>a').on('click', function(){
    jQuery(this).removeAttr('href');
    var element = jQuery(this).parent('li');
    if (element.hasClass('open')) {
      element.removeClass('open');
      element.find('li').removeClass('open');
      element.find('ul').slideUp();
    }
    else {
      element.addClass('open');
      element.children('ul').slideDown();
      element.siblings('li').children('ul').slideUp();
      element.siblings('li').removeClass('open');
      element.siblings('li').find('li').removeClass('open');
      element.siblings('li').find('ul').slideUp();
    }
  });

  jQuery('#at__mob_menu>ul>li.has-sub>a').append('<span class="holder"></span>');

  (function getColor() {
    var r, g, b;
    var textColor = jQuery('#at__mob_menu').css('color');
    textColor = textColor.slice(4);
    r = textColor.slice(0, textColor.indexOf(','));
    textColor = textColor.slice(textColor.indexOf(' ') + 1);
    g = textColor.slice(0, textColor.indexOf(','));
    textColor = textColor.slice(textColor.indexOf(' ') + 1);
    b = textColor.slice(0, textColor.indexOf(')'));
    var l = rgbToHsl(r, g, b);
    if (l > 0.7) {
      jQuery('#at__mob_menu>ul>li>a').css('text-shadow', '0 1px 1px rgba(0, 0, 0, .35)');
      jQuery('#at__mob_menu>ul>li>a>span').css('border-color', 'rgba(0, 0, 0, .35)');
    }
    else
    {
      jQuery('#at__mob_menu>ul>li>a').css('text-shadow', '0 1px 0 rgba(255, 255, 255, .35)');
      jQuery('#at__mob_menu>ul>li>a>span').css('border-color', 'rgba(255, 255, 255, .35)');
    }
  })();

  function rgbToHsl(r, g, b) {
      r /= 255, g /= 255, b /= 255;
      var max = Math.max(r, g, b), min = Math.min(r, g, b);
      var h, s, l = (max + min) / 2;

      if(max == min){
          h = s = 0;
      }
      else {
          var d = max - min;
          s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
          switch(max){
              case r: h = (g - b) / d + (g < b ? 6 : 0); break;
              case g: h = (b - r) / d + 2; break;
              case b: h = (r - g) / d + 4; break;
          }
          h /= 6;
      }
      return l;
  }
});
} )( jQuery );

/* Mobile Sidebar Scripts */
function openNav() {
    document.getElementById("CRSSidenav").style.width = "230px";
}
function closeNav() {
    document.getElementById("CRSSidenav").style.width = "0";
    
}
jQuery("#openNavBtn").on('click',function(){
  jQuery(".mob-menu-click").removeClass('show-hide-menu'); 
  jQuery(this).addClass('show-hide-menu');
});

jQuery("#closeNavBtn").on('click',function(){
  jQuery(".mob-menu-click").removeClass('show-hide-menu'); 
  jQuery(this).addClass('show-hide-menu');
});



jQuery( document ).ready(function($) {
 var shrinkHeader = 155;
  $(window).scroll(function() {
    var scroll = getCurrentScroll();
      if ( scroll >= shrinkHeader ) {
           $('.hk-header').addClass('shrink');
        }
        else {
            $('.hk-header').removeClass('shrink');
        }
  });
  
function getCurrentScroll() {
    return window.pageYOffset || document.documentElement.scrollTop;
    }
});

jQuery( document ).ready(function($) {
 var shrinkHeader = 250;
  $(window).scroll(function() {
    var scroll = getCurrentScroll();
      if ( scroll >= shrinkHeader ) {
           $('.hk-header').addClass('shrink1');
        }
        else {
            $('.hk-header').removeClass('shrink1');
        }
  });
  
function getCurrentScroll() {
    return window.pageYOffset || document.documentElement.scrollTop;
    }
});

/**Password Toggle show/hide script ( password and password repeat field )**/

          /* Register Page*/
  jQuery(document).ready(function(){
  jQuery('#passw1').after('<span toggle="#passw1" class="toggle-password"></span>');
  jQuery("#passw2").after('<span toggle="#passw2" class="toggle-password-repeat"></span>');
  jQuery("#user_pass").after('<span toggle="#user_pass" class="toggle-password-login"></span>');

  jQuery(document).on('click','.toggle-password' , function() {
  //alert('clicked');
  jQuery(this).toggleClass("toggle-remove");
  var input = jQuery(this).attr("toggle");
  //console.log(input);
  if (jQuery(input).attr("type") == "password") {
    jQuery(input).attr("type", "text");
  } else {
    jQuery(input).attr("type", "password");
  }

});

  jQuery(document).on('click','.toggle-password-repeat' , function() {
  //alert('clicked');
  jQuery(this).toggleClass("toggle-remove-repeat");
  var input = jQuery(this).attr("toggle");
  //console.log(input);
  if (jQuery(input).attr("type") == "password") {
    jQuery(input).attr("type", "text");
  } else {
    jQuery(input).attr("type", "password");
  }

});

  /*Login page password toggle*/

  jQuery(document).on('click','.toggle-password-login' , function() {
  //alert('clicked');
  jQuery(this).toggleClass("toggle-remove-login");
  var input = jQuery(this).attr("toggle");
  //console.log(input);
  if (jQuery(input).attr("type") == "password") {
    jQuery(input).attr("type", "text");
  } else {
    jQuery(input).attr("type", "password");
  }

});
 });


jQuery(document).ready(function(){
	jQuery(".es_subscription_form.es_shortcode_form .es-field-wrap").after('<div class="es-field-wrap terms-condition-text">By proceeding, you agree to our <a target="_blank" href="https://www.hongkongdivorce.com/privacy-policy/">Privacy Policy</a>.</br></br>  Please note that hongkongdivorce.com agrees to keep confidential any information provided by, or relating to the subscriber and will refrain from disclosing the same without the subscriber’s express permission to do so.  Please visit our <a target="_blank" href="https://www.hongkongdivorce.com/privacy-policy/">Privacy Policy</a> page for details.</div>');
	
});

jQuery(document).on('click', '.ap-btn-newcomment' , function(){
	//jQuery('#loader_image').show();
	setTimeout(function(){ 
		jQuery("#form_comment .ap-btn-submit").before('<div class="ap-form-group terms-condition-text">By proceeding, you agree to our <a target="_blank" href="https://www.hongkongdivorce.com/privacy-policy/">Privacy Policy</a>.</br></br>  Please note that hongkongdivorce.com agrees to keep confidential any information provided by, or relating to the subscriber and will refrain from disclosing the same without the subscriber’s express permission to do so.  Please visit our <a target="_blank" href="https://www.hongkongdivorce.com/privacy-policy/">Privacy Policy</a> page for details.</div>');
		jQuery('#form_comment').show();
		}, 700);
});

    
/*Subscribe newsletter plugin functionality script*/

jQuery(document).on('click', '.es_subscription_form_submit' , function(){
    
    var htmlstr = '<div class="es_spinner_image" id="spinner-image" style="display: inline;position: absolute;width: 100%;top: 80px;text-align: center;right: 0px;"><img src="https://www.hongkongdivorce.com/wp-content/plugins/email-subscribers/public/images/spinner.gif"></div>';  
    jQuery('.modal-form-title').hide();
    setTimeout(function(){ 
		if(jQuery(".es_subscription_message").hasClass('success')){
		  jQuery(".modal-body").append(htmlstr);		
			setTimeout(function(){ 
			  jQuery("div#spinner-image").remove();
			  jQuery('.modal-form-title').text('Great!');
			  jQuery('.modal-form-title').show();
			  //jQuery(".es_subscription_message").animate({opacity: 1}, "slow");
			  //jQuery('es_subscription_message').html(htmlstr).delay('500').;
			  jQuery(".es_subscription_message").addClass('great-success');
			  jQuery(".es_subscription_message").text('You have successfully subscribed to our newsletter');
			  jQuery(".es_subscription_message").animate({opacity: 1}, "slow");
			  //location.reload();
			  //jQuery(".es_subscription_message").css('opacity','1'); 
			}, 6000);
		}
	}, 2000);  
});



/*jQuery(document).ready(function(){
if(jQuery('.newsletter_form').find('es_subscription_form_submit')){
jQuery(".es_subscription_form_submit").on('click', function(){
//alert('clicked');
var htmlstr = '<div class="es_spinner_image" id="spinner-image" style="display: inline;position: absolute;width: 100%;top: 80px;text-align: center;right: 0px;"><img src="http://hkdivorce.yoshirodev.com/wp-content/plugins/email-subscribers/public/images/spinner.gif"></div>';  
//jQuery(".newsletter_form").find(".es_subscription_message")    
    jQuery('.modal-form-title').hide();
    setTimeout(function(){ 
    if(jQuery(".es_subscription_message").hasClass('success')){
      jQuery('.newsletter_form').append(htmlstr);  
      jQuery("div#spinner-image").remove();
      jQuery(".es_subscription_message").parent(".newsletter_form")
      jQuery(".es_subscription_message").text('You have successfully subscribed to our newsletter');
      jQuery(".es_subscription_message").animate({opacity: 1}, "slow");
      //jQuery(".es_subscription_message").css('opacity','1'); 
   }
}, 1000);

});
};
});
*/




