
$('.touchscreen-popups').on('click', function () {
	closeTouchscreenPopups();
	var target = $(this).attr('touchscreen-popup-icon-target');
	$(target).addClass('rotate');

	var target = $(this).attr('touchscreen-active-tab');
	$(target).addClass('active-tab');

 	var target = $(this).attr('touchscreen-popup-target');
 	$(target).addClass('touchscreen-slideout-active');

});

 function closeTouchscreenPopups()
 {

 	$('.touchscreen-popups').each(function(){
		var target = $(this).attr('touchscreen-popup-icon-target');
		$(target).removeClass('rotate');

		var target = $(this).attr('touchscreen-active-tab');
		$(target).removeClass('active-tab');

	 	var target = $(this).attr('touchscreen-popup-target');
	 	$(target).removeClass('touchscreen-slideout-active');
 	});
 }

$('.close-container').on('click', function () {
 	$('.touchscreen-slideout').removeClass('touchscreen-slideout-active');
	$('.touchscreen-popups > i').removeClass('rotate');
	$('.touchscreen-popups').removeClass('active-tab');
 });

$('#sitePlanZoomInBtn').on('click', function(){
	console.log('buttonClick');
	$('.mobileSiteplanImageWrapper').addClass('zoomed-in');
	$('.zoom-out').addClass('zoom-out-active');
	$('#sitePlanZoomInBtn').addClass('btn-zoomed');
})


$('.zoom-out').on('click', function(){
	$('.mobileSiteplanImageWrapper').removeClass('zoomed-in');
	$('#sitePlanZoomInBtn').removeClass('btn-zoomed');
})


function offsetAnchor() {
  if (location.hash.length !== 0) {
    window.scrollTo(window.scrollX, window.scrollY - 100);
  }
}

// Captures click events of all a elements with href starting with #
$(document).on('click', 'a[href^="#"]', function(event) {
  // Click events are captured before hashchanges. Timeout
  // causes offsetAnchor to be called after the page jump.
  window.setTimeout(function() {
    offsetAnchor();
  }, 0);
});

// Set the offset when entering page with hash present in the url
window.setTimeout(offsetAnchor, 0);


$(document).ready(function(){
setTimeout(function(){ $('#select#sortBy').click()}, 100);
});

$('.dropdown > #devDropdown').on('click', function (){
	$('#devDropdown > .toggler > .dropdown-toggler-vertical').toggleClass('d-none');
	$('.dropdown > select').click();
 });


var labelID;

$('#sortBy').on('click', function (){
$ ('#toggler').toggleClass('rotate');
});

$('.mortgage-field-inner input').on('keyup', function(){
  var value = $('input[mortgage-calc="house_value"]').val();
  var deposit = $('input[mortgage-calc="deposit"]').val();
  var interest = $('input[mortgage-calc="interest"]').val();
  var years = $('input[mortgage-calc="years"]').val();

  if((value.length >= 5) && (deposit.length >=1) && (interest.length >=1) && (years.length >=1))
	$('.mortgage-calculator-link').removeClass('d-none');
	else {
	$('.mortgage-calculator-link').addClass('d-none');
  }
});

$('#development-accordion').on('click', function() {
  $('#development-accordion i').toggleClass('rotate-search');
  $('#development-accordion i').toggleClass('rotate-search-reverse');
});

$('#page-accordion').on('click', function() {
  $('#page-accordion i').toggleClass('rotate-search');
  $('#page-accordion i').toggleClass('rotate-search-reverse');
});

$('#events-accordion').on('click', function() {
  $('#events-accordion i').toggleClass('rotate-search');
  $('#events-accordion i').toggleClass('rotate-search-reverse');
});

$('#articles-accordion').on('click', function() {
  $('#articles-accordion i').toggleClass('rotate-search');
  $('#articles-accordion i').toggleClass('rotate-search-reverse');
});

window.addEventListener('load', AOS.refresh)


