;(function ($, window, document, undefined) {
	'use strict';

	/**
	 * write your codes here
	 */

	var w     = window,
			$w    = $(window),
			$body = $('body');

	 /** * mobile nav functionality
 	 */
 	var $mobileNav = $('.mobile-top-nav'),
			$closeNavBtn = $mobileNav.find('a.close-nav'),
			$openNavBtn = $('.nav-icon');

 	$openNavBtn.on('click', function (e) {
		e.preventDefault();
		$mobileNav.fadeIn(500);
	});
 	
	$closeNavBtn.on('click', function (e) {
		e.preventDefault();
		$mobileNav.fadeOut(500);
	});

	$mobileNav.on('click', '.has-submenu > a', function (e) {
		e.preventDefault();
		$(this).closest('li.has-submenu').toggleClass('active');
		$(this).siblings('ul').stop().slideToggle(500);
	});
	

	// approx_unit_size-other field disabled enabled
	$(document).ready(function(){
		$(".other-val").attr('disabled','disabled');
	});

	$("#approx_unit_size-other").on('click', function () {
		if ($(this).is(":checked")) {
			$("#approx_unit_size-other-value").removeAttr('disabled');
		} else {
			$("#approx_unit_size-other-value").attr('disabled','disabled');
		}
	});

	$("#approx_unit_size-0, #approx_unit_size-1, #approx_unit_size-2").on('click', function () {
		if ($(this).is(":checked")) {
			$("#approx_unit_size-other-value").attr('disabled','disabled');
		} else {
			$("#approx_unit_size-other-value").removeAttr('disabled');
		}
	});

		 
	// googlereviewsbutton js
	$('.vw-google-reviews').attr( 'id', 'googlereviews' );

	$(".home-review").on('click', function(e) {
		if (location.hash == $(this).attr('href')) {
			e.preventDefault();
			$w.trigger('custom.hashchange');
		}
	});

	var gotoSection = function () {
		var hash     = location.hash.replace('#__', '');
		
		if (location.hash.indexOf('#__') == -1) {
			return;
		}

		var $section = $('#' + hash);
		
		if (!$section.length) {
			return;
		}

		$('html, body').stop().animate({
			scrollTop: ($section.offset().top - 122)
		}, 1000);
	};

	$w.on('load hashchange custom.hashchange', function () {
		gotoSection();
	});


	//  header carousel 
	$('.owl-carousel').owlCarousel({
		loop:true,
		nav:false,
		animateOut: 'fadeOut',
		animateIn: 'fadeIn',
		dots: false,
		autoplay: true,
		center: true,
		// navText: ["<i class='fal fa-angle-left'></i>","<i class='fal fa-angle-right'></i>"],
		responsive:{
			0:{
				items:1,
				nav: false,
			},
			600:{
				items:1,
				nav: false,
			},
			1000:{
				items:1
			}
		}
	})

	
	// sticky header 
	// var $header = $('.header'),
	// 		headerHeight = $header.height(),
	// 		scrollTop = 0,
	// 		bodyStickyClass = 'has-sticky',
	// 		headerStickyClass = 'sticky-header';

	// $w.on('load scroll resize', function () {
	// 	scrollTop = $w.scrollTop();

	// 	if (scrollTop >= headerHeight && (!$body.hasClass(bodyStickyClass)) && (!$header.hasClass(headerStickyClass))) {
	// 		$body.addClass(bodyStickyClass).css('padding-top', headerHeight);
	// 		$header.addClass(headerStickyClass).css('top', -$header.height()).animate({
	// 			top: 0
	// 		}, 400);
	// 	}

	// 	if (scrollTop < headerHeight && $body.hasClass(bodyStickyClass) && $header.hasClass(headerStickyClass)) {
	// 		$body.removeClass(bodyStickyClass).css('padding-top', 0);
	// 		$header.css('top', 'auto').removeClass(headerStickyClass);
	// 	}
	// });


	     var $quicklinks    = $('.mob-quick-links'),
	         $quicklink     = null,
	         $quicklinkUl   = null,
	         $quicklinkLi   = null,
	         $quickDropdown = null;

	     $quicklinks.on('click', '.hasquickDropdown > a', function (e) {
	         e.preventDefault();
	         $quicklink     = $(this);
	         $quicklinkLi   = $quicklink.closest('li');
	         $quicklinkUl   = $quicklinkLi.closest('ul');
	         $quickDropdown = $quicklink.siblings('ul.quickDropdown');

	         $quicklinkLi.toggleClass('active');

	         $quickDropdown.css({
	             'max-width' : 'none',
	             width       : $quicklinkUl.innerWidth(),
	             left        : - $quicklinkLi.offset().left + $quicklinkUl.offset().left,
	         }).toggle(0);

	         if ($quicklinkLi.hasClass('active')) {
	           $quicklinkLi
	             .siblings('.hasquickDropdown.active')
	             .removeClass('active')
	             .removeAttr('style')
	             .find('.quickDropdown')
	             .hide();

	           $quicklinkLi.css('height', $quicklinkLi.height() + $quickDropdown.height() + 25);
	         } else {
	           $quicklinkLi.removeAttr('style');
	         }
	     });


	// rent size js
	// $w.on('load scroll resize', function () {
	// 	var marginTop2 = 0;
	// 	if ($(window).width() < 991) { 
	// 		var marginTop2 = 100;
	// 	} else {
	// 		var marginTop2 = 160;
	// 	}

	// 	$('.home-page .pricing-quadrant-tabs').attr( 'id', 'homepricetab' );
	// 	$(".vw-banner-8 .vw-inner .btn").on('click', function(e) {
	// 		$('html, body').stop().animate({
	// 			scrollTop: ($('#homepricetab').offset().top - marginTop2)
	// 		}, 1000);
	// 	});
	// });
	
	/**
	 * mm overlay component code
	 */
	$('[data-vw-action=open-mm-popup]').on('click', function (e) {
		e.preventDefault();
		$('.vw-mm-popup').first().fadeIn(600, function () {
			$(this).find('input[type=search]').trigger('focus');
		});
	});

	$('[data-vw-action=close-mm-popup]').on('click', function (e) {
		e.preventDefault();
		$('.vw-mm-popup').first().fadeOut(600);
	});
// To open External links in new tab or window == CODE STARTS HERE
openAllExternalLinksInNewTab();
function openAllExternalLinksInNewTab(){
	let siteHost  = location.host;
	let cleaned_host;
	if(siteHost.indexOf('www.') === 0){
		cleaned_host = siteHost.replace('www.','');
	}else{
		cleaned_host = siteHost;
	}
	$('a').on('click', function(e){
	  if(this.href != '') {
		if((this.href.indexOf('http') === 0) || (this.href.indexOf('www.') === 0)){
		  if(this.href.indexOf(cleaned_host) == -1) {
			window.open(this.href, "target=_blank");
			return false;
		  }
		}
	  }
	});
  }
  
// To open External links in new tab or window == CODE ENDS HERE
$('.header-toggle-button a').click(function(){
	$('header.header').toggle();
  });
})(jQuery, window, document);


