$(document).ready(function(){

	// Global Variables

		var toggle_primary_button = $('.nav_toggle_button'),
				toggle_primary_icon = $('.nav_toggle_button i'),
				toggle_secondary_button = $('.page_nav li span'),
				primary_menu = $('.page_nav'),
				secondary_menu = $('.page_nav ul ul'),
				webHeight = $(document).height(),
				window_width = $(window).width();

	// Company name and phone number on content area
	$("main * :not('h1')").not('.woocommerce *').each(function() {
		var regex1 = /(?![^<]+>)((\+\d{1,2}[\s.-])?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{6})/g;
		var regex2 = /(?![^<]+>)((\+\d{1,2}[\s.-])?\(?\d{3}\)?[\s.-]?\d{4}[\s.-]?\d{4})/g;
		var regex = /(?![^<]+>)((\+\d{1,2}[\s.-])?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4})/g;
				$(this).html(
						$(this).html()
						.replace(/AYA Enterprises/g, "<mark class='comp'>$&</mark>")					
						.replace(/AYA/g, "<mark class='comp'>$&</mark>")					
						.replace(regex1, "<mark class='main_phone'>$&</mark>").replace(regex2, "<mark class='main_phone'>$&</mark>").replace(regex, "<mark class='main_phone'>$&</mark>"));
		});

		$("main a[href]").each(function() {
		   var newHref = $(this).attr('href').replace("<mark class='comp'>", "").replace("</mark>", "");
			 $(this).attr('href', newHref);
		});

		// Forms on content area
		var form = $('main').find('#myframe');
			if(form.length > 0) {
			document.getElementById('myframe').onload = function(){
			  calcHeight();
			};
		}

	// Add class to tab having drop down
	$( ".page_nav li:has(ul)").find('span i').addClass("fa-caret-down");


	//Multi-line Tab
	toggle_secondary_button.click(function(){
		$(this).parent('li').siblings('li').children('ul').slideUp(400, function() {
			$(this).removeAttr('style');
		});

		$(this).parent('li').siblings('li').find('.fa').removeClass("fa-caret-up").addClass("fa-caret-down");

		$(this).parent('li').children('ul').slideToggle();
		$(this).children().toggleClass("fa-caret-up").toggleClass("fa-caret-down");
	});

	// Basic functionality for nav_toggle

	var hamburger = $(".hamburger");
    // hamburger.each(function(){
        // $(this).click(function(){
         // $(this).toggleClass("is-active");
        // });
      // });

	hamburger.click(function(){
		primary_menu.addClass('toggle_right_style');
		$('.toggle_right_nav').addClass('toggle_right_cont');
		$(".nav_toggle_button").toggleClass('active');
		$(".hamburger").toggleClass("is-active");
		$('body').addClass('active');
	});


	$('.toggle_nav_close, .menu_slide_right .hamburger').click(function(){
		primary_menu.removeClass('toggle_right_style');
		secondary_menu.removeAttr('style');
		toggle_secondary_button.children().removeClass("fa-caret-up").addClass("fa-caret-down");
		$('.toggle_right_nav').removeClass('toggle_right_cont');
		$(".nav_toggle_button").removeClass('active');
		$(".hamburger").removeClass("is-active");
		$('body').removeClass('active');
	});

	// Swap Elements
	function swap_this(){
		if(window_width <= 800){
			$('.main_logo').insertAfter('.logo_wrap');
			$('#nav_area').insertBefore('header');
		} else {
			$('.main_logo').insertBefore('.head_info');
			$('#nav_area').insertAfter('header');
		}
	}

	swap_this();

	// Reset all configs when width > 800
	$(window).resize(function(){
		window_width = $(this).width();

		swap_this();

		if(window_width > 800) {
			$(".nav_toggle_button").removeClass('active');
			$(".hamburger").removeClass("is-active");
			primary_menu.removeClass('toggle_right_style');
			$('.toggle_right_nav').removeClass('toggle_right_cont');
			$('body').removeClass('active');
		}
		else{
			secondary_menu.removeAttr('style');
			toggle_secondary_button.children().removeClass("fa-caret-up").addClass("fa-caret-down");
		}


	});

	$('.rslides').responsiveSlides();
	$('.box_skitter_large').skitter({
		theme: 'square',
		numbers_align: 'center',
		progressbar: false,
		navigation: true,
		numbers: false,
		dots: false,
		stop_over: false,
		preview: false,
		interval: 4000
	});

	$('.back_top').click(function () { // back to top
		$("html, body").animate({
			scrollTop: 0
		}, 900);
		return false;
	});

	$(window).scroll(function(){  // fade in fade out button
	var windowScroll = $(this).scrollTop();

		if (windowScroll > (webHeight * 0.5) && window_width <= 600 ) {
			$(".back_top").fadeIn();
		} else{
			$(".back_top").fadeOut()
		};

		// For (AddThis) Plugins
		if($('body #at-share-dock').hasClass('at-share-dock')) {
			$('.back_top').addClass('withAddThis_plugins');
			$('.footer_btm').addClass('withAddThis_ftr_btm');
		} else {
			$('.back_top').removeClass('withAddThis_plugins');
			$('.footer_btm').removeClass('withAddThis_ftr_btm');
		}
		// End (AddThis) Plugins

		//Backgrond Middle Fixed
		if ($('#middle').length >= 1) {
			var fixbtm = $('#middle').offset().top;
			if (fixbtm <= windowScroll){
				$("#middle").css({
					'background-attachment' : 'fixed',
					'background-size ' : 'auto'
				});
			} else {
					$("#middle").css({
					'background-attachment' : 'unset',
					'background-size ' : 'unset'
					});
				}
			}
		//End Middle Fixed

		//Header Fixed
		if($('#nav_area').length) {
			var section_fixed = $('#nav_area').offset().top;
			if (windowScroll > section_fixed && window_width > 1024){
				$('.page_nav').addClass('fixed_section');
			} else {
				$('.page_nav').removeClass('fixed_section');
			}
		}
		if($('header').length) {
			var section_fixed = $('header').offset().top;
			if (windowScroll > section_fixed && window_width > 1024){
				$('.main_logo').addClass('fixed_section2');
			} else {
				$('.main_logo').removeClass('fixed_section2');
			}
		}
		if($('header').length) {
			var section_fixed = $('header').offset().top;
			if (windowScroll > section_fixed && window_width > 1024){
				$('.head_info').addClass('fixed_section3');
			} else {
				$('.head_info').removeClass('fixed_section3');
			}
		}
		//End Header Fixed
	});

	$('.faq h6').click(function(){
		$(this).next().slideToggle()
	   .siblings('.faq div').slideUp();
	   //toggle sign
		$(this).toggleClass('sign')
		.siblings('.faq h6').removeClass();
	  });

	$('.nh_box').click(function (){

		var popupnumber = $(this).attr('id').split("-")[2];
		// console.log(popup);
		$('#show-popup'+popupnumber).fadeIn();



	});
	$(".pop_close").click(function() {
		$(".pop_card").css("display", "none");
	});

	$("#commentform").click(function(e){
		if ($('#author').val() == '') {
		$('#author').addClass( "testimonialreq" );
		e.preventDefault();
		} else {
		$('#author').removeClass( "testimonialreq" );
		}
		
		if ($('#email').val() == '') {
		$('#email').addClass( "testimonialreq" );
		e.preventDefault();
		} else {
		$('#email').removeClass( "testimonialreq" );
		}
		
		if ($('#comment').val() == '') {
		$('#comment').addClass( "testimonialreq" );
		e.preventDefault();
		} else {
		$('#comment').removeClass( "testimonialreq" );
		}
		
		});

		$('#submit_formmessage .form_btn_message').on('click', function(e){

			if ($('#submit_formmessage .form_fullname').val() == '') {
			$('#submit_formmessage .form_fullname').addClass( "FormReq" );
			e.preventDefault();
			}else{
			$('#submit_formmessage .form_fullname').removeClass( "FormReq" );
			}
		
			if ($('#submit_formmessage .form_email').val() == '') {
			$('#submit_formmessage .form_email').addClass( "FormReq" );
			e.preventDefault();
			}else{
			$('#submit_formmessage .form_email').removeClass( "FormReq" );
			}
		});

});