// Mortgage Calc
$('body').on('keyup', '[mortgage-calc]', function(){
	var house = $('[mortgage-calc=house_value]').val();
	var deposit = $('[mortgage-calc=deposit]').val();
	var interest = $('[mortgage-calc=interest]').val();
	var years = $('[mortgage-calc=years]').val();

	var total = parseInt(house)-parseInt(deposit);

	var x = total;
	var y = parseInt(interest);
	y /= 1200;
	var z = parseInt(years)*12;

	if(total > 0){

	var monthly = x*(y * Math.pow((1 + y), z))/(Math.pow((1 + y), z) - 1);

	var repayable = monthly*z;

		$('[mortgage-total]').html(total.toFixed(0));
		$('[mortgage-monthly]').html(monthly.toFixed(2));
		$('[mortgage-repayable]').html(repayable.toFixed(2));
		$('[mortgage-results]').fadeIn();
	  } else{
		$('[mortgage-results]').fadeOut();
	  }
});
// Mortgage Calc Finish

var swiper = new Swiper('.swiper-container', {
	slidesPerView: 3,
	freeMode: true,

	spaceBetween: 30,
	pagination: {
		el: '.swiper-pagination',
		clickable: true,
	},
	navigation: {
	// autoplay: {
	//     delay: 2500,
	//     disableOnInteraction: false,
	// },		nextEl: '.swiper-button-next',
		prevEl: '.swiper-button-prev',
	  },
	scrollbar: {
		el: '.swiper-scrollbar',
		hide: false,
		draggable: true,
	},
	  breakpoints: {
	// when window width is <= 320px
	1650: {
	  slidesPerView: 2.5,
	  spaceBetween: 30
	},
	1500: {
	  slidesPerView: 2,
	  spaceBetween: 30
	},
	// when window width is <= 480px
	1080: {
	  slidesPerView: 2,
	  spaceBetween: 30
	},
	// when window width is <= 640px
	797: {
	  slidesPerView: 1.5,
	  spaceBetween: 15
	},
	500: {
	  slidesPerView: 1,
	  spaceBetween: 15
	},
	0: {
		slidesPerView: 1,
	 	spaceBetween: 15
	}
  }
});

var swiper = new Swiper('.featured-plots', {
	slidesPerView: 3,
	freeMode: true,
	spaceBetween: 30,
	pagination: {
		el: '.swiper-pagination',
		clickable: true,
	},
	navigation: {
		nextEl: '.swiper-button-next',
		prevEl: '.swiper-button-prev',
	  },
	scrollbar: {
		el: '.swiper-scrollbar',
		hide: false,
		draggable: true,
	},
	  breakpoints: {
	// when window width is <= 320px
	1650: {
	  slidesPerView: 2.5,
	  spaceBetween: 30
	},
	1500: {
	  slidesPerView: 2,
	  spaceBetween: 30
	},
	// when window width is <= 480px
	1080: {
	  slidesPerView: 2,
	  spaceBetween: 30
	},
	// when window width is <= 640px
	797: {
	  slidesPerView: 1.5,
	  spaceBetween: 15
	},
	500: {
	  slidesPerView: 1,
	  spaceBetween: 15
	},
	0: {
	  slidesPerView: 1,
	  spaceBetween: 15
	}
  }
});

