• File: menu.white.v0552.js.stažený soubor
  • Full Path: /home/tlcompan/www/diskport/0 Osobní/Jaguar1 - 9AJ 5686/inzerát/Jaguar E-Pace 2018 P250 AWD 56700km SUV_files/menu.white.v0552.js.stažený soubor
  • Date Modified: 03/21/2026 10:17 PM
  • File size: 66.43 KB
  • MIME-type: text/plain
  • Charset: utf-8
var animateSpeed = 250;
var trackComparisonEnabled = false;
var iframeStartPosition = null;
var iframeStartPositionParent = null;

var isMobileBrowser = function () {
  var a = navigator.userAgent || navigator.vendor || window.opera;
  return (
    /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(
      a,
    ) ||
    /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(
      a.substr(0, 4),
    )
  );
};

var showExponeaTopBannerScroll = false;
var isBeingTranslated = function () {
  return (
    $("html").hasClass("translated-ltr") || $(".goog-te-banner-frame").length
  );
};
var transheight = 39;
var hasHeader = null;
var initExponeaBanner = function () {
  if (hasHeader === null) {
    hasHeader = $("header").length + $("#modern-header").length > 0;
  }
  var el = $(".exponea-banner.exponea-leaderboard");

  var h = el.length ? el.outerHeight() : 0;

  if (!hasHeader) {
    $("body").css("border-top", h + "px solid #FFFFFF");
    var mh = $("#modern-header").not(".static");
    mh.css(
      "margin-top",
      -1 * (isBeingTranslated() ? h + transheight : h) + "px",
    );
    el.css("margin-top", -1 * h + "px");
  } else {
    $("body").css("padding-top", h + "px");

    var mh = $("#modern-header").not(".static");
    mh.css("margin-top", (isBeingTranslated() ? h + transheight : h) + "px");
  }

  if (h) {
    $("header").css("margin-top", 0);
  }

  setOnScroll();

  if (el.length && !showExponeaTopBannerScroll) {
    $(window).scroll(setOnScroll);
    showExponeaTopBannerScroll = true;
  }
};
var closeExponeaTopBanner = function () {
  setOnScroll();
};

var setOnScroll = function () {
  var topPosition = window.scrollY || document.documentElement.scrollTop;
  var el = $(".exponea-banner.exponea-leaderboard");
  var exponeaHeight = el.length ? el.outerHeight() : 0;

  var mh = $("#modern-header").not(".static");

  if (!hasHeader) {
    $("body").css("border-top", exponeaHeight + "px solid #FFFFFF");
    mh.css(
      "margin-top",
      -1 * (isBeingTranslated() ? exponeaHeight + transheight : exponeaHeight) +
        "px",
    );
    el.css("margin-top", -1 * exponeaHeight + "px");
  } else {
    if (exponeaHeight - topPosition >= 0) {
      var menuMargin = exponeaHeight - topPosition;
    } else {
      var menuMargin = 0;
    }

    $("body").css("padding-top", menuMargin + "px");
    menuMargin += isBeingTranslated() ? transheight : 0;
    mh.css("margin-top", menuMargin + "px");
  }
};
var showExponeaTopBanner = function () {
  initExponeaBanner();
  for (var i = 150; i <= 1500; i += 150) {
    setTimeout(initExponeaBanner, i);
  }
};

var reloadNotifications = function () {
  $.getJSON("/ajax/account.php?notifications", function (t) {
    if (t.notifications) {
      $("header .notificationsGarage").replaceWith(t.notifications);
      //$('#userNameHeader').text(t.firstname);
      $("#userNameHeader").text(t.firstname.length < 40 ? t.firstname : "");
    }
  });
};

function setVw() {
  var vw = document.documentElement.clientWidth;
  document
    .querySelector(":root")
    .style.setProperty("--window-width", vw + "px");
}

function showBuyoutFormOverlay(appointment) {
  if (window.location.href.indexOf("inhouseForms=buyout") > -1) {
    var lightboxWidth = 970;
    var lightboxHeight = 700;

    var url =
      "https://new-m.aaaauto.cz/oceneni-vozu-online-form/text.html?id=47&popupOpen=buyingFormPopup&removeHeader=true";
    if (G_LANG == "pl") {
      var url =
        "https://new-m.aaaauto.pl/jak-wyglada-skup-w-aaa-auto-form/text.html?id=47&popupOpen=buyingFormPopup&removeHeader=true";
    } else if (G_LANG == "sk") {
      var url =
        "https://new-m.aaaauto.sk/vykup-vozidiel-aaa-auto-form/text.html?id=47&popupOpen=buyingFormPopup&removeHeader=true";
    }

    tb_show(
      "",
      url +
        "&TB_iframe=true&max-height=1&className=inhouse+corners+social&width=" +
        lightboxWidth +
        "&height=" +
        lightboxHeight,
      false,
    );

    function setupTBcloseButton() {
      $("#TB_iframeContent").on("load", function () {
        $("#TB_window").addClass("finished");
      });
      $("#TB_closeWindowButton")
        .css("top", "auto")
        .css("bottom", parseInt($("#TB_iframeContent").height() - 35) + "px");

      if (!$("#TB_loading").length) {
        $('<div id="TB_loading"></div>').appendTo($("#TB_window"));
      }

      $("#TB_loading")
        .css("top", "auto")
        .css(
          "bottom",
          parseInt($("#TB_iframeContent").height() / 2 - 35) + "px",
        );
    }
    setupTBcloseButton();
    $(window).resize(setupTBcloseButton);

    return;
  }

  $.get("/ajax/buyout-overlay.php?lang=" + G_LANG, function (data) {
    $(document.body).append(data);

    var href =
      "/" +
      G_LANG +
      "/buyout.php?formOverlay&showExponea=no" +
      (appointment ? "&appointment" : "");
    if (!$(".formOverlay.global .formOverlay-content").html().length) {
      var iframe = $("<iframe />")
        .attr("src", href)
        .attr("height", G_LANG == "pl" || G_LANG == "hu" ? 742 : 727)
        .attr("width", 702)
        .attr("frameborder", "no")
        .attr("scrolling", "no");
      $(".formOverlay.global .formOverlay-content")
        .html(iframe)
        .removeClass("hide");
    }
    $(".formOverlay.global").removeClass("hide").addClass("buyout");

    $("body,html").attr("style", "background-color:#F2F2F2 !important");
    $(
      "body > .page,#site-bottom-bar,.container-fluid,.formOverlayHiddenElement",
    ).addClass("hide");
    $(window).scrollTop(0);

    $(".formOverlay.global .formOverlay-close").click(function () {
      $(
        "body > .page,#site-bottom-bar,.container-fluid,.formOverlayHiddenElement",
      ).removeClass("hide");
      $("body,html").css("background-color", "#FFF");
      $(".formOverlay.global").addClass("hide").removeClass("buyout");
      $(".formOverlay.global .formOverlay-content").addClass("hide").html("");
    });
  });
}

function cookiebarBtnClicked() {
  var visitedCarsFrame = $("#visitedCarsFrame");
  if (visitedCarsFrame.length) {
    visitedCarsFrame[0].contentWindow.postMessage(
      { cookiebarBtnClicked: true },
      "https://new-m.aaaauto." + G_LANG,
    );
    //visitedCarsFrame[0].contentWindow.postMessage({ cookiebarBtnClicked: true}, "https://beta-m.aaaauto." + G_LANG);
  }

  if (
    typeof listComparison !== "undefined" &&
    typeof listComparisonCookies !== "undefined"
  ) {
    listComparisonCookies();
    if ($.cookie("ah-cookie-functional") && trackComparisonEnabled) {
      trackGAeventML([
        "_trackEvent",
        "porovnani box",
        "nechali souhlas",
        "vypis vozu",
      ]);
    }
  }

  if (iframeStartPositionParent) {
    $("html, body")
      .stop()
      .animate({ scrollTop: iframeStartPositionParent }, 250);
    iframeStartPositionParent = null;
  }

  //console.log('cookiebarBtnClicked');
  if (!$.cookie("cje") && $.cookie("ah-cookie-advertisement") == 1) {
    var urlParams = new URLSearchParams(window.location.search);
    const cj = urlParams.get("cjevent");

    if (cj && cj.length) {
      $.cookie("cje", cj, {
        expires: 120,
        path: "/",
        domain: ".aaaauto." + G_LANG,
      });
      if (typeof cjAffilCode != "undefined") cjAffilCode();
    }
  }
}

