//Writen by Bedirhan Teymur @ LM Control
function init_map(){
	let map = L.map('map', {scrollWheelZoom: false}).setView([-36.8762668, 174.7325985], 16);

	L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
		attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
	}).addTo(map);
	
	
	L.marker([-36.8762668, 174.7325985]).addTo(map).bindPopup('31B Taylors Road, Morningside, Auckland 1025').openPopup();
}

e(function(){
	init_map();
	e('.service').listen('click', function(evt){
		let targetElement = evt.target;
		let failSafe = 0;

		if(e(targetElement).hasClass('contactLink')) return;

		while(!e(targetElement).hasClass('service') && (failSafe < 5)){
			targetElement = targetElement.parentNode;
			failSafe++;
		}
		if(failSafe == 5) return;
		targetElement = e(targetElement);

		let isActive = targetElement.hasClass('active');

		let serviceElements = e('.service');
		for(let i = 0; i < 4; i++){
			let current = e(serviceElements[i]);
			if(current.hasClass('active')) current.removeClass('active');
		}
		
		if(isActive)
			targetElement.removeClass('active');	
		else {
			targetElement.addClass('active');
			window.location.hash = "#wwd";
		}
	});
});