
  var x = 1;  
  $("div > .mySlides").each(function(){
    if(x == 1){
      $("#dotspace").append("<span class='dot dotspace active' onclick='currentSlide("+ x +")'></span>\n");
    }else{
       $("#dotspace").append("<span class='dot dotspace' onclick='currentSlide("+ x +")'></span>\n");
    }
    x++;
  });

var loc = window.location.pathname;

if(loc == "/ja/menu" || loc == "/ja/menu.php" || loc == "/en/menu" || loc == "/en/menu.php") {
  var slideIndex = Math.floor((Math.random() * document.getElementsByClassName("mySlides").length));
} else {
  var slideIndex = 1;
}

var timer = null;
showSlides(slideIndex);

function plusSlides(n) {
  clearTimeout(timer);
  showSlides(slideIndex += n);
}

function currentSlide(n) {
  clearTimeout(timer);
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  if (n==undefined){n = ++slideIndex}
  if (n > slides.length) {slideIndex = 1}
  if (n < 1) {slideIndex = slides.length}
  for (i = 0; i < slides.length; i++) {
      slides[i].style.display = "none";
  }
  for (i = 0; i < dots.length; i++) {
      dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";
  dots[slideIndex-1].className += " active";
  timer = setTimeout(showSlides, 5000);
}
$(window).on('hashchange', function(e){
    history.replaceState ("", document.title, e.originalEvent.oldURL);
});

$(function(){

  $('.mySlides').click(function() {
    $.ajax({
      url:'../api/getAds.php',
      type: 'post',
      dataType: 'text',
      data: {
        location: 'menu',
        adsId: $(this).attr('id'),
        link: $(this).find('a').attr('href'),
        user_id: $('#user_id').val(),
		lang: $('html').attr('lang')
      }
    });
  });
});



