 /**
   * The Custome Script.
   *
   *
   * @package   cuisine WordPress Theme
   * @copyright Copyright (C) 2015, OrdaSoft
   * @license  http://www.gnu.org/licenses/gpl-2.0.html  GNU General Public License v2 or later
   * @author    AUTHOR <www.ordasoft.com>
   * cuisine is distributed under the terms of the GNU GPL
   */
//menu
jQuery(document).ready(function (){
jQuery('#newsletterwidget-2 .tnp-widget form .tnp-field-email .tnp-email').attr('placeholder',' your_email_here@gmail.com');


// fixed block

  jQuery(' .fixed-block').hcSticky({

    offResolutions: [-769]

  });


// galery
  jQuery(".diamondswrap").diamonds({
    size: 268, // Size of the squares
    autoRedraw : true,
    gap: 5 // Pixels between squares
  });


// accordion


jQuery(".accordion .accordion-body").addClass('accord-body--close');

jQuery(".accordion .accord-header").click(function() {

    if(jQuery(this).parent().hasClass('accord-body--close')){

        jQuery(".accordion .accordion-body").addClass('accord-body--close');
        jQuery(this).parent().removeClass('accord-body--close');
    }

    else{
        jQuery(this).parent().addClass('accord-body--close');
    }

});


//slider
    var swiper = new Swiper('.swiper-container', {
        slidesPerView: 1,
        spaceBetween: 30,
        grabCursor: true,
        loop: true
    });

});

//tab
   jQuery('#myTab a').click(function (e) {
    e.preventDefault();
    jQuery(this).tab('show');
  })
  jQuery('#myTab a[href="#test"]').tab('show'); // Select tab by name
  jQuery('#myTab a:first').tab('show'); // Select first tab
  jQuery('#myTab a:last').tab('show'); // Select last tab
  jQuery('#myTab li:eq(0) a').tab('show'); // Select third tab (0-indexed)


//about us
( function( jQuery ) {
  var timelineBlocks = jQuery('.cd-timeline-block'),
    offset = 0.8;

  //hide timeline blocks which are outside the viewport
  hideBlocks(timelineBlocks, offset);

  //on scolling, show/animate timeline blocks when enter the viewport
  jQuery(window).on('scroll', function(){
    (!window.requestAnimationFrame)
      ? setTimeout(function(){ showBlocks(timelineBlocks, offset); }, 100)
      : window.requestAnimationFrame(function(){ showBlocks(timelineBlocks, offset); });
  });

  function hideBlocks(blocks, offset) {
    blocks.each(function(){
      ( jQuery(this).offset().top > jQuery(window).scrollTop()+jQuery(window).height()*offset ) && jQuery(this).find('.cd-timeline-img, .cd-timeline-content').addClass('is-hidden');
    });
  }

  function showBlocks(blocks, offset) {
    blocks.each(function(){
      ( jQuery(this).offset().top <= jQuery(window).scrollTop()+jQuery(window).height()*offset && jQuery(this).find('.cd-timeline-img').hasClass('is-hidden') ) && jQuery(this).find('.cd-timeline-img, .cd-timeline-content').removeClass('is-hidden').addClass('bounce-in');
    });
  }

  var theToggle = document.getElementById('toggle');

//to top
 jQuery(window).scroll(function(){
     if (jQuery(this).scrollTop() > 200) {
    jQuery('.top-up').fadeIn();
     } else {
    jQuery('.top-up').fadeOut();
  }
  });
    jQuery('.top-up').click(function(){
    jQuery("html, body").animate({ scrollTop: 0 }, 1100);
    return false;
  });




//MENU

// hasClass
function hasClass(elem, className) {
  return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' ');
}
// addClass
function addClass(elem, className) {
    if (!hasClass(elem, className)) {
      elem.className += ' ' + className;
    }
}
// removeClass
function removeClass(elem, className) {
  var newClass = ' ' + elem.className.replace( /[\t\r\n]/g, ' ') + ' ';
  if (hasClass(elem, className)) {
        while (newClass.indexOf(' ' + className + ' ') >= 0 ) {
            newClass = newClass.replace(' ' + className + ' ', ' ');
        }
        elem.className = newClass.replace(/^\s+|\s+jQuery/g, '');
    }
}
// toggleClass
function toggleClass(elem, className) {
  var newClass = ' ' + elem.className.replace( /[\t\r\n]/g, " " ) + ' ';
    if (hasClass(elem, className)) {
        while (newClass.indexOf(" " + className + " ") >= 0 ) {
            newClass = newClass.replace( " " + className + " " , " " );
        }
        elem.className = newClass.replace(/^\s+|\s+jQuery/g, '');
    } else {
        elem.className += ' ' + className;
    }
}

theToggle.onclick = function() {
   toggleClass(this, 'on');
   return false;
}

// off-canvas navigation menu
  // jQuery("#site").append('<div class="js-overlay-block"></div>');



function delayFunc(){

  var scrollHeight=document.documentElement.scrollHeight ;
  var clientHeight=document.documentElement.clientHeight;

  var headerHeight = jQuery("#header").outerHeight();
  var mainHeight = jQuery("#site>div").outerHeight();
  var footerHeight = jQuery("#footer").outerHeight();

   var siteHeight = jQuery("#site").outerHeight();

  var height=  siteHeight;



  jQuery("#navbar").addClass('js-off-canvas-meni').outerHeight(height);
  jQuery(".menu-container").addClass('js-events-none');


  jQuery("a#toggle").click(function() {

      jQuery(".js-overlay-block").toggleClass('active');
      jQuery(".menu-container").toggleClass('js-events-none');
      jQuery(".menu-container").toggleClass('js-events-auto');
      
  });


  jQuery(".js-overlay-block").click(function() {

      jQuery(this).removeClass('active');
      jQuery("a#toggle").removeClass('on');
      jQuery("body").removeClass('js-overflow-hid');

  });


  // hide/view sub menu on click
  jQuery( '.menu-item-has-children > a' ).click(function() {

       jQuery(this).parent().siblings('.menu-item-has-children').children('.sub-menu').slideUp(400);
       jQuery('.active').toggleClass('active');

       jQuery(this).parent().children('.sub-menu').slideToggle(400);
       jQuery(this).toggleClass('active');

  });

// view active sub menu item
  jQuery( '.menu-item-has-children.active > ul > li.current.active' ).parent().show() ;



};

setTimeout(delayFunc,1000);


// jQuery( '.menu-item-has-children>a' ).toggle(


//         function(){
//            jQuery(this).parent().siblings('.menu-item-has-children').children('.sub-menu').slideUp(400);
//             jQuery(this).siblings('.sub-menu').slideToggle(400);
           
//         },
//         function(){
//          jQuery(this).parent().siblings('.menu-item-has-children').children('.sub-menu').slideUp(400);
//             jQuery(this).siblings('.sub-menu').slideToggle(400);
            
//         }

// );
// jQuery( '.menu-item-has-children>a' ).toggle(


//         function(){
//            jQuery(this).parent().siblings('.menu-item-has-children').children('.sub-menu').slideUp(400);
//             jQuery(this).siblings('.sub-menu').slideToggle(400);
           
//         },
//         function(){
//          jQuery(this).parent().siblings('.menu-item-has-children').children('.sub-menu').slideUp(400);
//             jQuery(this).siblings('.sub-menu').slideToggle(400);
            
//         }
        
// );



} )( jQuery );
