// menus 
function commercial_automation_services_menu_open_nav() {
	window.commercial_automation_services_responsiveMenu=true;
	jQuery(".sidenav").addClass('show');
}
function commercial_automation_services_menu_close_nav() {
	window.commercial_automation_services_responsiveMenu=false;
 	jQuery(".sidenav").removeClass('show');
}
jQuery(function($){
 	"use strict";
 	jQuery('.main-menu > ul').superfish({
		delay: 500,
		animation: {opacity:'show',height:'show'},
		speed: 'fast'
 	});
});

jQuery(document).ready(function () {
	window.commercial_automation_services_currentfocus=null;
  	commercial_automation_services_checkfocusdElement();
	var commercial_automation_services_body = document.querySelector('body');
	commercial_automation_services_body.addEventListener('keyup', commercial_automation_services_check_tab_press);
	var commercial_automation_services_gotoHome = false;
	var commercial_automation_services_gotoClose = false;
	window.commercial_automation_services_responsiveMenu=false;
 	function commercial_automation_services_checkfocusdElement(){
	 	if(window.commercial_automation_services_currentfocus=document.activeElement.className){
		 	window.commercial_automation_services_currentfocus=document.activeElement.className;
	 	}
 	}
 	function commercial_automation_services_check_tab_press(e) {
		"use strict";
		// pick passed event or global event object if passed one is empty
		e = e || event;
		var activeElement;

		if(window.innerWidth < 999){
		if (e.keyCode == 9) {
			if(window.commercial_automation_services_responsiveMenu){
			if (!e.shiftKey) {
				if(commercial_automation_services_gotoHome) {
					jQuery( ".main-menu ul:first li:first a:first-child" ).focus();
				}
			}
			if (jQuery("a.closebtn.mobile-menu").is(":focus")) {
				commercial_automation_services_gotoHome = true;
			} else {
				commercial_automation_services_gotoHome = false;
			}

		}else{

			if(window.commercial_automation_services_currentfocus=="responsivetoggle"){
				jQuery( "" ).focus();
			}}}
		}
		if (e.shiftKey && e.keyCode == 9) {
		if(window.innerWidth < 999){
			if(window.commercial_automation_services_currentfocus=="header-search"){
				jQuery(".responsivetoggle").focus();
			}else{
				if(window.commercial_automation_services_responsiveMenu){
				if(commercial_automation_services_gotoClose){
					jQuery("a.closebtn.mobile-menu").focus();
				}
				if (jQuery( ".main-menu ul:first li:first a:first-child" ).is(":focus")) {
					commercial_automation_services_gotoClose = true;
				} else {
					commercial_automation_services_gotoClose = false;
				}

			}else{

			if(window.commercial_automation_services_responsiveMenu){
			}}}}
		}
	 	commercial_automation_services_checkfocusdElement();
	}
});