function addCarToGarageAAAID(aaaid) {
  $.ajax({
    dataType: "html",
    url:
      "/ajax/addcar.php?aaaid=" + aaaid + "&lang=" + G_LANG + "&type=5&cnt=1",
    success: function (d) {
      setGarageNumber(d);
    },
    error: function () {
      showLoginForm("no");
    },
  });
}

function addCarToGarage(id, pixel, aaaid, price, currency, el) {
  //fbq('trackSingle', pixel, 'AddToWishlist', {content_type: 'vehicle', content_ids: [aaaid], currency: currency});
  if ($("body").hasClass("country-sk")) {
    gtagRTB("event", "conversion", {
      allow_custom_scripts: true,
      send_to: "DC-9329976/audie0/butto0+standard",
    });
  }

  if (aaaid) {
    garageHeart(aaaid);
  }

  $.ajax({
    dataType: "html",
    url: "/ajax/addcar.php?id=" + id + "&lang=" + G_LANG + "&type=5&cnt=1",
    success: function (d) {
      if (el) {
        el.attr("data-tooltip", el.attr("data-tooltip-replace"));
      }

      setGarageNumber(d);

      $("#garageHeart" + id).addClass("active");

      if (aaaid) {
        //fbq('track', 'AddToWishlist', {content_ids: [aaaid],content_type: 'product',value: price,currency: currency});
      }
    },
    error: function () {
      showLoginForm(false, ["addcar", id, 5]);
    },
  });
  return false;
}

function deleteCarFromGarage(id, e, el) {
  $.ajax({
    dataType: "html",
    url: "/ajax/delcar.php?id=" + id + "&lang=" + G_LANG + "&type=5&cnt=1",
    success: function (d) {
      if (el) {
        el.attr("data-tooltip", el.attr("data-tooltip-default"));
      }

      setGarageNumber(d);

      $("#garageHeart" + id).removeClass("active");
    },
    error: function () {
      showLoginForm();
    },
  });
  return false;
}