// 			if (fixbtm <= windowScroll){
// 				$("#middle").css({
// 					'background-attachment' : 'fixed'
// 				});
// 			} else {
// 					$("#middle").css({
// 					'background-attachment' : 'unset'
// 					});
// 			}

// 		//End Middle Fixed

// 		//Header Fixed
// 		if($('#nav_area').length) {
// 			var section_fixed = $('#nav_area').offset().top;
// 			if (windowScroll > section_fixed && window_width > 1024){
// 				$('.page_nav').addClass('fixed_section');
// 			} else {
// 				$('.page_nav').removeClass('fixed_section');
// 			}
// 		}
// 		if($('header').length) {
// 			var section_fixed = $('header').offset().top;
// 			if (windowScroll > section_fixed && window_width > 1024){
// 				$('.main_logo').addClass('fixed_section2');
// 			} else {
// 				$('.main_logo').removeClass('fixed_section2');
// 			}
// 		}
// 		if($('header').length) {
// 			var section_fixed = $('header').offset().top;
// 			if (windowScroll > section_fixed && window_width > 1024){
// 				$('.head_info').addClass('fixed_section3');
// 			} else {
// 				$('.head_info').removeClass('fixed_section3');
// 			}
// 		}
// 		//End Header Fixed
// 	});


// });