// var swiper = new Swiper('.incentive-swiper-container', {
// 	slidesPerView: 3,
// 	freeMode: true,
// 	// autoplay: {
// 	//     delay: 2500,
// 	//     disableOnInteraction: false,
// 	// },
// 	spaceBetween: 30,
// 	pagination: {
// 		el: '.swiper-pagination',
// 		clickable: true,
// 	},
// 	navigation: {
// 		nextEl: '.swiper-button-next',
// 		prevEl: '.swiper-button-prev',
// 	  },
// 	scrollbar: {
// 		el: '.swiper-scrollbar',
// 		hide: false,
// 		draggable: true,
// 	},
// 	  breakpoints: {
// 	// when window width is <= 320px
// 	1650: {
// 	  slidesPerView: 2.5,
// 	  spaceBetween: 30
// 	},
// 	1500: {
// 	  slidesPerView: 2,
// 	  spaceBetween: 30
// 	},
// 	// when window width is <= 480px
// 	1080: {
// 	  slidesPerView: 2,
// 	  spaceBetween: 30
// 	},
// 	// when window width is <= 640px
// 	797: {
// 	  slidesPerView: 1.5,
// 	  spaceBetween: 15
// 	},
// 	500: {
// 	  slidesPerView: 1,
// 	  spaceBetween: 15
// 	},
// 	0: {
// 	  slidesPerView: 1,
// 	  spaceBetween: 15
// 	}
//   }
// });


// Touchscreen
$('.touchscreen-plot-swiper-container').slick({
	slidesToShow: 6,
	slidesToScroll: 3,
	autoplay: true,
	autoplaySpeed: 4000,
	prevArrow: ' ',
	nextArrow: '<div class="touchscreen-next-news-link"><span class="link-inner">Next</span><img class="arrow-right" src="/media/arrow-right.svg" alt=""></div>'
});
$('.touchscreen-gallery-slider').slick({
	slidesToShow: 2,
	slidesToScroll: 1,
	autoplay: true,
	autoplaySpeed: 4000,
	prevArrow: ' ',
	nextArrow: '<div class="touchscreen-next-news-link"><span class="link-inner">Next</span><img class="arrow-right" src="/media/arrow-right.svg" alt=""></div>'
});

$('.touchscreen-dev-cards').slick({
	slidesToShow: 3,
	slidesToScroll: 1,
	centerMode: false,
	autoplay: false,
 	prevArrow: ' ',
	nextArrow: '<div class="touchscreen-next-news-link"><span class="link-inner">Next</span><img class="arrow-right" src="/media/arrow-right.svg" alt=""></div>'
});



var swiper = new Swiper('.incentive-container', {
	slidesPerView: 2.5,
	freeMode: true,
	// autoplay: {
	//     delay: 2500,
	//     disableOnInteraction: false,
	// },
	spaceBetween: 30,
	pagination: {
		el: '.swiper-pagination',
		clickable: true,
	},
	navigation: {
		nextEl: '.swiper-button-next',
		prevEl: '.swiper-button-prev',
	  },
	scrollbar: {
		el: '.swiper-scrollbar',
		hide: false,
		draggable: true,
	},
	  breakpoints: {
	// when window width is <= 320px
	1650: {
	  slidesPerView: 2.5,
	  spaceBetween: 30
	},
	1500: {
	  slidesPerView: 2,
	  spaceBetween: 30
	},
	// when window width is <= 480px
	1080: {
	  slidesPerView: 1.5,
	  spaceBetween: 30
	},
	// when window width is <= 640px
	797: {
	  slidesPerView: 1,
	  spaceBetween: 15
	}
  }
});


var swiper = new Swiper('.news-swiper-container', {
	slidesPerView: 3,
	freeMode: true,
	// autoplay: {
	//     delay: 2500,
	//     disableOnInteraction: false,
	// },
	spaceBetween: 30,
	pagination: {
		el: '.swiper-pagination',
		clickable: true,
	},
	navigation: {
		nextEl: '.swiper-button-next',
		prevEl: '.swiper-button-prev',
	  },
	scrollbar: {
		el: '.swiper-scrollbar',
		hide: false,
		draggable: true,
	},
	  breakpoints: {
	// when window width is <= 320px
	1650: {
	  slidesPerView: 2.5,
	  spaceBetween: 30
	},
	1500: {
	  slidesPerView: 2,
	  spaceBetween: 30
	},
	// when window width is <= 480px
	1080: {
	  slidesPerView: 1.5,
	  spaceBetween: 30
	},
	// when window width is <= 640px
	797: {
	  slidesPerView: 1,
	  spaceBetween: 15
	}
  }
});