$(document).ready(function () {
  /*	$('body').on('click', '.cookiebarBtn', function(){
		setTimeout(cookiebarBtnClicked, 2000);
	}); */
  cebiaBox();
  headerRotating();

  setVw();
  $(window).resize(setVw);

  function checkGoogtrans() {
    if (document.location.hash.indexOf("googtrans") > -1) {
      var textFrame = $(
        ".leftText.layout-fuller iframe:first, .leftText.layout-full iframe:first",
      );
      if (textFrame.length) {
        var l = document.location.hash.substring(14, 16);
        textFrame[0].contentWindow.postMessage(
          { translate: l },
          "https://new-m.aaaauto." + G_LANG,
        );
        console.log({ translate: l });
      }
      clearInterval(checkGoogtransInterval);
      if (
        !document.getElementById("exponea-banner-top") &&
        $("#modern-header.fixed").length
      ) {
        $("header").css("margin-top", transheight + "px");
      }
    } else if (
      isBeingTranslated() &&
      !document.getElementById("exponea-banner-top") &&
      $("#modern-header").length
    ) {
      $("header").css("margin-top", transheight + "px");
    }
  }
  var checkGoogtransInterval = setInterval(checkGoogtrans, 1000);

  if (window.location.href.indexOf("show-popup=callus") > -1) {
    $(".headerTools #open-callback-form").click();
  }

  $(window).on("message onmessage", function (e) {
    var data = e.originalEvent.data;
    //console.log(data);

    var domain = window.location.host.substring(
      window.location.host.lastIndexOf(".") + 1,
    );
    if (
      e.originalEvent.origin == "https://new-m.aaaauto." + domain ||
      e.originalEvent.origin == "https://beta-m.aaaauto." + domain ||
      e.originalEvent.origin == "https://dev2.aaaauto." + domain ||
      e.originalEvent.origin == "https://identity-beta.aaaauto." + domain ||
      e.originalEvent.origin == "https://identity.aaaauto." + domain
    ) {
      if (
        data.message == "iframeToken" ||
        data.message == "iframeTokenNoRedir"
      ) {
        $.getJSON(
          "/ajax/saveGarageToken.php?token=" +
            encodeURIComponent(data.value) +
            (typeof jsactionURL != "undefined" ? "&" + jsactionURL : ""),
          function (ret) {
            if (
              data.message != "iframeTokenNoRedir" &&
              !$.cookie("loginFormNoRedir")
            ) {
              if (ret && ret.reload) {
                window.location.reload();
              } else if (ret && ret.redirect) {
                window.location.href = ret.redirect;
              }
            } else {
              tb_remove();
              $.cookie("loginFormNoRedir", null, { path: "/" });

              //reload
              var iframe = document.getElementById("visitedCarsFrame");
              $(iframe).css("opacity", 0.2);
              $("#visitedCarsLoaderblock").addClass("loaderblock");
              iframe.onload = function () {
                $(iframe).css("opacity", 1);
                $("#visitedCarsLoaderblock").removeClass("loaderblock");
              };
              iframe.src =
                iframe.src + "&token=" + encodeURIComponent(data.value);
            }
            reloadNotifications();
          },
        );
      } else if (data.message == "iframeScrollOffset") {
        var urlParams = new URLSearchParams(window.location.search);
        var offset = urlParams.get("iframeScrollOffset");
        if (offset && offset == data.value[0].id) {
          var frames = document.getElementsByTagName("iframe");
          for (var i = 0; i < frames.length; i++) {
            if (
              $(frames[i]).attr("src") &&
              frames[i].contentWindow === e.originalEvent.source
            ) {
              iframeStartPositionParent = data.value[1].offset;
              $("html, body")
                .stop()
                .animate({ scrollTop: data.value[1].offset }, 250);
            }
          }
        }
      } else if (data.message == "popupScrollToFocus") {
        iframeStartPosition = data.value;
      } else if (data.message == "openGalleryPopup" && data.value) {
        $("html").css("overflow", "hidden");
        var lightboxWidth = $(window).width();
        var lightboxHeight = $(window).height();
        tb_show(
          "",
          data.value +
            "&TB_iframe=true&className=inhouse+opaque+corners+social+fullWidth+white-close&width=" +
            lightboxWidth +
            "&height=" +
            lightboxHeight,
          false,
          function () {
            $("html").css("overflow", "auto");
          },
        );
      } else if (data.message == "garageHeight") {
        $("#inhouseGarageIframe").height(data.value);
      } else if (data.message == "showLoginForm") {
        //tb_remove();
        showLoginForm();
      } else if (data.message == "showRegForm") {
        //tb_remove();
        showRegForm();
      } else if (data.message == "recentlyUsedHeight") {
        //console.log("recentlyUsedHeight", data.value);
        if ($("#visitedCarsFrame").height() == 0) {
          $("#visitedCarsFrame").animate({ height: data.value }, 600);
        } else {
          $("#visitedCarsFrame").height(data.value);
        }
      } else if (data.message == "iframeHeight") {
        if (document.getElementById("inhouseGarageIframe")) {
          $("#inhouseGarageIframe").css("height", data.value + "px");
        } else {
          $(".leftText iframe").height(data.value);
        }
      } else if (data.type == "iframe-height") {
        if (document.getElementById("aaa-hpiframe")) {
          $("#aaa-hpiframe").css("height", data.height + "px");
        }
      } else if (data.message == "popupClose") {
        tb_remove();
      } else if (data.message == "addToGarage") {
        $.cookie("loginFormNoRedir", 1, { path: "/" });
        addCarToGarageAAAID(data.value);
      } else if (
        data.message == "cookiebarOpen" ||
        data.message == "openCookiebar"
      ) {
        if (data.value) {
          $("a[data-cookiebar-open]").click();
        } else {
          $('button[data-cookie-save="decline"]').click();
        }
      } else if (data.message == "hashScrollPosition") {
        //console.log('hashScrollPosition ' + data.value);
        /*var textFrame = $('.leftText.layout-fuller iframe:first, .leftText.layout-full iframe:first');
				if(textFrame.length){
					$('html,body').stop(true, true).animate({scrollTop:data.value + textFrame.offset().top},800);
				}*/
        $("html,body").stop(true, true).animate({ scrollTop: data.value }, 800);
      } else if (data.message == "popupOpen") {
        $("html,body").stop(true, true).animate({ scrollTop: data.value }, 500);
      } else if (data.message == "popupOpenOld" && data.value == "#moreInfo") {
        $("#info-button-hidden").click();
      } else if (
        data.message == "popupSize" &&
        data.value[0] > 1 &&
        data.value[1] > 1
      ) {
        var w = data.value[0];
        var h = data.value[1];

        if (h < $(window).height()) {
          $("#TB_window")
            .css("height", h + "px")
            .css("width", w + "px")
            .css("margin-top", -0.5 * h + "px");
        }
        $("#TB_iframeContent")
          .css("height", h + "px")
          .css("width", w + "px")
          .css("opacity", "1");
        $("#TB_closeWindowButton").css("bottom", h - 35 + "px");
      }
    }
  });

  saleCountdown();

  $(document).on("click", ".cky-btn", function () {
    $.cookie("cky-reaction", "1", { expires: 30, path: "/" });
  });

  $(".container-fluid.menu .main-menu li.item").mouseenter(function () {
    $(".container-fluid.menu .submenu").hide();
    $(".submenu", this).show();
    $(".container-fluid.menu .main-menu li.item").removeClass("hover");
    $(this).closest(".item").addClass("hover");
  });
  $(".container-fluid.menu .main-menu").mouseleave(function () {
    $(".container-fluid.menu .main-menu li.item").removeClass("hover");
    $(".container-fluid.menu .submenu").hide();
  });

  $(
    "header.modern2018 nav > ul > li, header.modern2018 .garage-container, header.modern2018 .notifications-container-svg, header.modern2018 .notifications-container, header.modern2018 .phone-container",
  ).mouseenter(function () {
    $("header.modern2018 .submenu").hide();
    $("header.modern2018 li").removeClass("hover");

    if (!$(".submenu", this).length) {
      $("#modern-header .page-overlay").stop(true, false).fadeOut(200);
      return;
    }
    $("#modern-header .page-overlay").stop(true, false).fadeIn(200);
    $(".submenu", this).show();
    $(this).addClass("hover");
  });
  $(
    "header.modern2018 nav, header.modern2018 .garage-container, header.modern2018 .notifications-container-svg, header.modern2018 .phone-container, header.modern2018 .notifications-container",
  ).mouseleave(function () {
    $("header.modern2018 li, header.modern2018 .phone-container").removeClass(
      "hover",
    );
    $("header.modern2018 .submenu").hide();
    $("#modern-header .page-overlay").stop(true, false).fadeOut(200);
  });
  $(
    "header.modern2018 .search-container span, header.modern2018 .search-container-svg span",
  ).click(function () {
    $("header.modern2018 nav, header.modern2018 .header-container").fadeOut(
      100,
      function () {
        $("header.modern2018 .search-form .submenu").show();
        $("header.modern2018 .search-form input[type=text]").focus();
        $("#modern-header .page-overlay").stop(true, false).fadeIn(200);
        $("header.modern2018 .search-form").fadeIn(100);
      },
    );
  });
  $("header.modern2018 .close-button").click(function () {
    $("#modern-header .page-overlay").stop(true, false).fadeOut(200);
    $("header.modern2018 .search-form").fadeOut(100, function () {
      $("header.modern2018 nav, header.modern2018 .header-container").fadeIn(
        100,
      );
    });
    return false;
  });

  if (
    $("header.modern2018 .notifications-container").length ||
    $(".header.fullwidth #notifications-desktop").length ||
    $("header.modern2018 .notifications-container-svg").length
  ) {
    notifications();
  }

  if ($(".headerSearch").length) {
    ($(".searchButton").click(function () {
      $(".headerSearch").show();
      $("#header-search-input-value").focus();
      $(".headerToolsItem, .headerTranslate").hide();
    }),
      $(".headerSearchClose").click(function () {
        $(".headerSearch").hide();
        $(".headerToolsItem, .headerTranslate").show();
      }),
      $(".headerMenu .hasSubmenu").on("mouseenter", function () {
        ($(".headerMenu .hasSubmenu").removeClass("hover"),
          $(this).addClass("hover"));
      }),
      $(".headerMenu > ul").on("mouseleave", function () {
        $(".headerMenu .hasSubmenu").removeClass("hover");
      }));
  }

  //notificationsAdd(6, 'notificationName1', 'infoFill', 'primaryAlt', 'Nová výkupní pobočka 1', 'V Horní Dolní, na ulici Dlouhá 1234/56 jsme pro vás otevřeli novou, komfortní výkupní pobočku.', 'warning', false);

  /*
	$('.container-fluid.header .count-container.with-magnifier').click(function(){
		$('.filter-search .search-button.opener').click();
	});


	$('.filter-search .search-button.opener').click(function(){
		if(!$('.filter-search .filter-form').is(':visible')){
			$(this).hide();
			$('.container-fluid.menu .garage-container').hide();
			$('.filter-search .filter-form').removeClass('hide').hide().fadeIn(300);
			$('.filter-search .filter-form .text').focus();
			$('.container-fluid.menu .filter-submenu.links').removeClass('hide').hide().slideDown(300);
		}
		return false;
	});
	$('.filter-search .close-button').click(function(){
		$('.filter-search .filter-form').fadeOut(300);
		$('.container-fluid.menu .filter-submenu.links').slideUp(300);
		$('.container-fluid.menu .filter-submenu.hint').slideUp(300);
		$('.container-fluid.menu .garage-container').fadeIn(300);
		$('.filter-search .search-button.opener').fadeIn(300);
		return false;
	});
	*/

  $(".container-fluid.header .count-container.with-magnifier form").click(
    function () {
      $("#header-search-input-wrapper").removeClass("hide");
      if (!$("#header-search-links").is(":visible")) {
        $("#header-search-links").removeClass("hide").hide().slideDown();
      }
      $("#header-search-input-wrapper input[type=text]")
        .focus()
        .blur(function () {
          if (!$(this).val().length) {
            $("#header-search-input-wrapper").addClass("hide");
          }
          $("#header-search-links, #header-search-hint").slideUp();
        });
    },
  );

  $("#header-search-links-close").click(function () {
    $("#header-search-input-wrapper").addClass("hide");
  });

  $("#header-search-input-wrapper input[type=text]").keyup(function () {
    if ($(this).val().length) {
      $("#header-search-links").slideUp(300);
      $("#header-search-hint:not(:visible)")
        .removeClass("hide")
        .hide()
        .slideDown(300);
    } else {
      $("#header-search-links").slideDown(300);
      $("#header-search-hint").slideUp(300);
    }
  });

  if (
    $(".submenu-arrow").length ||
    !document.getElementById("dropmenu") ||
    isMobileBrowser()
  )
    return;

  var menu3 = $("#dropmenu").hasClass("menu3");
  var dropmenuTimeout = null;
  var dropmenuTimeoutOver = null;

  var r2;
  if (document.getElementById("header")) {
    r2 = $("#header").offset().left + $("#header").width() - 10;
  } else {
    r2 = $("header").offset().left + $("header").width() - 10;
  }

  var mouseIsOutside = true;

  $("#topmenu").bind("mouseoutoutside", function () {
    mouseIsOutside = true;
    clearTimeout(dropmenuTimeoutOver);
  });

  $("#dropmenu li.menu")
    .mouseenter(function () {
      if (document.location.href.indexOf("donthide") < 0) {
        $("div.columns-wrapper").css("visibility", "hidden");
        $("div.menuB").css("display", "none");
        if (typeof $this != "undefined") $this.removeClass("active");
      }
    })
    .mouseover(function () {
      clearTimeout(dropmenuTimeout);
      clearTimeout(dropmenuTimeoutOver);

      function showSubmenu($this) {
        var first = $this.hasClass("first");
        if (first) {
          //if(document.cookie.indexOf('letter')>=0){
          $this.removeClass("first").addClass("first2");
          $this.find("table").css("margin-top", "10px");
          /*	$("#dropmenu .letter").hide();
					if(!menu3){
					}
				}else{
					$.cookie('letter','1',{expires:30,path:'/'});
				}*/
        }

        var cw = $this.find("div.columns-wrapper");
        cw.css("visibility", "visible");
        if (cw.length) $this.addClass("active");

        var a = $this.children("div.menuB");

        if (a.length) {
          var mi = parseInt(
            a
              .attr("class")
              .toString()
              .replace(/^.* menub([0-9]+)$/i, "$1"),
          );
          var mb = meb[mi];
          if (mb) {
            a.html(mb.replace(/\[/g, "<").replace(/\]/g, ">"));
            meb[mi] = false;
          }
          a.css("display", "block");
        }

        mouseIsOutside = false;
      }

      var $this = $(this);
      if (mouseIsOutside) {
        dropmenuTimeoutOver = setTimeout(function () {
          showSubmenu($this);
        }, 200);
      } else {
        showSubmenu($this);
      }
    })
    .mouseout(function () {
      if (document.location.href.indexOf("donthide") < 0) {
        $this = $(this);
        dropmenuTimeout = setTimeout(function () {
          $this.removeClass("active");
          $this.find("div.columns-wrapper").css("visibility", "hidden");
          $this.children("div.menuB").css("display", "none");
        }, 10);
      }
    })
    .each(function () {
      var c = $(this).find("div.columns-wrapper");
      if (c.length && !menu3) {
        o = (l2 = c.offset().left) + c.width();
        o > r2 ? c.offset({ left: r2 - c.width() }) : null;

        var l = l2 - c.offset().left + (c.parent(".menu").width() - 8) / 2;
        c.prepend($("<div></div>").addClass("submenu-arrow").css("left", l));
      }
    });

  $("#dropmenu .menu a.main:last").css("border", "0");
});