jQuery('document').ready(function($){
	// preloader
  setTimeout(function () {
		jQuery("#preloader").fadeOut("slow");
  },1000);

  // Sticky Header
  $(window).scroll(function(){
		var sticky = $('.header-sticky'),
			scroll = $(window).scrollTop();

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

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

  var scrollTop = window.scrollY || document.documentElement.scrollTop;
  var windowHeight = window.innerHeight;
  var documentHeight = document.documentElement.scrollHeight;

  var isBottom = scrollTop + windowHeight >= documentHeight-100;

  if (scrollTop >= 100 && !isBottom) {
    sticky.classList.add('copyright-fixed');
  } else {
    sticky.classList.remove('copyright-fixed');
  }
});

// Scroller
jQuery(document).ready(function () {
	jQuery(window).scroll(function () {
    if (jQuery(this).scrollTop() > 100) {
      jQuery('.scrollup i').fadeIn();
    } else {
      jQuery('.scrollup i').fadeOut();
    }
	});
	jQuery('.scrollup i').click(function () {
    jQuery("html, body").animate({
      scrollTop: 0
    }, 600);
    return false;
	});
});

// search product
jQuery(document).ready(function () {
  	function commercial_automation_services_search_loop_focus(element) {
	  var commercial_automation_services_focus = element.find('select, input, textarea, button, a[href]');
	  var commercial_automation_services_firstFocus = commercial_automation_services_focus[0];  
	  var commercial_automation_services_lastFocus = commercial_automation_services_focus[commercial_automation_services_focus.length - 2];
	  var KEYCODE_TAB = 9;

	  element.on('keydown', function commercial_automation_services_search_loop_focus(e) {
	    var isTabPressed = (e.key === 'Tab' || e.keyCode === KEYCODE_TAB);
	    if (!isTabPressed) { 
	      return; 
	    }
	    if ( e.shiftKey ) /* shift + tab */ {
	      if (document.activeElement === commercial_automation_services_firstFocus) {
	        commercial_automation_services_lastFocus.focus();
	          e.preventDefault();
	        }
	      } else /* tab */ {
	      if (document.activeElement === commercial_automation_services_lastFocus) {
	        commercial_automation_services_firstFocus.focus();
	          e.preventDefault();
	        }
	      }
	  });
	}
	jQuery('.search-box span a').click(function(){
	  jQuery(".serach_outer").slideDown(1000);
		commercial_automation_services_search_loop_focus(jQuery('.serach_outer'));
  });
  jQuery('.closepop a').click(function(){
    jQuery(".serach_outer").slideUp(1000);
  });
});

// tabend

jQuery(document).ready(function(){
    var commercial_automation_services_mydate =jQuery('.date').val();
  	jQuery(".countdown").each(function(){
      	commercial_automation_services_countdown(jQuery(this),commercial_automation_services_mydate);
  	});
});

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

  var scrollTop = window.scrollY || document.documentElement.scrollTop;
  var windowHeight = window.innerHeight;
  var documentHeight = document.documentElement.scrollHeight;

  var isBottom = scrollTop + windowHeight >= documentHeight-100;

  if (scrollTop >= 100 && !isBottom) {
    sticky.classList.add('sidebar-fixed');
  } else {
    sticky.classList.remove('sidebar-fixed');
  }
});

function commercial_automation_services_countdown($timer,commercial_automation_services_mydate){
  // Set the date we're counting down to
  var commercial_automation_services_countDownDate = new Date(commercial_automation_services_mydate).getTime();
  // Update the count down every 1 second
  var x = setInterval(function() {
    // Get todays date and time
    var now = new Date().getTime();
    // Find the distance between now an the count down date
    var distance = commercial_automation_services_countDownDate - now;
    // Time calculations for days, hours, minutes and seconds
    var days = Math.floor(distance / (1000 * 60 * 60 * 24));
    var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);
    // Output the result in an element with id="timer"
    $timer.html( "<div class='numbers'><span class='count1'>" + days + "</span><span class='text'>Days</span>" + "</div>" + "   " +"<div class='numbers'><span class='count1'>" + hours + "</span><span class='text'>Hrs</span>" + "</div>" + "   " + "<div class='numbers'><span class='count1'>" + minutes + "</span><span class='text'>Mins</span>" + "</div>" + "   " + "<div class='numbers'><span class='count1'>" + seconds + "</span><span class='text'>Sec</spn" + "</div>");

    // If the count down is over, write some text
    if (distance < 0) {
        clearInterval(x);
        $timer.html("EXPIRED");
    }
  }, 1000);
}

// Product section
jQuery('document').ready(function(){
  var owl = jQuery('#main-product .owl-carousel');
    owl.owlCarousel({
    margin:20,
    autoplayTimeout: 90000,
    loop: true,
    dots:false,
    autoplay : true,
	autoplayTimeout: 90000,
    nav:false,
    navText : ['<i class="fa fa-chevron-left" aria-hidden="true"></i>','<i class="fa fa-chevron-right" aria-hidden="true"></i>'],
    responsive: {
      0: {
        items: 1,
      },
      600: {
        items: 2
      },
      1024: {
        items: 3,
        margin:10
      },
      1200: {
        items: 4,
        margin:10,
      }
    },
    autoplayHoverPause : true,
    mouseDrag: true
  });
});
/* Progress Bar */
document.addEventListener("DOMContentLoaded", function () {
	const commercial_automation_services_progressBar =
		document.getElementById("commercial_automation_services_elemento_progress_bar");
	if (!commercial_automation_services_progressBar) return;
	window.addEventListener("scroll", function () {
		const commercial_automation_services_scrollTop =
			document.documentElement.scrollTop || document.body.scrollTop;
		const commercial_automation_services_height =
			document.documentElement.scrollHeight -
			document.documentElement.clientHeight;
		const commercial_automation_services_scrolled =
			(commercial_automation_services_scrollTop / commercial_automation_services_height) * 100;
		commercial_automation_services_progressBar.style.width =
			commercial_automation_services_scrolled + "%";
	});
});