$(function () {
  $("#datepicker").datepicker({
		autoclose: true,
		todayHighlight: true
  }).datepicker('update', new Date());
});

$(document).ready(function(){
	$('.news-slider').slick({
		infinite: true,
		slidesToShow: 1,
		slidesToScroll: 1,
		prevArrow: ' ',
		nextArrow: '<div class="next-news-link"><span class="link-inner">Next Story</span><img class="arrow-right" src="/media/arrow-right-blue.svg" alt=""></div>'
	});
});


$(document).ready(function(){
  $('.htb-slider-1').slick({
	 infinite: true,
	slidesToShow: 1,
	slidesToScroll: 1,
	prevArrow: ' ',
	nextArrow: '<div class="next-news-link"><div class="link-inner">Next Step</div><img class="arrow-right" src="/media/arrow-right-blue.svg" alt=""></div>'
  });
 });


$(document).ready(function(){
  $('.slick-test').slick({
	 infinite: true,
	slidesToShow: 1,
	slidesToScroll: 1,
	prevArrow: ' ',
	nextArrow: '<div class="next-news-link"><div class="link-inner">Next Step</div><img class="arrow-right" src="/media/arrow-right-blue.svg" alt=""></div>'
  });
 });


$(document).ready(function(){
  $('.htb-slider-2').slick({
	 infinite: true,
	slidesToShow: 1,
	slidesToScroll: 1,
	prevArrow: ' ',
	nextArrow: '<div class="next-news-link"><div class="link-inner">Next Step</div><img class="arrow-right" src="/media/arrow-right-blue.svg" alt=""></div>'
  });
 });

$(document).ready(function(){
  $('.touchscreen-htb-slider').slick({
	 infinite: true,
	slidesToShow: 1,
	slidesToScroll: 1,
	prevArrow: ' ',
	nextArrow: '<div class="touchscreen-next-htb-link"><div class="link-inner">Next Step</div><img class="arrow-right" src="/media/arrow-right.svg" alt=""></div>'
  });
 });
$('.touchscreen-popups').on('click', function(){
  $('.touchscreen-htb-slider').slick('refresh');
  $('.htb-slider-2').slick('refresh');
});

$('.nav-item-htb').on('click', function(){
  $('.htb-slider-1').slick('refresh');
  $('.htb-slider-2').slick('refresh');
});

$(document).ready(function(){
  $('.news-gallery-slider').slick({
	 infinite: false,
	slidesToShow: 1,
	slidesToScroll: 1,
	arrows: true
	});
});
$(document).ready(function(){
  $('.testimonial-slider-inner').slick({
	 infinite: false,
	  slidesToShow: 1,
	  slidesToScroll: 1,
	  arrows: false,
	  dots: true
	});
});

$(document).ready(function(){
	$('.floorplans-slider').slick({
		infinite: true,
		dots: true,
		slidesToShow: 2,
		slidesToScroll: 1,
		prevArrow: ' ',
		nextArrow: ' ',
		responsive: [
			{
			breakpoint: 1200,
			settings: {
				slidesToShow: 1,
				slidesToScroll: 1
				}
			},
		]
	});
});




//Fade on scroll
$(window).scroll(function(){
	$(".hero-caption").css("opacity", 1 - $(window).scrollTop() / 750);
});

$(window).scroll(function(){
	$(".hero-box").css("opacity", 1 - $(window).scrollTop() / 750);
});

//Paralax - scroll at different rates
$.fn.moveIt = function(){
  var $window = $(window);
  var instances = [];

  $(this).each(function(){
	instances.push(new moveItItem($(this)));
  });

  window.addEventListener('scroll', function(){
	var scrollTop = $window.scrollTop();
	instances.forEach(function(inst){
	  inst.update(scrollTop);
	});
  }, {passive: true});
}

var moveItItem = function(el){
  this.el = $(el);
  this.speed = parseInt(this.el.attr('data-scroll-speed'));
};