function saleCountdown() {
  $(".sale-countdown").each(function () {
    var thisElement = $(this),
      secs = $(this).attr("data-countdown-time"),
      currentSeconds = 0,
      currentMinutes = 0;

    setInterval(function Decrement() {
      currentDays = Math.floor(secs / (24 * 3600));
      currentHours = Math.floor(secs / 60 / 60) % 24;
      currentMinutes = Math.floor(secs / 60) % 60;
      currentSeconds = secs % 60;
      currentSeconds <= 9 && (currentSeconds = "0" + currentSeconds);
      secs--;

      thisElement.find("span[data-label-1]:eq(0) span").text(currentDays);
      thisElement.find("span[data-label-1]:eq(1) span").text(currentHours);
      thisElement.find("span[data-label-1]:eq(2) span").text(currentMinutes);
    }, 1e3);
  });
}

function notifications() {
  //setTimeout(function() {
  if (
    ($(".notificationsLoading").hide(),
    0 <
      $(".notifications ul:not(.notificationsRead) li").length +
        $(".notifications ul.notificationsRead li").length)
  ) {
    var notificationsNewNotificationTimer;
    (0 < $(".notifications ul.notificationsRead li").length &&
      $(".notificationsTitle, .notificationsRead").css("display", "block"),
      $("#notifications-desktop").addClass("active"),
      notificationsNumber(),
      $(document).on("click", ".notificationsRead", function () {
        var notificationId = $(this).attr("data-id");
        ($(
          '.notifications ul:not(.notificationsRead) li[data-id="' +
            notificationId +
            '"]',
        ).appendTo($(".notifications ul.notificationsRead")),
          $(".newNotification").attr("data-id") == notificationId &&
            ($('.newNotification[data-id="' + notificationId + '"]')
              .addClass("hiddenNotification")
              .fadeOut(2 * animateSpeed),
            clearTimeout(notificationsNewNotificationTimer),
            notificationsAnimate()),
          $(".notifications ul.notificationsRead")
            .find("li")
            .sort(notificationsAddSort)
            .appendTo($(".notifications ul.notificationsRead")),
          0 < $(".notifications ul.notificationsRead li").length &&
            $(".notificationsTitle, .notificationsRead").css(
              "display",
              "block",
            ),
          $.cookie(notificationId, "false", {
            path: "/",
            domain: window.location.hostname,
          }),
          notificationsNumber());
      }),
      $(document).on(
        "click",
        ".newNotificationClose.notificationsRead",
        function () {
          (clearTimeout(notificationsNewNotificationTimer),
            notificationsAnimate());
        },
      ));

    if (0 < $(".notifications ul:not(.notificationsRead) li.active").length) {
      var notificationsActive =
        null != $.cookie("notificationsActive")
          ? parseInt($.cookie("notificationsActive"))
          : void 0;
      null == notificationsActive ||
      notificationsActive >=
        $(".notifications ul:not(.notificationsRead) li.active").length - 1
        ? (notificationsActive = 0)
        : (notificationsActive += 1);

      $.cookie("notificationsActive", notificationsActive, {
        path: "/",
        domain: window.location.hostname,
      });
      var notificationsActiveElement = $(".notifications li.active").eq(
        notificationsActive,
      );

      (newNotification(
        notificationsActiveElement.attr("data-icon"),
        notificationsActiveElement.find("h4").html(),
        notificationsActiveElement.find(".notificationsContent").html(),
        notificationsActiveElement.attr("data-id"),
        notificationsActiveElement.attr("data-important"),
        !0,
        "notificationsRead",
      ),
        (notificationsNewNotificationTimer = setTimeout(function () {
          notificationsNewNotificationHide();
        }, 2e4)));

      $(".newNotification").on({
        mouseenter: function () {
          clearTimeout(notificationsNewNotificationTimer);
        },
        mouseleave: function () {
          notificationsNewNotificationTimer = setTimeout(function () {
            notificationsNewNotificationHide();
          }, 2e4);
        },
      });
    }

    notificationsAnimate();

    $(
      "#notifications-desktop:not(.notifications-container-svg) .notifications, #notifications-desktop.inhouse .notifications",
    ).mCustomScrollbar({
      scrollButtons: {
        enable: !0,
      },
      theme: "light-thick",
      scrollbarPosition: "outside",
    });

    notificationSVG();
  } else {
    $("#notifications-desktop .mtooltip__footer").append(
      '<div id="notifications-no-data">' +
        $("#notifications-desktop").attr("data-no-data") +
        "</div>",
    );
    $("#notifications-desktop.active .mtooltip .notifications").hide();
  }
  //}, 5e3)
}
function notificationsAnimate() {
  $(".notificationsNumber").addClass("animate");
  $(".notificationsIcon").addClass("animate");
}

function notificationsNewNotificationHide() {
  (notificationsAnimate(),
    $(".newNotification")
      .addClass("hiddenNotification")
      .fadeOut(2 * animateSpeed));
}

function notificationsAdd(
  order,
  id,
  icon,
  iconColor,
  title,
  content,
  important,
  newNotification,
  link,
) {
  $("#notifications-no-data").hide();
  var newNotificationClass = newNotification ? "active" : "";
  link =
    void 0 !== link && 0 < link.length
      ? ' <a href="' +
        link +
        '">' +
        $("#notifications-desktop").attr("data-more") +
        "</a>"
      : "";
  null == $.cookie(id) &&
    $.cookie(id, "true", {
      path: "/",
      domain: window.location.hostname,
    });
  var markAsRead = $("#notifications-desktop").attr("data-mark-as-read");
  var notificationsUl = $(".notifications ul:not(.notificationsRead)");
  ("true" != $.cookie(id) &&
    (notificationsUl = $(".notifications ul.notificationsRead")),
    notificationsUl.append(
      '<li data-id="' +
        id +
        '" data-important="' +
        important +
        '" data-icon="' +
        icon +
        '" data-icon-color="' +
        iconColor +
        '" data-order="' +
        order +
        '" class="' +
        newNotificationClass +
        '"><h4>' +
        title +
        '</h4><div class="row"><img src="/images/modern/svg/' +
        icon +
        '.svg" alt="' +
        title +
        '" class="svg iconMin ' +
        iconColor +
        ' mr10"><div class="notificationsContent"><p>' +
        content +
        link +
        '</p></div></div><span data-id="' +
        id +
        '" class="notificationsRead" title="' +
        markAsRead +
        '"><img src="/images/modern/svg/check.svg" class="svg primary"></span></li>',
    ),
    notificationsUl
      .find("li")
      .sort(notificationsAddSort)
      .appendTo(notificationsUl));

  notifications();
  //notificationSVG();
  //$("#notifications-desktop .mtooltip .notifications").show();
}

