//var pinesClicks = [];);
var mousesFocus = [];
function hideDiv(buttonElement) {
	console.log("pinesClicks init", pinesClicks);
	let attrid = jQuery(buttonElement.parentElement).attr('attrid')
	let idEnd = jQuery(buttonElement.parentElement).attr('id')[jQuery(buttonElement.parentElement).attr('id').length - 1]
	let id = jQuery(buttonElement.parentElement).attr('id')
	let clicksNow = pinesClicks[idEnd + '_' + attrid].clicks
	clicksNow = clicksNow.filter(item => item !== '#' + id);
	console.log("clicksNow", clicksNow);
	console.log("pinesClicks", pinesClicks);

	var parentDiv = buttonElement.parentElement;
	parentDiv.style.display = 'none';
	pinesClicks[idEnd + '_' + attrid].clicks = clicksNow
	console.log('pinesClicks', pinesClicks)
	if (clicksNow.length == 0) {
		const valor = pinesClicks[idEnd + '_' + attrid];
		let originalSrc = valor.url
		let originalSize = valor.size
		jQuery('img[id="' + idEnd + '_' + attrid + '"]').attr('src', originalSrc);
		jQuery('img[id="' + idEnd + '_' + attrid + '"]').css({
			width: originalSize.width,
			//height: originalSize.height
		});
		reboteInfinito(jQuery('img[id="' + idEnd + '_' + attrid + '"]'))

		pinesClicks = pinesClicks.filter(item => item !== idEnd + '_' + attrid);
		console.log('pinesClicks222', pinesClicks)
	}
}


function esVisible(elemento) {
	var rect = elemento.getBoundingClientRect();
	console.log('rect', rect, window.innerHeight, document.documentElement.clientHeight)
	return (
		rect.top >= 0 &&
		rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)
	);
}

jQuery(function ($) {


	var targetLi;
	$(document).on('mouseleave1', "li[id^='menu-item-'] > a", function () {
		$(this).siblings("div").remove();
	});

	$(document).on('mouseenter', "li[id^='menu-item-'] > a", function () {
		$(this).siblings("div").remove();
		//console.log("Mouse over en111:", this);
		var liElement = $(this).parent();

		var sectionParent = liElement.closest("section");

		var sectionWidth = sectionParent.width();
		var aHeight = liElement.find("a").outerHeight();
		var aElement = $(this);
		//console.log("Width of section:", sectionWidth);
		console.log("Height of <a>:", liElement.outerHeight());

		var position = aElement.offset();

		//console.log("Top:", position.top);
		//console.log("Left:", position.left);

		var positionRelativeToParent = aElement.position();

		//console.log("Relative Top:", positionRelativeToParent.top);
		//console.log("Relative Left:", positionRelativeToParent.left);
		var leftSpace = aElement.offset().left - sectionParent.offset().left
		var newDiv = $("<div class='newDivC' style='line-height:22px; letter-spacing:0px;font-family: \"Lato\", Sans-serif; padding-top:6px; padding-right:40px ;padding-left: " + (leftSpace) + "px ; background-color:#514D49; z-index:11; position:relative; left:-" + (leftSpace) + "px; top:-32px; color:#fff; font-weight: 300; font-size:18px; width:" + (sectionWidth + 30) + "px; height:" + (aHeight + 2) + "px'></div>");

		// Agrega el nuevo <div> al <li> seleccionado.
		liElement.css('height', liElement.outerHeight() + "px");
		//liElement.css('overflow', "hidden");

		$(".newDivC").remove()
		let newA = $(this).clone()
		liElement.append(newDiv);
		newDiv.append(newA)
		if (newA.text().trim().indexOf('ESG: Gesellschaftliche') > -1) {
			if (newA.is('a')) {
				newDiv.css('padding-top', "5px");

				var number = parseInt(newDiv.css('height'), 10);
				var resultNumber = number - 4;
				var resultString = resultNumber + "px";
				console.log('height', resultString)
				newDiv.css('height', resultString);
			}
		}

		newDiv.mouseout(function () {
			$(this).remove();
		});

		let totalHeight = 0;
		newDiv.prevAll().each(function () {
			totalHeight += $(this).outerHeight(); // Utiliza outerHeight() para incluir el padding y border en el cálculo
		});

		if (newA.text().trim().indexOf('ESG: Gesellschaftliche') > -1) {
			if (newA.is('a')) {
				newDiv.css('top', "-" + (totalHeight - 5) + "px");
			}
		} else {
			newDiv.css('top', "-" + (totalHeight) + "px");
		}
	});

	$(document).on('mouseenter', 'div.cardnc', function (e1) {
		let attrid = $(this).attr('attrid')
		let id = $(this).attr('id')[$(this).attr('id').length - 1]
		mousesFocus[id + '_' + attrid] = true
	})



	const divElements = document.querySelectorAll('.elementor-element.elementor-element-edit-mode.elementor-element-8748de8 e-con.e-flex.e-con-full.e-con--row.elementor-hidden-tablet.elementor-hidden-mobile.ui-resizable');

	// Agregar un evento de clic a cada elemento
	divElements.forEach(div => {
		div.addEventListener('click', function (event) {
			// Acciones a realizar cuando se hace clic en el div
			console.log('Se hizo clic en el div');
		});
	});


});