moveItItem.prototype.update = function(scrollTop){
  this.el.css('transform', 'translateY(' + -(scrollTop / this.speed) + 'px)');
};

// Initialization
$(function(){
  $('[data-scroll-speed]').moveIt();
});

 //This is for the selects so i can click a label and the selects drop down
$("#devDropdown1").on('click', function() {
	var $target = $("#sortBy");
	var $clone = $target.clone().removeAttr('id');
	$clone.val($target.val()).css({
		overflow: "auto",
		position: 'absolute',
		'z-index': 999,
		left: $target.offset().left,
		top: $target.offset().top + $target.outerHeight(),
		width: $target.outerWidth()
	}).attr('size', $clone.find('option').length > 10 ? 10 : $clone.find('option').length).change(function() {
		$target.val($clone.val());
	}).on('click blur keypress',function(e) {
	 if(e.type !== "keypress" || e.which === 13)
		$(this).remove();
	});
	$('body').append($clone);
	$clone.focus();
});


$("#devDropdown2").on('click', function() {
	var $target = $("#sortBy2");
	var $clone = $target.clone().removeAttr('id');
	$clone.val($target.val()).css({
		overflow: "auto",
		position: 'absolute',
		'z-index': 999,
		left: $target.offset().left,
		top: $target.offset().top + $target.outerHeight(),
		width: $target.outerWidth()
	}).attr('size', $clone.find('option').length > 10 ? 10 : $clone.find('option').length).change(function() {
		$target.val($clone.val());
	}).on('click blur keypress',function(e) {
	 if(e.type !== "keypress" || e.which === 13)
		$(this).remove();
	});
	$('body').append($clone);
	$clone.focus();
});

$("#devDropdown3").on('click', function() {
	var $target = $("#sortBy3");
	var $clone = $target.clone().removeAttr('id');
	$clone.val($target.val()).css({
		overflow: "auto",
		position: 'absolute',
		'z-index': 999,
		left: $target.offset().left,
		top: $target.offset().top + $target.outerHeight(),
		width: $target.outerWidth()
	}).attr('size', $clone.find('option').length > 10 ? 10 : $clone.find('option').length).change(function() {
		$target.val($clone.val());
	}).on('click blur keypress',function(e) {
	 if(e.type !== "keypress" || e.which === 13)
		$(this).remove();
	});
	$('body').append($clone);
	$clone.focus();
});

$("#devDropdown4").on('click', function() {
	var $target = $("#sortBy4");
	var $clone = $target.clone().removeAttr('id');
	$clone.val($target.val()).css({
		overflow: "auto",
		position: 'absolute',
		'z-index': 999,
		left: $target.offset().left,
		top: $target.offset().top + $target.outerHeight(),
		width: $target.outerWidth()
	}).attr('size', $clone.find('option').length > 10 ? 10 : $clone.find('option').length).change(function() {
		$target.val($clone.val());
	}).on('click blur keypress',function(e) {
	 if(e.type !== "keypress" || e.which === 13)
		$(this).remove();
	});
	$('body').append($clone);
	$clone.focus();
});




//Stick to the top on scroll - Anchor Bar
function sticktothetop() {
	var window_top = $(window).scrollTop();
	var top = $('#stick-here').offset().top;
	if (window_top > top) {
		$('#stickThis').addClass('stick');
		$('#stick-here').height($('#stickThis').outerHeight());
	} else {
		$('#stickThis').removeClass('stick');
		$('#stick-here').height(0);
	}
}
$(function() {
	$(window).scroll(sticktothetop);
	sticktothetop();
});

