jQuery(function($){
	"use strict";
	jQuery('.main-menu-navigation > ul').superfish({
		delay:       500,
		animation:   {opacity:'show',height:'show'},  
		speed:       'fast'
	});
});

function handyman_cleaner_menu_open() {
	jQuery(".menu-brand.primary-nav").addClass('show');
}
function handyman_cleaner_menu_close() {
	jQuery(".menu-brand.primary-nav").removeClass('show');
}

var handyman_cleaner_Keyboard_loop = function (elem) {
    var handyman_cleaner_tabbable = elem.find('select, input, textarea, button, a').filter(':visible');

    var handyman_cleaner_firstTabbable = handyman_cleaner_tabbable.first();
    var handyman_cleaner_lastTabbable = handyman_cleaner_tabbable.last();
    /*set focus on first input*/
    handyman_cleaner_firstTabbable.focus();

    /*redirect last tab to first input*/
    handyman_cleaner_lastTabbable.on('keydown', function (e) {
        if ((e.which === 9 && !e.shiftKey)) {
            e.preventDefault();
            handyman_cleaner_firstTabbable.focus();
        }
    });

    /*redirect first shift+tab to last input*/
    handyman_cleaner_firstTabbable.on('keydown', function (e) {
        if ((e.which === 9 && e.shiftKey)) {
            e.preventDefault();
            handyman_cleaner_lastTabbable.focus();
        }
    });

    /* allow escape key to close insiders div */
    elem.on('keyup', function (e) {
        if (e.keyCode === 27) {
            elem.hide();
        }
        ;
    });
};

// scroll
jQuery(document).ready(function () {
	jQuery(window).scroll(function () {
	    if (jQuery(this).scrollTop() > 0) {
	        jQuery('#scrollbutton').fadeIn();
	    } else {
	        jQuery('#scrollbutton').fadeOut();
	    }
	});
	jQuery(window).on("scroll", function () {
	   document.getElementById("scrollbutton").style.display = "block";
	});
	jQuery('#scrollbutton').click(function () {
	    jQuery("html, body").animate({
	        scrollTop: 0
	    }, 600);
	    return false;
	});
});

jQuery(function($){
	$('.mobiletoggle').click(function () {
        handyman_cleaner_Keyboard_loop($('.menu-brand.primary-nav'));
    });
});

// preloader
jQuery(function($){
    setTimeout(function(){
        $(".frame").delay(1000).fadeOut("slow");
    });
});

jQuery('document').ready(function($){
    $('.main-search span a').click(function(){
        $(".searchform_page").slideDown(500);
        handyman_cleaner_Keyboard_loop($('.searchform_page'));
    });

    $('.close a').click(function(){
        $(".searchform_page").slideUp(500);
    });
}); 

/*sticky copyright*/
window.addEventListener('scroll', function() {
  var handyman_cleaner_sticky = document.querySelector('.copyright-sticky');
  if (!handyman_cleaner_sticky) return;

  var handyman_cleaner_scrollTop = window.scrollY || document.documentElement.scrollTop;
  var handyman_cleaner_windowHeight = window.innerHeight;
  var handyman_cleaner_documentHeight = document.documentElement.scrollHeight;

  var handyman_cleaner_isBottom = handyman_cleaner_scrollTop + handyman_cleaner_windowHeight >= handyman_cleaner_documentHeight - 100;

  if (handyman_cleaner_scrollTop >= 100 && !handyman_cleaner_isBottom) {
    handyman_cleaner_sticky.classList.add('copyright-fixed');
  } else {
    handyman_cleaner_sticky.classList.remove('copyright-fixed');
  }
});
/* Progress Bar */
document.addEventListener("DOMContentLoaded", function () {
    const handyman_cleaner_progressBar =
        document.getElementById("handyman_cleaner_elemento_progress_bar");
    if (!handyman_cleaner_progressBar) return;
    window.addEventListener("scroll", function () {
        const handyman_cleaner_scrollTop =
            document.documentElement.scrollTop || document.body.scrollTop;
        const handyman_cleaner_height =
            document.documentElement.scrollHeight -
            document.documentElement.clientHeight;
        const handyman_cleaner_scrolled =
            (handyman_cleaner_scrollTop / handyman_cleaner_height) * 100;
        handyman_cleaner_progressBar.style.width =
            handyman_cleaner_scrolled + "%";
    });
});