function notificationsNumber() {
  $(".notificationsNumber").removeClass("hide");
  $(".notificationsNumber, .notifications__title-count").html(
    $(".notifications ul:not(.notificationsRead) li").length,
  );
  $(".notifications ul:not(.notificationsRead) li").length < 1 &&
    $("#notifications-desktop .notificationsNumber").hide();
  $(".notifications ul:not(.notificationsRead) li").length < 1 &&
    $(".notifications__title-count").hide();
}

function notificationsAddSort(a, b) {
  return $(b).data("order") < $(a).data("order") ? 1 : -1;
}

function newNotification(
  icon,
  title,
  content,
  id,
  important,
  close,
  closeClass,
) {
  if (!$(".newNotification:not(.hiddenNotification)").length) {
    ($(
      '<div class="newNotification ' +
        important +
        'Bg" data-id="' +
        id +
        '"><img src="/images/modern/svg/' +
        icon +
        '.svg" class="newNotificationIcon white svg iconSmall"><span><h4>' +
        title +
        "</h4>" +
        content +
        "</span>" +
        (1 == close
          ? '<span class="newNotificationClose ' +
            closeClass +
            '" data-id="' +
            id +
            '"><img src="/images/modern/svg/close.svg" class="svg white"></span>'
          : "") +
        "</div>",
    ).insertAfter("header > .container"),
      notificationSVG());
  }
}

function newNotificationClose() {
  $(document).on("click", ".newNotificationClose", function () {
    $(this)
      .parents(".newNotification")
      .addClass("hide")
      .fadeOut(2 * animateSpeed);
  });
}

function notificationSVG() {
  setTimeout(function () {
    var imgIcons = [],
      imgIconsReplaced = [],
      actualIcon = [];
    $("#notifications-desktop img.svg, .newNotification img.svg").each(
      function (index) {
        var img = $(this),
          imgID = img.attr("id"),
          imgClass = img.attr("class"),
          imgURL = img.attr("src");
        actualIcon[index] = $.get(
          imgURL,
          function (data) {
            if ($.inArray(imgURL, imgIcons) < 0) {
              imgIcons.push(imgURL);
              var svg = $(data).find("svg");
              (void 0 !== imgID && (svg = svg.attr("id", imgID)),
                void 0 !== imgClass &&
                  (svg = svg.attr("class", imgClass + " svgReplaced")),
                !(svg = svg.removeAttr("xmlns:a")).attr("viewBox") &&
                  svg.attr("height") &&
                  svg.attr("width") &&
                  svg.attr(
                    "viewBox",
                    "0 0 " + svg.attr("height") + " " + svg.attr("width"),
                  ),
                img.replaceWith(svg),
                imgIconsReplaced.push(svg));
            } else
              $.when(actualIcon[imgIcons.indexOf(imgURL)]).done(function () {
                img.replaceWith(
                  imgIconsReplaced[imgIcons.indexOf(imgURL)]
                    .clone()
                    .attr("id", imgID)
                    .attr("class", imgClass),
                );
              });
          },
          "xml",
        );
      },
    );
  }, animateSpeed);
}

function recommendedSmoothScroll(el) {
  el = el ? el : wrapperElement;

  var arrow =
    '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 50 50" version="1.1" class="svg iconMin primaryAlt"><path class="primary" style="stroke:none;fill-rule:nonzero;fill:#005da8;fill-opacity:1;" d="M 34.980469 3.992188 C 34.71875 3.996094 34.472656 4.105469 34.292969 4.292969 L 14.292969 24.292969 C 13.902344 24.683594 13.902344 25.316406 14.292969 25.707031 L 34.292969 45.707031 C 34.542969 45.96875 34.917969 46.074219 35.265625 45.980469 C 35.617188 45.890625 35.890625 45.617188 35.980469 45.265625 C 36.074219 44.917969 35.96875 44.542969 35.707031 44.292969 L 16.414063 25 L 35.707031 5.707031 C 36.003906 5.417969 36.089844 4.980469 35.929688 4.601563 C 35.769531 4.21875 35.394531 3.976563 34.980469 3.992188 Z"></path></svg>';

  $(".smoothScroll", el).each(function () {
    if (!$(this).find("button").length) {
      ($(this).prepend('<button class="arrow left">' + arrow + "</button>"),
        $(this).append('<button class="arrow right">' + arrow + "</button>"));
    }
    $(this)
      .find("button")
      .click(function (e) {
        e.preventDefault();
      });
  });

  $(".smoothScroll", el).each(function () {
    $(this).removeClass("rightArrow").find(".arrow").hide();
    $(this).find(".smoothScrollInner").width() <
      $(this).find(".smoothScrollItems").width() &&
      $(this).addClass("rightArrow") &&
      $(this).find(".arrow.right").show();
  });

  $(".smoothScrollInner", el)
    .unbind("scroll")
    .scroll(function () {
      var smoothScrollPosition = $(this)
          .parents(".smoothScroll")
          .find(".smoothScrollInner")
          .scrollLeft(),
        smoothScrollInner = $(this)
          .parents(".smoothScroll")
          .find(".smoothScrollInner")
          .width(),
        smoothScrollItems = $(this)
          .parents(".smoothScroll")
          .find(".smoothScrollItems")
          .width();
      (0 == smoothScrollPosition
        ? $(this)
            .parents(".smoothScroll")
            .find(".arrow.left")
            .fadeOut(2 * animateSpeed)
        : $(this)
            .parents(".smoothScroll")
            .find(".arrow.left")
            .fadeIn(2 * animateSpeed),
        smoothScrollItems <= smoothScrollPosition + smoothScrollInner
          ? $(this)
              .parents(".smoothScroll")
              .find(".arrow.right")
              .fadeOut(2 * animateSpeed)
          : $(this)
              .parents(".smoothScroll")
              .find(".arrow.right")
              .fadeIn(2 * animateSpeed));
    });

  $(".smoothScroll", el).each(function () {
    if (
      $(this).find(".smoothScrollInner").width() <
      $(this).find(".smoothScrollItems").width()
    ) {
      $(this).find(".arrow.right").show();
    }
  });

  var smoothScrollTo = 0;
  $(".smoothScroll", el)
    .find(".arrow")
    .on("click", function () {
      var smoothScrollPosition = $(this)
        .parents(".smoothScroll")
        .find(".smoothScrollInner")
        .scrollLeft();
      var smoothScrollInner = $(this)
        .parents(".smoothScroll")
        .find(".smoothScrollInner")
        .width();

      if ($(this).hasClass("left")) {
        $(this)
          .parents(".smoothScroll")
          .find(".smoothScrollInner")
          .animate(
            { scrollLeft: smoothScrollPosition - smoothScrollInner },
            1000,
          );
      } else {
        $(this)
          .parents(".smoothScroll")
          .find(".smoothScrollInner")
          .animate(
            { scrollLeft: smoothScrollPosition + smoothScrollInner },
            1000,
          );
      }
    });
  $(window).resize(function () {
    $(".smoothScroll", el).each(function () {
      if (
        $(this).find(".smoothScrollInner").width() <
        $(this).find(".smoothScrollItems").width()
      ) {
        $(this).find(".arrow.right").show();
      } else {
        $(this).find(".arrow.right").hide();
        $(this).find(".arrow.left").hide();
      }
    });
  });

  $(".smoothScroll", el)
    .find(".smoothScrollInner")
    .scroll(function () {
      var smoothScrollPosition = $(this)
        .parents(".smoothScroll")
        .find(".smoothScrollInner")
        .scrollLeft();
      var smoothScrollInner = $(this)
        .parents(".smoothScroll")
        .find(".smoothScrollInner")
        .width();
      var smoothScrollItems = $(this)
        .parents(".smoothScroll")
        .find(".smoothScrollItems")
        .width();

      if (smoothScrollPosition == 0) {
        $(this).parents(".smoothScroll").find(".arrow.left").fadeOut(500);
      } else {
        $(this).parents(".smoothScroll").find(".arrow.left").fadeIn(500);
      }
      if (smoothScrollPosition + smoothScrollInner >= smoothScrollItems) {
        $(this).parents(".smoothScroll").find(".arrow.right").fadeOut(500);
      } else {
        $(this).parents(".smoothScroll").find(".arrow.right").fadeIn(500);
      }
    });
}