$(document).on('click', '.anchor-points[href^="#"]', function (event) {
	event.preventDefault();

	$('html, body').animate({
		scrollTop: $($.attr(this, 'href')).offset().top
	}, 1200);
});


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

	// -------------------------------------------------------------
	//   Basic Navigation
	// -------------------------------------------------------------
	(function () {
		var $frame  = $('#plot-slider');
		var $slidee = $frame.children('ul');
		var $wrap   = $frame.parent();

		// Call Sly on frame
		$frame.sly({
			horizontal: 1,
			itemNav: 'basic',
			smart: 0,
			scrollBy: 1,
			mouseDragging: 1,
			swingSpeed: 0.2,
			dragHandle: 1,
			clickBar: 1,
			elasticBounds: 1,
			speed: 600,
			startAt: 0,
			scrollBar: $wrap.find('.scrollbar'),
		 });
	}());
});

$('.btn-link').on('click', function () {
  setTimeout(function(){
  $('.btn-link').each(function(){
	var dropdown = $(this).attr('data-target');
	if($(dropdown).hasClass('show')){
		var target = $(this).attr('toggle-target');
		$(target).addClass('rotate');
	} else{
		var target = $(this).attr('toggle-target');
		$(target).removeClass('rotate');
	}
  });
  }, 400);

});

'use strict';

var searchBox = document.querySelectorAll('.search-box input[type="text"] + span');

searchBox.forEach((elm) => {
	elm.addEventListener('click', () => {
		elm.previousElementSibling.value = '';
	});
});

$('.modal-select-one').on('change', function() {
	 $('.modal-select-one').addClass('modal-selected');
});
$('.modal-select-two').on('change', function() {
	 $('.modal-select-two').addClass('modal-selected');
});
$('.modal-select-three').on('change', function() {
	 $('.modal-select-three').addClass('modal-selected');
});
$('.modal-select-four').on('change', function() {
	 $('.modal-select-four').addClass('modal-selected');
});

$('.buscar-btn').on('click', function(){
  $('.buscar-caja > .buscar-txt').toggleClass('buscar-txt-active');
	$('.buscar-btn i').toggleClass('buscar-btn-color');
});

$('.siteplan-popover').popover({
   html : true,
	content: function() {
	  var content = $(this).attr("data-popover-content");
	  return $(content).children(".popover-body").html();
	},
	title: function() {
		var title = $(this).attr("data-popover-content");
		return $(title).children(".popover-heading").html();
	}
})



//Animated form
let usernameInput = document.querySelector('.username')
let passwordInput = document.querySelector('.password')
let showPasswordButton = document.querySelector('.password-button')
let face = document.querySelector('.face')

passwordInput.addEventListener('focus', event => {
  document.querySelectorAll('.eye').forEach(hand => {
	hand.classList.add('hide')
	hand.classList.remove('eye-animation')
	hand.classList.remove('peek')
  })
  document.querySelector('.tongue').classList.remove('breath')
})

passwordInput.addEventListener('blur', event => {
  document.querySelectorAll('.eye').forEach(hand => {
	hand.classList.remove('hide')
	hand.classList.add('eye-animation')
	hand.classList.remove('peek')
  })
  document.querySelector('.tongue').classList.add('breath')
})

usernameInput.addEventListener('focus', event => {
  let length = Math.min(usernameInput.value.length - 16, 19)
  document.querySelectorAll('.eye').forEach(hand => {
	hand.classList.remove('hide')
	hand.classList.remove('peek')
  })

  face.style.setProperty('--rotate-head', `${-length}deg`)
})

usernameInput.addEventListener('blur', event => {
  face.style.setProperty('--rotate-head', '0deg')
})

usernameInput.addEventListener('input', _.throttle(event => {
  let length = Math.min(event.target.value.length - 16, 19)

  face.style.setProperty('--rotate-head', `${-length}deg`)
}, 100))

showPasswordButton.addEventListener('click', event => {
  if (passwordInput.type === 'text') {
	passwordInput.type = 'password'
	document.querySelectorAll('.eye').forEach(hand => {
	  hand.classList.remove('peek')
	  hand.classList.add('hide')
	})
  } else {
	passwordInput.type = 'text'
	document.querySelectorAll('.eye--right').forEach(hand => {
	  hand.classList.remove('hide')
	  hand.classList.add('peek')
	})
  }
})
