jQuery(document).ready(function($){
  $("#clients").owlCarousel({
     
      navigation : false, // Show next and prev buttons
      slideSpeed : 300,
      paginationSpeed : 400,
      autoHeight : true,
      itemsCustom : [
            [0, 1],
            [450, 2],
            [600, 2],
            [700, 2],
            [1000, 4],
            [1200, 3],
            [1400, 3],
            [1600, 3]
          ],
  });  

  var accordion = function() {
    $('.gtco-accordion-heading').on('click', function(event){

      var $this = $(this);

      $this.closest('.gtco-accordion').find('.gtco-accordion-content').slideToggle(400, 'easeInOutExpo');
      if ($this.closest('.gtco-accordion').hasClass('active')) {
        $this.closest('.gtco-accordion').removeClass('active');
      } else {
        $this.closest('.gtco-accordion').addClass('active');
      }
      event.preventDefault();
    });
  };

  if ( $('.iso-box-wrapper').length > 0 ) { 

      var $container  = $('.iso-box-wrapper'), 
        $imgs     = $('.iso-box img');

      $container.imagesLoaded(function () {

        $container.isotope({
        layoutMode: 'fitRows',
        itemSelector: '.iso-box'
        });

        $imgs.load(function(){
          $container.isotope('reLayout');
        })

      });

      //filter items on button click

      $('.filter-wrapper li a').click(function(){

          var $this = $(this), filterValue = $this.attr('data-filter');

      $container.isotope({ 
        filter: filterValue,
        animationOptions: { 
            duration: 750, 
            easing: 'linear', 
            queue: false, 
        }                
      });             

      // don't proceed if already selected 

      if ( $this.hasClass('selected') ) { 
        return false; 
      }

      var filter_wrapper = $this.closest('.filter-wrapper');
      filter_wrapper.find('.selected').removeClass('selected');
      $this.addClass('selected');

        return false;
      }); 

  }

  // Languange
  $('.flaglang').click(function(){
    $('.preloader').show();
    var langweb    = $(this).attr("langweb");
    var postAct    = 'sesslang';

    // Ajax
    $.ajax({
          type : "POST",
          url : "ajx/kill_act.php",
          data : "postAct="+postAct+"&langweb="+langweb,
          success: function(rslt){
            // window.location.href = '';
            location.reload();
          }
        })
  });

  // Send Mail (Contact Form)
    $('.sendmailmessage').click(function(){
        var postAct         = 'sendmailmessage';
        var contactName     = $('.contactName').val();
        var contactMail     = $('.contactMail').val();
        var contactPhone    = $('.contactPhone').val();
        var contactSubject  = $('.contactSubject').val();
        var contactMess     = $('.contactMess').val();
        
        var valStatus     = false;
    
        var cekMailInp    = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
    
        if(contactName == ''){$('.alertContactName').show();valStatus = false;}
        else{$('.alertContactName').hide();valStatus = true;}
    
        if(contactMail == ''){$('.alertContactMail').show();valStatus = false;}
        else if(!cekMailInp.test(contactMail)){$('.alertContactMail').show();valStatus = false;}
        else{$('.alertContactMail').hide();valStatus = true;}
    
        if(contactPhone == ''){$('.alertContactPhone').show();valStatus = false;}
        else if(isNaN(contactPhone)){$('.alertContactPhone').show();valStatus = false;}
        else{$('.alertContactPhone').hide();valStatus = true;}
    
        if(contactSubject == ''){$('.alertContactSubj').show();valStatus = false;}
        else{$('.alertContactSubj').hide();valStatus = true;}
    
        if(contactMess == ''){$('.alertContactMess').show();valStatus = false;}
        else{$('.alertContactMess').hide();valStatus = true;}
    
        if(valStatus == true){
            $('.preloader').show();
            var form_data = new FormData();
            form_data.append('postAct', postAct);
            form_data.append('contactName', contactName);
            form_data.append('contactMail', contactMail);
            form_data.append('contactPhone', contactPhone);
            form_data.append('contactSubject', contactSubject);
            form_data.append('contactMess', contactMess);
    
            $.ajax({
                url : "ajx/kill_act.php",
                dataType: 'text',  // what to expect back from the PHP script, if anything
                cache: false,
                contentType: false,
                processData: false,
                data: form_data,                         
                type: 'post',
                success: function(rslt){
                  window.location.href = '';
                }
            })
        }
    
    });

  // Send Proposal  
  $('.sendproposal').click(function(){
    var postAct       = 'sendproposal';
    var proposName    = $('.proposName').val();
    var proposMail    = $('.proposMail').val();
    var proposPhone   = $('.proposPhone').val();
    var proposSubject = $('.proposSubject').val();
    var proposMess    = $('.proposMess').val();
    var proposFile    = $('.proposFile').val();

    var valStatus     = false;

    var cekMailInp    = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
    var fileExtension = ['pdf'];

    if(proposName == ''){$('.alertPropName').show();valStatus = false;}
    else{$('.alertPropName').hide();valStatus = true;}

    if(proposMail == ''){$('.alertPropMail').show();valStatus = false;}
    else if(!cekMailInp.test(proposMail)){$('.alertPropMail').show();valStatus = false;}
    else{$('.alertPropMail').hide();valStatus = true;}

    if(proposPhone == ''){$('.alertPropPhone').show();valStatus = false;}
    else if(isNaN(proposPhone)){$('.alertPropPhone').show();valStatus = false;}
    else{$('.alertPropPhone').hide();valStatus = true;}

    if(proposSubject == ''){$('.alertPropSubj').show();valStatus = false;}
    else{$('.alertPropSubj').hide();valStatus = true;}

    if(proposMess == ''){$('.alertPropMess').show();valStatus = false;}
    else{$('.alertPropMess').hide();valStatus = true;}

    if(proposFile == ''){$('.alertPropFile').show();valStatus = false;}
    else if ($.inArray(proposFile.split('.').pop().toLowerCase(), fileExtension) == -1){$('.alertPropFile').show();valStatus = false;}
    else if($('#sortpicture').prop('files')[0].size > 20000){$('.alertPropFile').show();valStatus = false;}
    else{$('.alertPropFile').hide();valStatus = true;}

    if(valStatus == true){
        $('.preloader').show();
        var file_data = $('#sortpicture').prop('files')[0];  
      var form_data = new FormData();                  
      form_data.append('file', file_data);
      form_data.append('postAct', postAct);
      form_data.append('proposName', proposName);
      form_data.append('proposMail', proposMail);
      form_data.append('proposPhone', proposPhone);
      form_data.append('proposSubject', proposSubject);
      form_data.append('proposMess', proposMess);

      $.ajax({
        url : "ajx/kill_act.php",
        dataType: 'text',  // what to expect back from the PHP script, if anything
        cache: false,
        contentType: false,
        processData: false,
        data: form_data,                         
        type: 'post',
        success: function(rslt){
          window.location.href = '';
        }
      })
    }
    
  });
  
  // Reset Form
  $('.resetPropos').click(function(){
       $('.proposName').val('');
       $('.proposMail').val('');
       $('.proposPhone').val('');
       $('.proposSubject').val('');
       $('.proposMess').val('');
       $('.proposFile').val('');
  });


});


// PRELOADER JS
$(window).load(function(){
    $('.preloader').fadeOut(2000); // set duration in brackets 
    $('.mailnotify').fadeOut(7000);  // Mail sent successfully
});


// jQuery to collapse the navbar on scroll //
$(window).scroll(function() {
    if ($(".navbar").offset().top > 50) {
        $(".navbar-fixed-top").addClass("top-nav-collapse");
    } else {
        $(".navbar-fixed-top").removeClass("top-nav-collapse");
    }
});


/* HTML document is loaded. DOM is ready. 
-------------------------------------------*/
$(function(){

  // ------- WOW ANIMATED ------ //
  wow = new WOW(
  {
    mobile: false
  });
  wow.init();


  // HIDE MOBILE MENU AFTER CLIKING ON A LINK
  $('.navbar-collapse a').click(function(){
        $(".navbar-collapse").collapse('hide');
    });
});

