$(document).ready(function(){
  $(window).scroll(function(){
    $("header").removeClass("fixed");
    if(jQuery(window).scrollTop() > 100){
      $("header").addClass("fixed");
    }
  });  

  if($("#slideshow").length){
    slideShow = new rockSlide("#slideshow", "fade", 2000, 5000, "");
    /*
    $("#leftArrow").click(function(){
      slideShow.previous();
    });
    $("#rightArrow").click(function(){
      slideShow.next();
    });
    */
  }
  
  logoSlider = new rockSlide("#logoSlider", "fade", 2000, 5000, "");
  
  if($("#productSlider").length){
    productSlider = new rockSlide("#productSlider", "fade", 500, 5000, "");
    $(".arrow.left").click(function(){
      productSlider.previous();
    });
    $(".arrow.right").click(function(){
      productSlider.next();
    });
  }
  
  if($(".video").length){
    var width = $(window).width()
    var height = $(window).height();
    if(width >= 960){
      $(".video").colorbox({iframe:true, innerWidth:960, innerHeight:540});
    } else {
      popupWidth = width - 60;
      popupHeight = popupWidth * 0.5625;
      $(".video").colorbox({iframe:true, innerWidth:popupWidth, innerHeight:popupHeight});
    }
  }
  
  if($(".fb-share-button").length){
    var url = window.location;  
    console.log(url.href);
    $('.fb-share-button').attr('data-href', url.href);
  }
  
  $(".currentLang").click(function(){
    $("a.lang").toggleClass("hidden");
  });
  
  $(".scoreStar").click(function(){
    $(this).siblings("input").val($(this).attr("data-attr"));
    $(this).siblings(".scoreStar").removeClass("fa-star");
    $(this).siblings(".scoreStar").addClass("fa-star-o");
    for(i=1;i<$(this).attr("data-attr");i++){
      console.log(".star"+i);
      $(this).siblings(".star"+i).removeClass("fa-star-o");
      $(this).siblings(".star"+i).addClass("fa-star");
    }
    $(this).removeClass("fa-star-o");
    $(this).addClass("fa-star");
  });

  $("p.buttonHolder span").click(function(){
    $(this).siblings("input").val($(this).attr("data-attr"));
    $(this).siblings("span").removeClass("active");
    $(this).addClass("active");
  });
  
  //OPEN DAG
  $("#inputAmount").keyup(function(){
    if(parseInt($("#inputAmount").val()) > 10){
      $("#inputAmount").val(10);
    }
  
    $("p.label").show();
    for(i=1;i<11;i++){
      if(i <= parseInt($("#inputAmount").val())){
        $("#inputName"+i).show();
      } else {
        $("#inputName"+i).hide();
        $("#inputName"+i).val("");
      }
    }
  });
  $("#inputDay").change(function(){
    $("#inputInvite").hide();
    $("#inputTime").hide();
    
    if($("#inputDay").val() == "10-09-2020"){
      $("#inputTime").show();    
    } else {
      $("#inputTime").val("");
    }
    
    if($("#inputDay").val() == "11-09-2020"){
      $("#inputInvite").show();
    } else {
    
    }
  
  });
  
  //CHECKBOX
  $(".checkBox:not(.forced)").click(function(){
    if($(this).hasClass("radio")){
      $(this).parent().children(".checkBox").children("div.box").children("span").removeClass("active");  
    }
    
    $(this).children("div.box").children("span").toggleClass("active");
    if($(this).children("div.box").children("span").hasClass("active")){
      $(this).children("input").prop('checked', true);
    } else {
      $(this).children("input").prop('checked', false);
    }
  });
  
  $(".valForm").val("true");
  
  
  $("#countrySelector").change(function(){
    $.ajax({
      type : "POST",
      url  : "/js/json/getCountry.php",
      data : { country: $("#countrySelector").val()},
      dataType: "json",
      success: function(data){
        //console.log(data);
        $("#contact-phone").attr("href","tel:"+data['phone']);
        $("#contact-mail-general").attr("href","mailto:"+data['contact-mail-general']);
        $("#contact-mail-sales").attr("href","mailto:"+data['contact-mail-sales']);
        $("#contact-mail-parts").attr("href","mailto:"+data['contact-mail-parts']);
        $("#contact-mail-service").attr("href","mailto:"+data['contact-mail-service']);
        $("#contact-mail-invoice").attr("href","mailto:"+data['contact-mail-invoice']);
        $("#contact-mail-hrm").attr("href","mailto:"+data['contact-mail-hrm']);
        $("#whatsapp").attr("href",data['whatsapp']);
        $("#contact-text").html(data['contact-text']);
      }
    });
  });
});

var menuExpanded = false;
function toggleMenu() {
  if (menuExpanded) {
    $(".menuItem").fadeOut();
    //$("#menu").animate({bottom: "0px"}, {queue: false, duration: 500, complete: function() {
      menuExpanded = false;
    //}});
  } else {
    $(".menuItem:not(.homeButton)").fadeIn();
    //$("#menu").animate({bottom: "-" + ($("#menu").height()+25) + "px"}, {queue: false, duration: 500, complete: function() {
      menuExpanded = true;
    //}});
  }
}