function garageHeart(aaaid) {
  try {
    (function () {
      var prefix = "",
        hash = "1Tqhh3goLIEQimOGPcoW",
        rtbhTags = [];
      rtbhTags.push("pr_" + hash + "_wishlist_" + aaaid);
      var key = "__rtbhouse.lid",
        lid = window.localStorage.getItem(key);
      if (!lid) {
        lid = "";
        var pool =
          "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        for (var i = 0; i < 20; i++)
          lid += pool.charAt(Math.floor(Math.random() * pool.length));
        window.localStorage.setItem(key, lid);
      }
      rtbhTags.push("pr_" + hash + "_lid_" + lid);
      var ifr = document.createElement("iframe"),
        sr = encodeURIComponent(document.referrer ? document.referrer : ""),
        su = encodeURIComponent(
          document.location.href ? document.location.href : "",
        ),
        ifrSrc = "https://" + prefix + "creativecdn.com/tags?type=iframe",
        tmstmp = encodeURIComponent("" + Date.now());
      for (var i = 0; i < rtbhTags.length; i++) {
        ifrSrc += "&id=" + encodeURIComponent(rtbhTags[i]);
      }
      ifrSrc += "&su=" + su + "&sr=" + sr + "&ts=" + tmstmp;
      ifr.setAttribute("src", ifrSrc);
      ifr.setAttribute("width", "1");
      ifr.setAttribute("height", "1");
      ifr.setAttribute("scrolling", "no");
      ifr.setAttribute("frameBorder", "0");
      ifr.setAttribute("style", "display:none");
      ifr.setAttribute("referrerpolicy", "no-referrer-when-downgrade");
      if (document.body) {
        document.body.appendChild(ifr);
      } else {
        window.addEventListener("DOMContentLoaded", function () {
          document.body.appendChild(ifr);
        });
      }
    })();
  } catch (e) {}
}

function shortenCardLabels(singleline, carsColumns) {
  $(".carsColumns .card .carFeatures h2").each(function () {
    var _this = $(this);
    var span = _this.find("span.hide");
    if (span.length) {
      var oldHeight = _this.height();
      span.attr("style", "display:inline !important");
      var newHeight = _this.height();
      if (newHeight > oldHeight) {
        span.attr("style", "display:none !important");
      }
    }
  });

  $(".card .carFeatures > p").each(function () {
    var origHeadline = $(this).text();
    var headline = $(this);
    headline.css("height", "auto").css("overflow", "visible");
    var limit = singleline ? 25 : 66;

    var beenStripped = false;

    while (headline.height() > limit) {
      var txt = headline.html();
      txt = txt.replace(/,\s*$/);

      var stripped = txt.substring(txt.lastIndexOf(","));
      if (!carsColumns && stripped.indexOf("VIN:") > -1) {
        txt = txt.substring(0, txt.lastIndexOf(","));
        txt = txt.substring(0, txt.lastIndexOf(",")) + stripped;
      } else {
        txt = txt.substring(0, txt.lastIndexOf(","));
      }
      beenStripped = true;
      headline.html(txt);

      if (singleline) {
        headline
          .attr("data-tooltip", origHeadline)
          .attr("data-tooltip-card", "true")
          .css("z-index", 1000);
      }
    }

    headline.html(headline.html().replace(/^, /, ""));
    headline.css("height", singleline ? "30px" : "48px");

    if (singleline) {
      headline.css("white-space", "nowrap");

      if (beenStripped) headline.html(headline.html() + "...");

      var eq = headline.closest(".card").find(".carFeatures ul.equipment");
      eq.css("height", "auto").css("overflow", "visible");
      var limit = 75;

      var removed = 0;
      var toberemoved;

      var others = new Array();

      while (eq.height() > limit) {
        toberemoved = eq.find("li:not(.link):last");
        others.push(toberemoved.text());

        toberemoved.remove();
        removed++;
      }
      eq.css("height", limit + "px");
      var strong = eq.find(".link strong");
      if (removed) {
        strong.html(
          strong
            .attr("data-form" + (removed == 1 ? "1" : removed < 5 ? "2" : "3"))
            .replace("XX", removed),
        );
      } else {
        strong.remove();
      }
    }
  });
}

function cebiaBox() {
  ("closed" == $.cookie("cebia-box") || !$.cookie("cebia-box")
    ? $(".cebia-box__banner, .cebia-box").addClass("cebia-box__banner--active")
    : $(".cebia-box__main").addClass("cebia-box__main--active"),
    $(document).on("click", ".cebia-box .cebia-box__close", function () {
      ($(".cebia-box__main").removeClass("cebia-box__main--active"),
        $(".cebia-box__banner, .cebia-box").addClass(
          "cebia-box__banner--active",
        ),
        $.cookie("cebia-box", "closed", { expires: 7, path: "/" }));
    }),
    $(document).on("click", ".cebia-box .cebia-box__banner", function () {
      ($(".cebia-box__main").addClass("cebia-box__main--active"),
        $(".cebia-box__banner, .cebia-box").removeClass(
          "cebia-box__banner--active",
        ),
        $.cookie("cebia-box", "opened", { expires: 7, path: "/" }));
    }));
}

function headerRotating() {
  if ($(".header-rotating").hasClass("started")) {
    return;
  }

  $(".header-rotating").addClass("started");
  var width;
  $(".header-rotating").length &&
    2 <= $(".header-rotating__item").length &&
    ((width = 0),
    $(".header-rotating__item:not(.header-rotating__item--active)").show(),
    $(".header-rotating__item").each(function () {
      var itemWidth = $(this).outerWidth(!0);
      width < itemWidth && (width = itemWidth);
    }),
    $(".header-rotating__item").hide(),
    $(".header-rotating").css("width", width + "px"),
    $(".header-rotating__item").addClass("header-rotating__item--loaded"),
    setTimeout(function () {
      $(".header-rotating__item").addClass("header-rotating__item--done");
    }, 10),
    setInterval(function () {
      var activeItem = $(".header-rotating__item--active"),
        activeIndex = $(".header-rotating__item").index(activeItem[0]),
        activeIndex =
          activeIndex + 1 >= $(".header-rotating__item").length
            ? 0
            : activeIndex + 1;
      (activeItem.removeClass("header-rotating__item--active"),
        $(".header-rotating__item")
          .eq(activeIndex)
          .addClass("header-rotating__item--active"));
    }, 5e3));
}

function generateGaUniqueId() {
  // První část: hexadecimální řetězec z timestampu
  const timestamp = Date.now(); // milisekundy od epochy
  const randomHex = timestamp.toString(16); // převedeme na hex

  // Druhá část: náhodné 8místné číslo
  const randomNumber = Math.floor(Math.random() * 90000000) + 10000000;

  return `${randomHex}.${randomNumber}`;
}

// ##########################################################################################################################################################
// GA4
// ##########################################################################################################################################################

function generateGaUniqueId() {
  // První část: hexadecimální řetězec z timestampu
  const timestamp = Date.now(); // milisekundy od epochy
  const randomHex = timestamp.toString(16); // převedeme na hex

  // Druhá část: náhodné 8místné číslo
  const randomNumber = Math.floor(Math.random() * 90000000) + 10000000;

  return `${randomHex}.${randomNumber}`;
}

function trackAddToWishlist(aaaid) {
  var ga_unique_id = generateGaUniqueId();
  masterLayer[0].ga_unique_id = ga_unique_id;

  aaafbcq_send([
    {
      event_name: "AddToWishlist",
      eid: ga_unique_id,
      content_type: "vehicle",
      content_ids: [aaaid],
    },
  ]);
}

//inhouse karta
$("[data-ga-event-event=click_tlacitko_add_to_wishlist]").click(function () {
  trackAddToWishlist($(this).attr("data-car-id"));
});

