function onSyneriseLoad() {
    SR.init({
    'trackerKey': 'B87EDE03-DE4F-243B-828E-659A7E7385FB',
    });
}

// test

(function (s, y, n, e, r, i, se) {
	

s['SyneriseObjectNamespace'] = r;

s[r] = s[r] || [],

s[r]._t = 1 * new Date(), s[r]._i = 0, s[r]._l = i;
	

var z = y.createElement(n),
se = y.getElementsByTagName(n)[0];
z.async = 1;
z.src = e;
	
se.parentNode.insertBefore(z, se);
z.onload = z.onreadystatechange = function () {
var rdy = z.readyState;
if (!rdy || /complete|loaded/.test(z.readyState)) {
s[i]();
z.onload = null;
z.onreadystatechange = null;
}

};
	

})(window, document, 'script',
'//www.snrcdn.net/sdk/3.0/synerise-javascript-sdk.min.js', 'SR', 'onSyneriseLoad');

(function ($) {
	$.fn.countTo = function (options) {
		options = options || {};
		
		return $(this).each(function () {
			// set options for current element
			var settings = $.extend({}, $.fn.countTo.defaults, {
				from:            $(this).data('from'),
				to:              $(this).data('to'),
				speed:           $(this).data('speed'),
				refreshInterval: $(this).data('refresh-interval'),
				decimals:        $(this).data('decimals')
			}, options);
			
			// how many times to update the value, and how much to increment the value on each update
			var loops = Math.ceil(settings.speed / settings.refreshInterval),
				increment = (settings.to - settings.from) / loops;
			
			// references & variables that will change with each update
			var self = this,
				$self = $(this),
				loopCount = 0,
				value = settings.from,
				data = $self.data('countTo') || {};
			
			$self.data('countTo', data);
			
			// if an existing interval can be found, clear it first
			if (data.interval) {
				clearInterval(data.interval);
			}
			data.interval = setInterval(updateTimer, settings.refreshInterval);
			
			// initialize the element with the starting value
			render(value);
			
			function updateTimer() {
				value += increment;
				loopCount++;
				
				render(value);
				
				if (typeof(settings.onUpdate) == 'function') {
					settings.onUpdate.call(self, value);
				}
				
				if (loopCount >= loops) {
					// remove the interval
					$self.removeData('countTo');
					clearInterval(data.interval);
					value = settings.to;
					
					if (typeof(settings.onComplete) == 'function') {
						settings.onComplete.call(self, value);
					}
				}
			}
			
			function render(value) {
				var formattedValue = settings.formatter.call(self, value, settings);
				$self.html(formattedValue);
			}
		});
	};
	
	$.fn.countTo.defaults = {
		from: 0,               // the number the element should start at
		to: 0,                 // the number the element should end at
		speed: 1,           // how long it should take to count between the target numbers
		refreshInterval: 10,  // how often the element should be updated
		decimals: 0,           // the number of decimal places to show
		formatter: formatter,  // handler for formatting the value before rendering
		onUpdate: null,        // callback method for every time the element is updated
		onComplete: null       // callback method for when the element finishes updating
	};
	
	function formatter(value, settings) {
		return value.toFixed(settings.decimals);
	}
}(jQuery));

jQuery(function ($) {
  // custom formatting example
  $('.count-number').data('countToOptions', {
	formatter: function (value, options) {
	  return value.toFixed(options.decimals).replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
	}
  });
  
  // start all the timers
  $('.timer').each(count);  
  
  function count(options) {
	var $this = $(this);
	options = $.extend({}, options || {}, $this.data('countToOptions') || {});
	$this.countTo(options);
  }
});

document.addEventListener("DOMContentLoaded", function() {
    const languages = [
        { code: 'pl', name: 'Polski', flag: 'pl', url: 'https://wislakrakow.com' },
        { code: 'en', name: 'English', flag: 'gb', url: 'https://en.wislakrakow.com' }
    ];

    function createDropdown(activeLang) {
        const container = document.createElement('div');
        container.className = 'dropdown position-relative'; // Dodano klasę position-relative

        // Najpierw dodajemy ikonę wyszukiwania do kontenera dropdown
        const searchIcon = createSearchIcon();
        container.appendChild(searchIcon);

        const button = document.createElement('button');
        button.className = 'btn btn-sm btn-secondary dropdown-toggle bg-transparent';
        button.type = 'button';
        button.id = 'languageDropdown';
        button.setAttribute('data-toggle', 'dropdown');
        button.setAttribute('aria-haspopup', 'true');
        button.setAttribute('aria-expanded', 'false');
        button.textContent = activeLang.name;

        const menu = document.createElement('div');
        menu.className = 'dropdown-menu';
        menu.setAttribute('aria-labelledby', 'languageDropdown');

        languages.forEach(lang => {
            const item = document.createElement('a');
            item.className = 'dropdown-item';
            item.href = lang.url;
            item.innerHTML = ` ${lang.name}`;
            menu.appendChild(item);
        });

        container.appendChild(button);
        container.appendChild(menu);
        return container;
    }

    function createSearchIcon() {
        const iconContainer = document.createElement('div');
        iconContainer.className = 'search-icon-container'; // Usunięto mr-2 dla ogólnej klasy
        iconContainer.style.position = 'absolute';
        iconContainer.style.left = '-20px';
        iconContainer.style.top = '50%';
        iconContainer.style.transform = 'translateY(-50%)';

        const icon = document.createElement('i');
        icon.className = 'fa-solid fa-magnifying-glass text-white';
        icon.style.cursor = 'pointer';
        icon.addEventListener('click', expandSearchMenu);

        iconContainer.appendChild(icon);
        return iconContainer;
    }

    const topBarDesktop = document.getElementById('top_bar_desktop');
    const container = topBarDesktop.querySelector('.container');
    const topDropdown = createDropdown(languages[0]); // Zakładam, że pierwszy język to PL
    topDropdown.classList.add('ml-auto');
    container.appendChild(topDropdown);

    // Wstaw dla side_nav_bottom
    const sideNav = document.getElementById('side_nav_bottom');
    const sideDropdown = createDropdown(languages[0]); // Zakładam, że pierwszy język to PL, ponownie z ikoną wyszukiwania
    sideNav.style.textAlign = 'center';
    sideNav.classList.add('s-20', 'pt-1', 'mt-1', 'w-100');
    sideNav.appendChild(sideDropdown);
    
    function createBigSearchIcon() {
        // Tworzy przycisk wyszukiwania
        const searchButton = document.createElement('a');
        searchButton.onclick = expandSearchMenu;
        searchButton.className = 'open-search d-flex align-items-center justify-content-center text-white';
        searchButton.style.cssText = 'font-size: 20px; width: 40px; height: 40px; position: absolute; top: 10px; left: 10px; background: rgba(255,255,255,0.3); border-radius: 50%; z-index: 10000;';

        // Dodaje ikonę wyszukiwania z Font Awesome do przycisku
        const icon = document.createElement('i');
        icon.className = 'fas fa-search';
        searchButton.appendChild(icon);

        return searchButton;
    }

    // Szuka elementu sideNav, aby dodać do niego przycisk wyszukiwania
    const sideNavDiv = document.getElementById('sideNav');
    if (sideNavDiv) {
        // Tworzy przycisk wyszukiwania
        const searchButton = createBigSearchIcon();
        // Dodaje przycisk wyszukiwania na początku elementu sideNav
        sideNav.insertBefore(searchButton, sideNav.firstChild);
    }
    
    document.getElementById('searchMenuModal').style.zIndex = '99999999999';

    
});