jQuery(function ($) {
	"use strict";

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

function home_electrician_resmenu() {

	/* First and last elements in the menu */
	var home_electrician_first_tab = jQuery('.main-menu-navigation ul:first li:first a');
	var home_electrician_last_tab = jQuery('.sidebar .closebtn');

	jQuery(".resToggle").click(function (e) {
		e.preventDefault();
		e.stopPropagation();
		jQuery('body').addClass("mobilemenu-open");
		home_electrician_first_tab.focus();
	});

	jQuery(".sidebar .closebtn").click(function (e) {
		e.preventDefault();
		e.stopPropagation();
		jQuery('body').removeClass("mobilemenu-open");
		jQuery(".resToggle").focus();
	});

	/* Redirect last tab to first input */
	home_electrician_last_tab.on('keydown', function (e) {
		if (
			jQuery('body').hasClass('mobilemenu-open') &&
			e.which === 9 &&
			!e.shiftKey
		) {
			e.preventDefault();
			home_electrician_first_tab.focus();
		}
	});

	/* Redirect first shift+tab to last input */
	home_electrician_first_tab.on('keydown', function (e) {
		if (
			jQuery('body').hasClass('mobilemenu-open') &&
			e.which === 9 &&
			e.shiftKey
		) {
			e.preventDefault();
			home_electrician_last_tab.focus();
		}
	});

	/* Allow escape key to close menu */
	jQuery('.sidebar').on('keyup', function (e) {
		if (
			jQuery('body').hasClass('mobilemenu-open') &&
			e.keyCode === 27
		) {
			jQuery('body').removeClass('mobilemenu-open');
			home_electrician_last_tab.focus();
		}
	});
}

jQuery(document).ready(function () {
	home_electrician_resmenu();
});

(function ($) {

	$(window).scroll(function () {
		var sticky = $('.sticky-menubox'),
			scroll = $(window).scrollTop();

		if (scroll >= 100) {
			sticky.addClass('fixed-menubox');
		} else {
			sticky.removeClass('fixed-menubox');
		}
	});

})(jQuery);

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

	// Set up common variables.
	var home_electrician_bar = ".search_bar";
	var home_electrician_input = home_electrician_bar + " input[type='text']";
	var home_electrician_button = home_electrician_bar + " button[type='submit']";
	var home_electrician_dropdown = home_electrician_bar + " .search_dropdown";
	var home_electrician_dropdown_label = home_electrician_dropdown + " > span";
	var home_electrician_dropdown_list = home_electrician_dropdown + " ul";
	var home_electrician_dropdown_list_items = home_electrician_dropdown_list + " li";

	function home_electrician_resize_elements() {

		var home_electrician_bar_width = $(home_electrician_bar).outerWidth();

		var home_electrician_label_width = $(home_electrician_dropdown_label).outerWidth();
		$(home_electrician_dropdown).width(home_electrician_label_width);

		var home_electrician_dropdown_width = $(home_electrician_dropdown).outerWidth();
		var home_electrician_button_width = $(home_electrician_button).outerWidth();
		var home_electrician_input_width = home_electrician_bar_width - home_electrician_dropdown_width - home_electrician_button_width;
		var home_electrician_input_width_percent = (home_electrician_input_width / home_electrician_bar_width * 100) + "%";

		$(home_electrician_input).css({
			'margin-left': home_electrician_dropdown_width,
			'width': home_electrician_input_width_percent
		});
	}

	function home_electrician_dropdown_on() {
		$(home_electrician_dropdown_list).fadeIn(25);
		$(home_electrician_dropdown).addClass("active");
	}

	function home_electrician_dropdown_off() {
		$(home_electrician_dropdown_list).fadeOut(25);
		$(home_electrician_dropdown).removeClass("active");
	}

	// Initialize.
	home_electrician_resize_elements();

	$(home_electrician_dropdown).click(function (event) {

		if ($(home_electrician_dropdown).hasClass("active")) {
			home_electrician_dropdown_off();
		} else {
			home_electrician_dropdown_on();
		}

		event.stopPropagation();
		return false;
	});

	$("html").click(home_electrician_dropdown_off);

	$(home_electrician_dropdown_list_items).click(function () {

		$(this).siblings("li.selected").removeClass("selected");
		$(this).addClass("selected");

		$(this).parents("form.search_bar:first").find("input[type=text]").focus();

		var home_electrician_label_text = $(this).text();

		$(home_electrician_dropdown_label).text(home_electrician_label_text);

		home_electrician_resize_elements();
	});

	$(window).resize(function () {
		home_electrician_resize_elements();
	});

});

// Services script.
document.addEventListener("DOMContentLoaded", function () {

	const homeElectricianBoxes = document.querySelectorAll('.single-service-bx');
	let homeElectricianActiveBox = null;

	// Set second box active by default.
	if (homeElectricianBoxes.length > 1) {
		homeElectricianBoxes[1].classList.add('active');
		homeElectricianActiveBox = homeElectricianBoxes[1];
	}

	homeElectricianBoxes.forEach(function (homeElectricianBox) {

		// Click → permanently change active.
		homeElectricianBox.addEventListener('click', function () {

			homeElectricianBoxes.forEach(function (homeElectricianItem) {
				homeElectricianItem.classList.remove('active');
			});

			homeElectricianBox.classList.add('active');
			homeElectricianActiveBox = homeElectricianBox;
		});

		// Hover → temporarily remove active.
		homeElectricianBox.addEventListener('mouseenter', function () {

			homeElectricianBoxes.forEach(function (homeElectricianItem) {
				homeElectricianItem.classList.remove('active');
			});

		});

		// Leave → restore previously active box.
		homeElectricianBox.addEventListener('mouseleave', function () {

			if (homeElectricianActiveBox) {
				homeElectricianActiveBox.classList.add('active');
			}

		});

	});

});