if (typeof galleryTabClicked == "undefined") {
  // pageType variable is declared in base.html.twig !
  let galleryTabClicked = false;

  $(document).on("click", ".headerMenu .submenu a", function () {
    let menuName = $(this)
      .closest(".hasSubmenu")
      .find(".submenuLink")
      .text()
      .toLowerCase()
      .normalize("NFD")
      .replace(/[\u0300-\u036f]/g, "")
      .replace(/[^a-z0-9 _ |]/gi, "")
      .replace(/ /g, "_")
      .replace(/__/g, "_");

    let categoryName = $(this)
      .text()
      .toLowerCase()
      .normalize("NFD")
      .replace(/[\u0300-\u036f]/g, "")
      .replace(/[^a-z0-9 _ |]/gi, "")
      .replace(/ /g, "_")
      .replace(/__/g, "_");
    gaMasterLayer = {
      event: "click_menu_" + menuName + "_" + categoryName,
    };
    trackGAeventML(gaMasterLayer);
  });

  $(document).on(
    "click",
    '[data-ga-event="click"], [data-ga-event="click-pageType"], [data-ga-event-category="tab"]',
    function (e) {
      if ($(this).attr("data-ga-event") == "click" && $(e.target).is("input"))
        return;

      let skip = false;
      let category = $(this).attr("data-ga-event-category");
      var eventClick = $(this).attr("data-ga-event");
      var event = $(this).attr("data-ga-event-event");
      var action = $(this).attr("data-ga-event-action");
      var aaaid = $(this).attr("data-aaaid") || $(this).attr("data-car-id");

      if (!event && !action) {
        var closest = $(this).closest('[data-ga-event="click"]');

        let category = closest.attr("data-ga-event-category");
        var eventClick = closest.attr("data-ga-event");
        var event = closest.attr("data-ga-event-event");
        var action = closest.attr("data-ga-event-action");
        var aaaid = closest.attr("data-aaaid") || closest.attr("data-car-id");
      }

      var gaMasterLayer = "";
      if (event.length > 0) {
        if (
          event == "click_vypis_add_to_wishlist" ||
          event ==
            "click_recom_add_to_wishlist" /* || event == "click_tlacitko_add_to_wishlist" */
        ) {
          trackAddToWishlist(aaaid);

          gaMasterLayer = {
            event: event,
          };
        } else if (
          (event == "click_dlazdice_makes" || event == "click_makes") &&
          action.length > 0
        ) {
          gaMasterLayer = {
            event: event,
            znacka: action
              .toLowerCase()
              .normalize("NFD")
              .replace(/[\u0300-\u036f]/g, ""),
          };
        } else if (category && category.includes("tab-kategorie")) {
          let categoryName = action
            .toLowerCase()
            .normalize("NFD")
            .replace(/[\u0300-\u036f]/g, "")
            .replace(/[^a-z0-9 _ |]/gi, "")
            .replace(/ /g, "_")
            .replace(/__/g, "_");
          gaMasterLayer = {
            event: "click_dlazdice_" + categoryName,
          };
        } else if (
          event.includes("vypis_main_dlazdice") ||
          event.includes("vypis_secondary_dlazdice")
        ) {
          let make = $(this).attr("data-ga-make");
          let model = $(this).attr("data-ga-model");
          gaMasterLayer = {
            event: event,
            znacka: make,
            model: model,
          };
        } else if (
          event.includes("click_main_menu") ||
          eventClick == "click-pageType"
        ) {
          if (event.includes("fulltext_search")) {
            let value = $("#header-search-input-value").val();
            gaMasterLayer = {
              event: event,
              pageType: pageType,
              search_value: value,
            };
          } else {
            //hp recommender position dependency
            if (
              event.includes("click_recom") &&
              $(this).parents(".recently-viewed").length
            ) {
              if ($(this).parents("#recently-viewed-first").length) {
                event = event.split("click_recom_");
                event = "click_recom_nz_" + event[1];
              }
              if ($(this).parents("#recently-viewed-second").length) {
                event = event.split("click_recom_");
                event = "click_recom_hledali_jste_" + event[1];
              }
              if ($(this).parents("#recently-viewed-third").length) {
                event = event.split("click_recom_");
                event = "click_recom_dopr_" + event[1];
              }
              gaMasterLayer = {
                event: event,
              };

              if (event === "click_recom_nz_сar") {
                gaMasterLayer.productId = $(this).attr("data-ga-carId");
                gaMasterLayer.pageType = pageType;
                gaMasterLayer.znacka = $(this).attr("data-ga-make");
                gaMasterLayer.model = $(this).attr("data-ga-model");
              }
            } else if (event.includes("click_recom")) {
              if ($(this).parents("#declineClose").length) {
                event = event.split("click_recom_");
                event = "click_recom_big_" + event[1];
              }
              if ($(this).parents(".fixed-recommander").length) {
                event = event.split("click_recom_");
                event = "click_recom_small_" + event[1];
              }
              gaMasterLayer = {
                event: event,
                pageType: pageType,
              };
            } else {
              if ($(this).parents(".pswpSidebar").length) {
                gaMasterLayer = {
                  event: event + "_galerie",
                  pageType: pageType,
                };
              } else {
                gaMasterLayer = {
                  event: event,
                  pageType: pageType,
                };
              }
            }
          }
        } else if (event.includes("click_vypis_porovnani")) {
          if ($("div.list-comparison").hasClass("list-comparison--active")) {
            gaMasterLayer = {
              event: "click_vypis_porovnani_off",
            };
          } else {
            gaMasterLayer = {
              event: "click_vypis_porovnani_on",
            };
          }
        } else if (
          (event.includes("click_slider") ||
            event.includes("click_akce") ||
            event.includes("click_banner")) &&
          action.length > 0
        ) {
          gaMasterLayer = {};
          gaMasterLayer.event = event;
          gaMasterLayer.marketing_campaign_name = action;
          gaMasterLayer.pageType = pageType;
          if ($(this).parents("#homepageMainSlider").length) {
            gaMasterLayer.banner_position = $(this).parent("li").index() + 1;
          }
          // gaMasterLayer = {
          //     'event': event,
          //     'marketing_campaign_name': action,
          //     'pageType': pageType
          // };
        } else if (event.includes("click_filtr")) {
          //label synthetic click prevention
          if (true) {
            //$(e.target).is('input') || $(e.target).hasClass('tag')){
            let isChecked = $(this)
              .find('input[type="checkbox"]')
              .is(":checked")
              ? true
              : false;
            gaMasterLayer = {};
            gaMasterLayer.event = event;

            if (event.includes("make")) {
              gaMasterLayer.znacka = action;
            } else if (event.includes("model")) {
              gaMasterLayer.model = action;
            } else if (event.includes("year_from")) {
              gaMasterLayer.year = action;
            } else if (event.includes("year_to")) {
              gaMasterLayer.year = action;
            } else if (event.includes("price_from")) {
              gaMasterLayer.price = action;
            } else if (event.includes("price_to")) {
              gaMasterLayer.price = action;
            } else if (event.includes("najeto_from")) {
              gaMasterLayer.najeto = action;
            } else if (event.includes("najeto_to")) {
              gaMasterLayer.najeto = action;
            } else if (event.includes("palivo")) {
              gaMasterLayer.palivo = action;
            } else if (event.includes("karoserie")) {
              gaMasterLayer.karoserie = action;
            } else if (event.includes("prevodovka")) {
              gaMasterLayer.prevodovka = action;
            } else if (event.includes("kategorie")) {
              gaMasterLayer.kategorie = action;
            } else if (event.includes("barva")) {
              gaMasterLayer.barva = action;
            }

            gaMasterLayer.pageType = pageType;
          } else {
            skip = true;
          }
        } else if (event.includes("otevreni_nove_okno")) {
          //label synthetic click prevention
          if ($(e.target).is("input:checked")) {
            gaMasterLayer = {
              event: "click_vypis_otevreni_nove_okno",
            };
          } else if ($(e.target).is("input")) {
            gaMasterLayer = {
              event: "click_vypis_otevreni_nove_okno_off",
            };
          }
        } else if (event.includes("click_vypis_serazeni")) {
          //label synthetic click prevention
          if ($(e.target).is("input")) {
            gaMasterLayer = {
              event: event,
              serazeni_vypisu: action,
            };
          } else {
            skip = true;
          }
        } else if (event.includes("click_cta_vykup")) {
          let make = $("#carValuationHomepageFormMake li.active").text().trim();
          let model = $("#carValuationHomepageFormModel button .selectVarMain")
            .text()
            .trim();
          gaMasterLayer = {
            event: event,
            znacka: make,
            model: model,
          };
        } else if (event.includes("click_galerie_zalozka")) {
          //first initial click prevention (tabs are initialized by js click on car detail)
          if (!galleryTabClicked) {
            skip = true;
            galleryTabClicked = true;
          } else {
            gaMasterLayer = {
              event: event,
            };
          }
        } else {
          if ($(this).parents(".pswpSidebar").length) {
            gaMasterLayer = {
              event: event + "_galerie",
            };
          } else {
            gaMasterLayer = {
              event: event,
            };
          }
        }
        if (!skip) {
          //console.log(gaMasterLayer);
          trackGAeventML(gaMasterLayer);
        }
      }
    },
  );

  //___________Car detail photogallery_________
  $(document).on("click", ".carouselGallery .slickArrow", function () {
    let gaMasterLayer = {
      event: "click_galerie_listovani",
    };

    trackGAeventML(gaMasterLayer);
  });
  $(document).on("click", ".pswp .pswp__button", function () {
    let gaMasterLayer = {
      event: "click_galerie_big_listovani",
    };

    trackGAeventML(gaMasterLayer);
  });
  $(document).on(
    "click",
    ".multipleTab--card-gallery .slickArrow",
    function () {
      let gaMasterLayer = {
        event: "click_galerie__small_listovani",
      };

      trackGAeventML(gaMasterLayer);
    },
  );
  $(document).on("click", ".homepageCategoryItem", function () {
    let link = $(this)
      .find("h3")
      .text()
      .toLowerCase()
      .normalize("NFD")
      .replace(/[\u0300-\u036f]/g, "")
      .replace(/ /g, "_");
    let gaMasterLayer = {
      event: "click_dlazdice_" + link,
      pageType: pageType,
    };
    //je v kodu infoboxu
    //trackGAeventML(gaMasterLayer);
  });

  $(document).on("click", ".cars-images-makes .item", function () {
    let link = $(this)
      .find(".text")
      .text()
      .toLowerCase()
      .normalize("NFD")
      .replace(/[\u0300-\u036f]/g, "")
      .replace(/ /g, "_")
      .replace(/_\([0-9]+\)/, "");
    let gaMasterLayer = {
      event: "click_dlazdice_makes",
      znacka: link, //,
      //'pageType': pageType
    };
    trackGAeventML(gaMasterLayer);
  });

  //___________Cars grid pager_________
  $(document).on("click", "#carsGrid #pager li", function () {
    let gaMasterLayer = {
      event: "click_vypis_strankovani",
    };

    trackGAeventML(gaMasterLayer);
  });

  //___________HP reviews_________
  $(document).on(
    "click",
    ".google-reviews .slick-prev, .google-reviews .slick-next",
    function () {
      let gaMasterLayer = {
        event: "click_listovani_review",
      };

      trackGAeventML(gaMasterLayer);
    },
  );

  //________Fixed recommender view_______
  let eventFired = false;
  $(document).on("scroll", function () {
    if (
      !eventFired &&
      !$(".fixed-recommander").hasClass("fixed-recommander--hidden") &&
      $(".fixed-recommander").length
    ) {
      eventFired = true;
      gaMasterLayer = {
        event: "view_recom_small",
        pageType: pageType,
      };
      trackGAeventML(gaMasterLayer);
    }
  });

  //________Recommender slider buttons________

  $(document).on(
    "click",
    ".sliderBoxes .slider .slick-next, .sliderBoxes .slider .slick-prev",
    function () {
      let gaMasterLayer;
      if ($(this).parents(".recently-viewed__content").length) {
        // gaMasterLayer={
        //     'event': 'nz_recom_click',
        // };
      } else {
        gaMasterLayer = {
          event: "click_recom_listovani",
          pageType: pageType,
        };
        trackGAeventML(gaMasterLayer);
      }
    },
  );

  $(document).on("click", "#declineClose .slickArrow", function () {
    let gaMasterLayer = {
      event: "click_recom_big_listovani",
      pageType: pageType,
    };
    trackGAeventML(gaMasterLayer);
  });

  $(document).on("click", ".fixed-recommander .slickArrow", function () {
    let gaMasterLayer = {
      event: "click_recom_small_listovani",
      pageType: pageType,
    };
    trackGAeventML(gaMasterLayer);
  });

  //______HP filter year slider________
  $(document).on(
    "click",
    "#sliderFilterYear .noUi-handle.noUi-handle-upper",
    function () {
      let year = $(this).attr("aria-valuetext").split(".");
      let gaMasterLayer = {
        event: "click_filtr_year_to",
        year: year[0],
        pageType: pageType,
      };
      trackGAeventML(gaMasterLayer);
    },
  );
  $(document).on(
    "click",
    "#sliderFilterYear .noUi-handle.noUi-handle-lower",
    function () {
      let year = $(this).attr("aria-valuetext").split(".");
      let gaMasterLayer = {
        event: "click_filtr_year_from",
        year: year[0],
        pageType: pageType,
      };
      trackGAeventML(gaMasterLayer);
    },
  );

  //______HP filter year select________
  $(document).on(
    "change filterChangeTrack",
    "#sliderFilterYearFrom",
    function () {
      let year = $(this).find("option:selected").val();
      let gaMasterLayer = {
        event: "click_filtr_year_from",
        year: year,
        pageType: pageType,
      };
      trackGAeventML(gaMasterLayer);
    },
  );
  $(document).on("change filterChange", "#sliderFilterYearTo", function () {
    let year = $(this).find("option:selected").val();
    let gaMasterLayer = {
      event: "click_filtr_year_to",
      year: year,
      pageType: pageType,
    };
    trackGAeventML(gaMasterLayer);
  });

  //______HP filter price slider________
  $(document).on(
    "click",
    "#sliderFilterPrice .noUi-handle.noUi-handle-upper",
    function () {
      let price = $(this).attr("aria-valuetext").split(".");
      let gaMasterLayer = {
        event: "click_filtr_price_to",
        price: price[0],
        pageType: pageType,
      };
      trackGAeventML(gaMasterLayer);
    },
  );
  $(document).on(
    "click",
    "#sliderFilterPrice .noUi-handle.noUi-handle-lower",
    function () {
      let price = $(this).attr("aria-valuetext").split(".");
      let gaMasterLayer = {
        event: "click_filtr_price_from",
        price: price[0],
        pageType: pageType,
      };
      trackGAeventML(gaMasterLayer);
    },
  );

  //______HP filter price select________
  $(document).on("change", "#sliderFilterPriceFrom", function () {
    let price = $(this).find("option:selected").val();
    let gaMasterLayer = {
      event: "click_filtr_price_from",
      price: price,
      pageType: pageType,
    };
    trackGAeventML(gaMasterLayer);
  });
  $(document).on(
    "change filterChangeTrack",
    "#sliderFilterPriceTo",
    function () {
      let price = $(this).find("option:selected").val();
      let gaMasterLayer = {
        event: "click_filtr_price_to",
        price: price,
        pageType: pageType,
      };
      trackGAeventML(gaMasterLayer);
    },
  );

  //_____HP tv videos section______
  $(document).on("click", ".tv-videos__slider-btn", function () {
    let gaMasterLayer = {
      event: "click_listovani_videi",
      pageType: pageType,
    };
    trackGAeventML(gaMasterLayer);
  });

  $(document).on("click", ".breadcrumb ul:first-child li", function () {
    let gaMasterLayer = {};
    let text = $(this).text().trim();
    let eventName = "click_drop_navigace";

    if ($(this).index() === 2) {
      gaMasterLayer.event = eventName + "_make";
      gaMasterLayer.znacka = text;
    }
    if ($(this).index() === 3) {
      gaMasterLayer.event = eventName + "_model";
      gaMasterLayer.znacka = text;
      text = $(this).prev().text().trim();
      gaMasterLayer.model = text;
    }
    if ($(this).index() === 4) {
      gaMasterLayer.event = eventName + "_karoserie";
      gaMasterLayer.karoserie = text;
    }
    if ($(this).index() === 5) {
      gaMasterLayer.event = eventName + "_palivo";
      gaMasterLayer.palivo = text;
    }
    trackGAeventML(gaMasterLayer);
  });

  //__________Footer links____________
  $(document).on("click", "footer a", function () {
    let link = $(this)
      .text()
      .toLowerCase()
      .normalize("NFD")
      .replace(/[\u0300-\u036f]/g, "")
      .replace(/ /g, "_");
    let gaMasterLayer = {
      event: "click_footer_menu_" + link,
      pageType: pageType,
    };
    trackGAeventML(gaMasterLayer);
  });
}