"use strict";
var lastScroll = 0;

// check for browser os
var isMobile = false;
var isiPhoneiPad = false;
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
        navigator.userAgent)) {
  isMobile = true;
}

if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
  isiPhoneiPad = true;
}

function SetMegamenuPosition() {
  if ($(window).width() > 991) {
    setTimeout(function() {
      var totalHeight = $('nav.navbar').outerHeight();
      $('.mega-menu').css({top : totalHeight});
      if ($('.navbar-brand-top').length === 0)
        $('.dropdown.simple-dropdown > .dropdown-menu').css({
          top : totalHeight
        });
    }, 200);
  } else {
    $('.mega-menu').css('top', '');
    $('.dropdown.simple-dropdown > .dropdown-menu').css('top', '');
  }
}

function pad(d) { return (d < 10) ? '0' + d.toString() : d.toString(); }

function isIE() {
  var ua = window.navigator.userAgent;
  var msie = ua.indexOf("MSIE ");
  if (msie > 0 ||
      !!navigator.userAgent.match(
          /Trident.*rv\:11\./)) // If Internet Explorer, return version number
  {
    return true;
  } else // If another browser, return 0
  {
    return false;
  }
}

// page title space
function setPageTitleSpace() {
  if ($('.navbar').hasClass('navbar-top') ||
      $('nav').hasClass('navbar-fixed-top')) {
    if ($('.top-space').length > 0) {
      var top_space_height = $('.navbar').outerHeight();
      if ($('.top-header-area').length > 0) {
        top_space_height =
            top_space_height + $('.top-header-area').outerHeight();
      }
      $('.top-space').css('margin-top', top_space_height + "px");
    }
  }
}

// swiper button position in auto height slider
function setButtonPosition() {
  if ($(window).width() > 767 &&
      $(".swiper-auto-height-container").length > 0) {
    var leftPosition = parseInt(
        $('.swiper-auto-height-container .swiper-slide').css('padding-left'));
    var bottomPosition = parseInt(
        $('.swiper-auto-height-container .swiper-slide').css('padding-bottom'));
    var bannerWidth =
        parseInt($('.swiper-auto-height-container .slide-banner').outerWidth());
    $('.navigation-area').css({
      'left' : bannerWidth + leftPosition + 'px',
      'bottom' : bottomPosition + 'px'
    });
  } else if ($(".swiper-auto-height-container").length > 0) {
    $('.navigation-area').css({'left' : '', 'bottom' : ''});
  }
}

$(window).on("scroll", init_scroll_navigate);
function init_scroll_navigate() {

  /*==============================================================
   One Page Main JS - START CODE
   =============================================================*/
  /*
      var menu_links = $(".navbar-nav li a");
      var scrollPos = $(document).scrollTop();
      scrollPos = scrollPos + 60;
      menu_links.each(function () {
          var currLink = $(this);
          var hasPos = currLink.attr("href");
          if ((hasPos !='#') && (hasPos !='')) {
              var res = currLink.attr("href");
              if ($(res).length > 0) {
                  var refElement = $(res);
                  if (refElement.offset().top <= scrollPos &&
     refElement.offset().top + refElement.height() > scrollPos) {
                      menu_links.not(currLink).removeClass("active");
                      currLink.addClass("active");
                  } else {
                      currLink.removeClass("active");
                  }
              }
          }
      });*/

  /*==============================================================*/
  // background color slider Start
  /*==============================================================*/
  var $window = $(window), $body = $('.bg-background-fade'),
      $panel = $('.color-code');
  var scroll = $window.scrollTop() + ($window.height() / 2);
  $panel.each(function() {
    var $this = $(this);
    if ($this.position().top <= scroll &&
        $this.position().top + $this.height() > scroll) {
      $body.removeClass(function(
          index,
          css) { return (css.match(/(^|\s)color-\S+/g) || []).join(' '); });
      $body.addClass('color-' + $(this).data('color'));
    }
  });

  /* ===================================
   sticky nav Start
   ====================================== */
  var headerHeight = $('nav').outerHeight();
  if (!$('header').hasClass('no-sticky')) {
    if ($(document).scrollTop() >= headerHeight) {
      $('header').addClass('sticky');

    } else if ($(document).scrollTop() <= headerHeight) {
      $('header').removeClass('sticky');
      setTimeout(function() { setPageTitleSpace(); }, 500);
    }
    SetMegamenuPosition();
  }

  /* ===================================
   header appear on scroll up
   ====================================== */
  var st = $(this).scrollTop();
  if (st > lastScroll) {
    $('.sticky').removeClass('header-appear');
    //  $('.dropdown.on').removeClass('on').removeClass('open').find('.dropdown-menu').fadeOut(100);
  } else
    $('.sticky').addClass('header-appear');
  lastScroll = st;
  if (lastScroll <= headerHeight)
    $('header').removeClass('header-appear');
}

/*==============================================================
 parallax text - START CODE
 ==============================================================*/
function parallax_text() {
  var window_width = $(window).width();
  if (window_width > 1024) {
    if ($('.swiper-auto-slide .swiper-slide').length !== 0) {
      $(document).on("mousemove", ".swiper-auto-slide .swiper-slide",
                     function(e) {
                       var positionX = e.clientX;
                       var positionY = e.clientY;
                       positionX = Math.round(positionX / 10) - 80;
                       positionY = Math.round(positionY / 10) - 40;
                       $(this).find('.parallax-text').css({
                         'transform' : 'translate(' + positionX + 'px,' +
                                           positionY + 'px)',
                         'transition-duration' : '0s'
                       });
                     });

      $(document).on("mouseout", ".swiper-auto-slide .swiper-slide",
                     function(e) {
                       $('.parallax-text').css({
                         'transform' : 'translate(0,0)',
                         'transition-duration' : '0.5s'
                       });
                     });
    }
  }
}

/*==============================================================*/
// Search - START CODE
/*==============================================================*/
function ScrollStop() { return false; }
function ScrollStart() { return true; }
function validationSearchForm() {
  var error = true;
  $('#search-header input[type=text]').each(function(index) {
    if (index === 0) {
      if ($(this).val() === null || $(this).val() === "") {
        $("#search-header").find("input:eq(" + index + ")").css({
          "border" : "none",
          "border-bottom" : "2px solid red"
        });
        error = false;
      } else {
        $("#search-header").find("input:eq(" + index + ")").css({
          "border" : "none",
          "border-bottom" : "2px solid #000"
        });
      }
    }
  });
  return error;
}

/*==============================================================
 //Parallax - START CODE
 ==============================================================*/
function stellarParallax() {
  if ($(window).width() > 1024) {
    $.stellar();
  } else {
    $.stellar('destroy');
    $('.parallax').css('background-position', '');
  }
}

/*==============================================================
 full screen START CODE
 ==============================================================*/
function fullScreenHeight() {
  var element = $(".full-screen");
  var $minheight = $(window).height();
  element.parents('section').imagesLoaded(function() {
    if ($(".top-space .full-screen").length > 0) {
      var $headerheight = $("header nav.navbar").outerHeight();
      $(".top-space .full-screen")
          .css('min-height', $minheight - $headerheight);
    } else {
      element.css('min-height', $minheight);
    }
  });

  var minwidth = $(window).width();
  $(".full-screen-width").css('min-width', minwidth);

  var sidebarNavHeight = $('.sidebar-nav-style-1').height() -
                         $('.logo-holder').parent().height() -
                         $('.footer-holder').parent().height() - 10;
  $(".sidebar-nav-style-1 .nav").css('height', (sidebarNavHeight));
  var style2NavHeight = parseInt(
      $('.sidebar-part2').height() -
      parseInt($('.sidebar-part2 .sidebar-middle').css('padding-top')) -
      parseInt($('.sidebar-part2 .sidebar-middle').css('padding-bottom')) -
      parseInt($(".sidebar-part2 .sidebar-middle .sidebar-middle-menu .nav")
                   .css('margin-bottom')));
  $(".sidebar-part2 .sidebar-middle .sidebar-middle-menu .nav")
      .css('height', (style2NavHeight));
}

function SetResizeContent() {
  //    all function call
  SetMegamenuPosition();
  setPageTitleSpace();
  setButtonPosition();
  parallax_text();
  stellarParallax();
  fullScreenHeight();
  //    navClick();
}

/* ===================================
 START RESIZE
 ====================================== */
$(window).resize(function(event) {
  setTimeout(function() { SetResizeContent(); }, 500);
  $('.menu-back-div').each(function() { $(this).attr('style', ''); });
  $('.navbar-collapse').collapse('hide');

  event.preventDefault();
});

/* ===================================
 START READY
 ====================================== */
$(document).ready(function() {
  "use strict";

  // Active class to current menu for only html
  var pgurl =
      window.location.href.substr(window.location.href.lastIndexOf("/") + 1);
  var $hash = window.location.hash.substring(1);

  if ($hash) {
    $hash = "#" + $hash;
    pgurl = pgurl.replace($hash, "");
  } else {
    pgurl = pgurl.replace("#", "");
  }

  $(".nav li a").each(function() {
    if ($(this).attr("href") == pgurl ||
        $(this).attr("href") == pgurl + '.html') {
      $(this).parent().addClass("active");
      $(this).parents('li.dropdown').addClass("active");
    }
  });
  $(window).scroll(function() {
    if ($(this).scrollTop() > 150)
      $('.scroll-top-arrow').fadeIn('slow');
    else
      $('.scroll-top-arrow').fadeOut('slow');
  });
  // Click event to scroll to top
  $(document).on('click', '.scroll-top-arrow', function() {
    $('html, body').animate({scrollTop : 0}, 800);
    return false;
  });

  /* ===================================
   swiper slider
   ====================================== */
  var swiperFull = new Swiper('.swiper-full-screen', {
    loop : true,
    slidesPerView : 1,
    preventClicks : false,
    allowTouchMove : true,
    pagination : {el : '.swiper-full-screen-pagination', clickable : true},
    autoplay : {delay : 5000},
    keyboard : {enabled : true},
    navigation :
        {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'},
    on : {resize : function() { swiperFull.update(); }}
  });

  var swiperAutoFade = new Swiper('.swiper-auto-fade', {
    allowTouchMove : true,
    loop : true,
    slidesPerView : 1,
    preventClicks : false,
    effect : 'fade',
    autoplay : {delay : 5000},
    keyboard : {enabled : true},
    navigation :
        {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'},
    pagination : {el : '.swiper-auto-pagination', clickable : true},
    on : {resize : function() { swiperAutoFade.update(); }}
  });

  var swiperSecond = new Swiper('.swiper-slider-second', {
    allowTouchMove : true,
    slidesPerView : 1,
    preventClicks : false,
    keyboard : {enabled : true},
    navigation :
        {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'},
    pagination : {el : '.swiper-pagination-second', clickable : true},
    on : {resize : function() { swiperSecond.update(); }}
  });

  var swiperThird = new Swiper('.swiper-slider-third', {
    allowTouchMove : true,
    slidesPerView : 1,
    preventClicks : false,
    keyboard : {enabled : true},
    navigation :
        {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'},
    pagination : {el : '.swiper-pagination-third', clickable : true},
    on : {resize : function() { swiperThird.update(); }}
  });

  var swiperNumber = new Swiper('.swiper-number-pagination', {
    allowTouchMove : true,
    preventClicks : false,
    autoplay : {delay : 4000, disableOnInteraction : true},
    pagination : {
      el : '.swiper-number',
      clickable : true,
      renderBullet : function(index, className) {
        return '<span class="' + className + '">' + pad((index + 1)) +
               '</span>';
      }
    },
    on : {resize : function() { swiperNumber.update(); }}
  });

  var swiperVerticalPagination = new Swiper('.swiper-vertical-pagination', {
    allowTouchMove : true,
    direction : 'vertical',
    slidesPerView : 1,
    spaceBetween : 0,
    preventClicks : false,
    mousewheel : {mousewheel : true, sensitivity : 1, releaseOnEdges : true},
    navigation :
        {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'},
    pagination : {el : '.swiper-pagination-vertical', clickable : true},
    on : {resize : function() { swiperVerticalPagination.update(); }}
  });

  var swiperClients = new Swiper('.swiper-slider-clients', {
    allowTouchMove : true,
    slidesPerView : 4,
    paginationClickable : true,
    preventClicks : true,
    autoplay : {delay : 3000, disableOnInteraction : true},
    pagination : {el : null},
    breakpoints : {
      1199 : {slidesPerView : 3},
      991 : {slidesPerView : 2},
      767 : {slidesPerView : 1}
    },
    on : {resize : function() { swiperClients.update(); }}
  });

  var swiperClients2 = new Swiper('.swiper-slider-clients-second', {
    allowTouchMove : true,
    slidesPerView : 4,
    paginationClickable : true,
    preventClicks : true,
    autoplay : {delay : 3000, disableOnInteraction : true},
    pagination : {el : null},
    breakpoints : {
      1199 : {slidesPerView : 3},
      991 : {slidesPerView : 2},
      767 : {slidesPerView : 1}
    },
    on : {resize : function() { swiperClients2.update(); }}
  });

  var swiperThreeSlides = new Swiper('.swiper-three-slides', {
    allowTouchMove : true,
    slidesPerView : 3,
    preventClicks : true,
    pagination : {el : '.swiper-pagination-three-slides', clickable : true},
    autoplay : {delay : 3000},
    keyboard : {enabled : true},
    navigation : {
      nextEl : '.swiper-three-slide-next',
      prevEl : '.swiper-three-slide-prev'
    },
    breakpoints : {991 : {slidesPerView : 2}, 767 : {slidesPerView : 1}},
    on : {resize : function() { swiperThreeSlides.update(); }}
  });

  var swiperFourSlides = new Swiper('.swiper-four-slides', {
    allowTouchMove : true,
    slidesPerView : 4,
    preventClicks : true,
    pagination : {el : '.swiper-pagination-four-slides', clickable : true},
    autoplay : {delay : 3000},
    keyboard : {enabled : true},
    navigation :
        {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'},
    breakpoints : {
      1199 : {slidesPerView : 3},
      991 : {slidesPerView : 2},
      767 : {slidesPerView : 1}
    },
    on : {resize : function() { swiperFourSlides.update(); }}
  });

  var swiperDemoHeaderStyle = new Swiper('.swiper-demo-header-style', {
    allowTouchMove : true,
    loop : true,
    slidesPerView : 4,
    preventClicks : true,
    slidesPerGroup : 4,
    pagination :
        {el : '.swiper-pagination-demo-header-style', clickable : true},
    autoplay : {delay : 3000},
    keyboard : {enabled : true},
    navigation :
        {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'},
    breakpoints : {
      1199 : {slidesPerGroup : 2, slidesPerView : 2},
      767 : {slidesPerGroup : 1, slidesPerView : 1}
    },
    on : {resize : function() { swiperDemoHeaderStyle.update(); }}
  });

  var $swiperAutoSlideIndex = 0;
  var swiperAutoSlide = new Swiper('.swiper-auto-slide', {
    allowTouchMove : true,
    slidesPerView : 'auto',
    centeredSlides : true,
    spaceBetween : 80,
    preventClicks : false,
    observer : true,
    speed : 1000,
    pagination : {el : null},
    scrollbar : {
      el : '.swiper-scrollbar',
      draggable : true,
      hide : false,
      snapOnRelease : true
    },
    autoplay : {delay : 3000},
    mousewheel : {invert : false},
    keyboard : {enabled : true},
    navigation :
        {nextEl : '.swiper-next-style2', prevEl : '.swiper-prev-style2'},
    breakpoints : {
      1199 : {spaceBetween : 60},
      960 : {spaceBetween : 30},
      767 : {spaceBetween : 15}
    },
    on : {resize : function() { swiperAutoSlide.update(); }}
  });

  if ($(window).width() > 767) {
    var swiperBottomScrollbarFull =
        new Swiper('.swiper-bottom-scrollbar-full', {
          allowTouchMove : true,
          slidesPerView : 'auto',
          grabCursor : true,
          preventClicks : false,
          spaceBetween : 30,
          keyboardControl : true,
          speed : 1000,
          pagination : {el : null},
          scrollbar : {
            el : '.swiper-scrollbar',
            draggable : true,
            hide : false,
            snapOnRelease : true
          },
          mousewheel : {enable : true},
          keyboard : {enabled : true},
          navigation :
              {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'}
        });
  }

  var swiperAutoHieght = new Swiper('.swiper-auto-height-container', {
    allowTouchMove : true,
    effect : 'fade',
    loop : true,
    autoHeight : true,
    pagination : {el : '.swiper-auto-height-pagination', clickable : true},
    autoplay : {delay : 3000},
    navigation :
        {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'},
    on : {resize : function() { swiperAutoHieght.update(); }}
  });

  var swiperMultyRow = new Swiper('.swiper-multy-row-container', {
    allowTouchMove : true,
    slidesPerView : 4,
    spaceBetween : 15,
    pagination : {el : '.swiper-multy-row-pagination', clickable : true},
    autoplay : {delay : 3000, disableOnInteraction : true},
    navigation :
        {nextEl : '.swiper-portfolio-next', prevEl : '.swiper-portfolio-prev'},
    breakpoints : {991 : {slidesPerView : 2}, 767 : {slidesPerView : 1}},
    on : {resize : function() { swiperMultyRow.update(); }}
  });

  var swiperBlog = new Swiper('.swiper-blog', {
    allowTouchMove : true,
    slidesPerView : "auto",
    centeredSlides : true,
    spaceBetween : 15,
    preventClicks : false,
    loop : true,
    loopedSlides : 3,
    pagination : {el : '.swiper-blog-pagination', clickable : true},
    autoplay : {delay : 5000, disableOnInteraction : true},
    navigation :
        {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'},
    on : {resize : function() { swiperBlog.update(); }}
  });

  var swiperPresentation = new Swiper('.swiper-presentation', {
    allowTouchMove : true,
    slidesPerView : 4,
    centeredSlides : true,
    spaceBetween : 30,
    preventClicks : true,
    loop : true,
    loopedSlides : 6,
    pagination : {el : '.swiper-presentation-pagination', clickable : true},
    autoplay : {delay : 3000, disableOnInteraction : true},
    keyboard : {enabled : true},
    navigation :
        {nextEl : '.swiper-button-next', prevEl : '.swiper-button-prev'},
    breakpoints : {
      991 : {spaceBetween : 15, slidesPerView : 2},
      767 : {slidesPerView : 1}
    },
    on : {resize : function() { swiperPresentation.update(); }}
  });

  var resizeId;

  $(window).resize(function() {
    if ($(".swiper-auto-slide").length > 0 && swiperAutoSlide) {
      $swiperAutoSlideIndex = swiperAutoSlide.activeIndex;
      swiperAutoSlide.detachEvents();
      swiperAutoSlide.destroy(true, false);
      swiperAutoSlide = undefined;
      $(".swiper-auto-slide .swiper-wrapper")
          .css("transform", "")
          .css("transition-duration", "");
      $(".swiper-auto-slide .swiper-slide").css("margin-right", "");

      setTimeout(function() {
        swiperAutoSlide = new Swiper('.swiper-auto-slide', {
          allowTouchMove : true,
          slidesPerView : 'auto',
          centeredSlides : true,
          spaceBetween : 80,
          preventClicks : false,
          mousewheelControl : true,
          observer : true,
          speed : 1000,
          pagination : {el : null},
          scrollbar : {
            el : '.swiper-scrollbar',
            draggable : true,
            hide : false,
            snapOnRelease : true
          },
          autoplay : {delay : 3000},
          keyboard : {enabled : true},
          navigation :
              {nextEl : '.swiper-next-style2', prevEl : '.swiper-prev-style2'},
          breakpoints : {
            1199 : {spaceBetween : 60},
            960 : {spaceBetween : 30},
            767 : {spaceBetween : 15}
          },
          on : {resize : function() { swiperAutoSlide.update(); }}
        });

        swiperAutoSlide.slideTo($swiperAutoSlideIndex, 1000, false);
      }, 1000);
    }

    if ($(".swiper-bottom-scrollbar-full").length > 0) {
      clearTimeout(resizeId);
      resizeId = setTimeout(doneResizing, 1000);
    }

    /* update all swiper on window resize */

    setTimeout(function() {
      if ($('.swiper-full-screen').length > 0 && swiperFull) {
        swiperFull.update();
      }

      if ($('.swiper-auto-fade').length > 0 && swiperAutoFade) {
        swiperAutoFade.update();
      }

      if ($('.swiper-slider-second').length > 0 && swiperSecond) {
        swiperSecond.update();
      }

      if ($('.swiper-slider-third').length > 0 && swiperThird) {
        swiperThird.update();
      }

      if ($('.swiper-number-pagination').length > 0 && swiperNumber) {
        swiperNumber.update();
      }

      if ($('.swiper-vertical-pagination').length > 0 &&
          swiperVerticalPagination) {
        swiperVerticalPagination.update();
      }

      if ($('.swiper-slider-clients').length > 0 && swiperClients) {
        swiperClients.update();
      }

      if ($('.swiper-slider-clients-second').length > 0 && swiperClients2) {
        swiperClients2.update();
      }

      if ($('.swiper-three-slides').length > 0 && swiperThreeSlides) {
        swiperThreeSlides.update();
      }

      if ($('.swiper-four-slides').length > 0 && swiperFourSlides) {
        swiperFourSlides.update();
      }

      if ($('.swiper-demo-header-style').length > 0 && swiperDemoHeaderStyle) {
        swiperDemoHeaderStyle.update();
      }

      if ($('.swiper-auto-slide').length > 0 && swiperAutoSlide) {
        swiperAutoSlide.update();
      }

      if ($('.swiper-auto-height-container').length > 0 && swiperAutoHieght) {
        swiperAutoHieght.update();
      }

      if ($('.swiper-multy-row-container').length > 0 && swiperMultyRow) {
        swiperMultyRow.update();
      }

      if ($('.swiper-blog').length > 0 && swiperBlog) {
        swiperBlog.update();
      }

      if ($('.swiper-presentation').length > 0 && swiperPresentation) {
        swiperPresentation.update();
      }
    }, 500);
    if (isIE()) {
      setTimeout(function() {
        if ($('.swiper-full-screen').length > 0 && swiperFull) {
          swiperFull.update();
        }

        if ($('.swiper-auto-fade').length > 0 && swiperAutoFade) {
          swiperAutoFade.update();
        }

        if ($('.swiper-slider-second').length > 0 && swiperSecond) {
          swiperSecond.update();
        }

        if ($('.swiper-slider-third').length > 0 && swiperThird) {
          swiperThird.update();
        }

        if ($('.swiper-number-pagination').length > 0 && swiperNumber) {
          swiperNumber.update();
        }

        if ($('.swiper-vertical-pagination').length > 0 &&
            swiperVerticalPagination) {
          swiperVerticalPagination.update();
        }

        if ($('.swiper-slider-clients').length > 0 && swiperClients) {
          swiperClients.update();
        }

        if ($('.swiper-slider-clients-second').length > 0 && swiperClients2) {
          swiperClients2.update();
        }

        if ($('.swiper-three-slides').length > 0 && swiperThreeSlides) {
          swiperThreeSlides.update();
        }

        if ($('.swiper-four-slides').length > 0 && swiperFourSlides) {
          swiperFourSlides.update();
        }

        if ($('.swiper-demo-header-style').length > 0 &&
            swiperDemoHeaderStyle) {
          swiperDemoHeaderStyle.update();
        }

        if ($('.swiper-auto-slide').length > 0 && swiperAutoSlide) {
          swiperAutoSlide.update();
        }

        if ($('.swiper-auto-height-container').length > 0 && swiperAutoHieght) {
          swiperAutoHieght.update();
        }

        if ($('.swiper-multy-row-container').length > 0 && swiperMultyRow) {
          swiperMultyRow.update();
        }

        if ($('.swiper-blog').length > 0 && swiperBlog) {
          swiperBlog.update();
        }

        if ($('.swiper-presentation').length > 0 && swiperPresentation) {
          swiperPresentation.update();
        }
      }, 500);
    }
  });

  function doneResizing() {
    if (swiperBottomScrollbarFull) {
      swiperBottomScrollbarFull.detachEvents();
      swiperBottomScrollbarFull.destroy(true, true);
      swiperBottomScrollbarFull = undefined;
    }

    $(".swiper-bottom-scrollbar-full .swiper-wrapper")
        .css("transform", "")
        .css("transition-duration", "");
    $(".swiper-bottom-scrollbar-full .swiper-slide").css("margin-right", "");
    $('.swiper-bottom-scrollbar-full .swiper-wrapper').removeAttr('style');
    $('.swiper-bottom-scrollbar-full .swiper-slide').removeAttr('style');

    if ($(window).width() > 767) {
      setTimeout(function() {
        swiperBottomScrollbarFull =
            new Swiper('.swiper-bottom-scrollbar-full', {
              allowTouchMove : true,
              slidesPerView : 'auto',
              grabCursor : true,
              preventClicks : false,
              spaceBetween : 30,
              keyboardControl : true,
              speed : 1000,
              pagination : {el : null},
              scrollbar : {
                el : '.swiper-scrollbar',
                draggable : true,
                hide : false,
                snapOnRelease : true
              },
              mousewheel : {enable : true},
              keyboard : {enabled : true},
              navigation : {
                nextEl : '.swiper-button-next',
                prevEl : '.swiper-button-prev'
              }
            });
      }, 500);
    }
  }

  /*==============================================================
   smooth scroll
   ==============================================================*/

  var scrollAnimationTime = 1200, scrollAnimation = 'easeInOutExpo';
  $(document).on('click.smoothscroll', 'a.scrollto', function(event) {
    event.preventDefault();
    var target = this.hash;
    if ($(target).length != 0) {
      $('html, body')
          .stop()
          .animate({'scrollTop' : $(target).offset().top}, scrollAnimationTime,
                   scrollAnimation,
                   function() { window.location.hash = target; });
    }
  });

  /*==============================================================
   humburger menu one page navigation
   ==============================================================*/

  if ($('.full-width-pull-menu').length > 0) {
    $(document).on('click', '.full-width-pull-menu .inner-link', function(e) {
      //$('body').removeClass('overflow-hidden position-fixed');
      $(".full-width-pull-menu .close-button-menu").trigger("click");
      var _this = $(this);
      setTimeout(function() {
        var target = _this.attr("href");
        if ($(target).length > 0) {
          $('html, body').stop().animate({
            'scrollTop' : $(target).offset().top
          });
        }
      }, 500);
    });
  }

  // Inner links
  if ($('.navbar-top').length > 0 || $('.navbar-scroll-top').length > 0 ||
      $('.navbar-top-scroll').length > 0) {
    $('.inner-link').smoothScroll({speed : 900, offset : 0});
  } else {
    $('.inner-link').smoothScroll({speed : 900, offset : -59});
  }

  $('.section-link').smoothScroll({speed : 900, offset : 1});

  /*==============================================================*/
  // PieChart For Onepage - START CODE
  /*==============================================================*/
  if ($('.chart1').length > 0) {
    $('.chart1').appear();
    $('.chart1').easyPieChart({
      barColor : '#929292',
      trackColor : '#d9d9d9',
      scaleColor : false,
      easing : 'easeOutBounce',
      scaleLength : 1,
      lineCap : 'round',
      lineWidth : 3, // 12
      size : 150,    // 110
      animate : {duration : 2000, enabled : true},
      onStep : function(
          from, to,
          percent) { $(this.el).find('.percent').text(Math.round(percent)); }
    });
    $(document.body).on('appear', '.chart1', function(e) {
      // this code is executed for each appeared element
      if (!$(this).hasClass('appear')) {
        $(this).addClass('appear');
        $(this).data('easyPieChart').update(0).update($(this).data('percent'));
      }
    });
  }

  if ($('.chart2').length > 0) {
    $('.chart2').appear();
    $('.chart2').easyPieChart({
      easing : 'easeOutCirc',
      barColor : '#ff214f',
      trackColor : '#c7c7c7',
      scaleColor : false,
      scaleLength : 1,
      lineCap : 'round',
      lineWidth : 2, // 12
      size : 120,    // 110
      animate : {duration : 2000, enabled : true},
      onStep : function(
          from, to,
          percent) { $(this.el).find('.percent').text(Math.round(percent)); }
    });
    $(document.body).on('appear', '.chart2', function(e) {
      // this code is executed for each appeared element
      if (!$(this).hasClass('appear')) {
        $(this).addClass('appear');
        $(this).data('easyPieChart').update(0).update($(this).data('percent'));
      }
    });
  }

  if ($('.chart3').length > 0) {
    $('.chart3').appear();
    $('.chart3').easyPieChart({
      easing : 'easeOutCirc',
      barColor : '#ff214f',
      trackColor : '',
      scaleColor : false,
      scaleLength : 1,
      lineCap : 'round',
      lineWidth : 3, // 12
      size : 140,    // 110
      animate : {duration : 2000, enabled : true},
      onStep : function(
          from, to,
          percent) { $(this.el).find('.percent').text(Math.round(percent)); }
    });
    $(document.body).on('appear', '.chart3', function(e) {
      // this code is executed for each appeared element
      if (!$(this).hasClass('appear')) {
        $(this).addClass('appear');
        $(this).data('easyPieChart').update(0).update($(this).data('percent'));
      }
    });
  }

  /*==============================================================
   portfolio filter
   ==============================================================*/
  var $portfolio_filter = $('.portfolio-grid');
  $portfolio_filter.imagesLoaded(function() {
    $portfolio_filter.isotope({
      layoutMode : 'masonry',
      itemSelector : '.grid-item',
      percentPosition : true,
      masonry : {columnWidth : '.grid-sizer'}
    });
    $portfolio_filter.isotope();
  });
  var $grid_selectors = $('.portfolio-filter > li > a');
  $grid_selectors.on('click', function() {
    $grid_selectors.parent().removeClass('active');
    $(this).parent().addClass('active');
    var selector = $(this).attr('data-filter');
    $portfolio_filter.find('.grid-item')
        .removeClass('animated')
        .css("visibility", ""); // avoid problem to filter after sorting
    $portfolio_filter.find('.grid-item').each(function() {
      /* remove perticular element from WOW array when you don't want animation
       * on element after DOM lead */
      wow.removeBox(this);
      $(this).css("-webkit-animation", "none");
      $(this).css("-moz-animation", "none");
      $(this).css("-ms-animation", "none");
      $(this).css("animation", "none");
    });
    $portfolio_filter.isotope({filter : selector});
    return false;
  });
  $(window).resize(function() {
    if (!isMobile && !isiPhoneiPad) {
      $portfolio_filter.imagesLoaded(function() {
        setTimeout(function() {
          $portfolio_filter.find('.grid-item')
              .removeClass('wow')
              .removeClass(
                  'animated'); // avoid problem to filter after window resize
          $portfolio_filter.isotope('layout');
        }, 300);
      });
    }
  });
  var $blog_filter = $('.blog-grid');
  $blog_filter.imagesLoaded(function() {
    $blog_filter.isotope({
      layoutMode : 'masonry',
      itemSelector : '.grid-item',
      percentPosition : true,
      masonry : {columnWidth : '.grid-sizer'}
    });
  });
  $(window).resize(function() {
    setTimeout(function() {
      $blog_filter.find('.grid-item')
          .removeClass('wow')
          .removeClass(
              'animated'); // avoid problem to filter after window resize
      $blog_filter.isotope('layout');
    }, 300);
  });

  /*==============================================================
   lightbox gallery
   ==============================================================*/
  $('.lightbox-gallery').magnificPopup({
    delegate : 'a',
    type : 'image',
    tLoading : 'Loading image #%curr%...',
    mainClass : 'mfp-fade',
    fixedContentPos : true,
    closeBtnInside : false,
    gallery : {
      enabled : true,
      navigateByImgClick : true,
      preload : [
        0, 1
      ] // Will preload 0 - before current, and 1 after the current image
    }
  });
  /* for group gallery */
  var lightboxgallerygroups = {};
  $('.lightbox-group-gallery-item').each(function() {
    var id = $(this).attr('data-group');
    if (!lightboxgallerygroups[id]) {
      lightboxgallerygroups[id] = [];
    }
    lightboxgallerygroups[id].push(this);
  });
  $.each(lightboxgallerygroups, function() {
    $(this).magnificPopup({
      type : 'image',
      closeOnContentClick : true,
      closeBtnInside : false,
      gallery : {enabled : true}
    });
  });

  $('.lightbox-portfolio').magnificPopup({
    delegate : '.gallery-link',
    type : 'image',
    tLoading : 'Loading image #%curr%...',
    mainClass : 'mfp-fade',
    fixedContentPos : true,
    closeBtnInside : false,
    gallery : {
      enabled : true,
      navigateByImgClick : false,
      preload : [
        0, 1
      ] // Will preload 0 - before current, and 1 after the current image
    }
  });
  /*==============================================================
   single image lightbox - zoom animation
   ==============================================================*/
  $('.single-image-lightbox').magnificPopup({
    type : 'image',
    closeOnContentClick : true,
    fixedContentPos : true,
    closeBtnInside : false,
    mainClass :
        'mfp-no-margins mfp-with-zoom', // class to remove default margin from
                                        // left and right side
    image : {verticalFit : true},
    zoom : {
      enabled : true,
      duration : 300 // don't foget to change the duration also in CSS
    }
  });
  /*==============================================================
   zoom gallery
   ==============================================================*/
  $('.zoom-gallery').magnificPopup({
    delegate : 'a',
    type : 'image',
    mainClass : 'mfp-with-zoom mfp-img-mobile',
    fixedContentPos : true,
    closeBtnInside : false,
    image : {
      verticalFit : true,
      titleSrc : function(item) { return item.el.attr('title'); }
    },
    gallery : {enabled : true},
    zoom : {
      enabled : true,
      duration : 300, // don't foget to change the duration also in CSS
      opener : function(element) { return element.find('img'); }
    }
  });
  /*==============================================================*/
  // Modal popup - START CODE
  /*==============================================================*/
  $('.modal-popup').magnificPopup({
    type : 'inline',
    preloader : false,
    // modal: true,
    blackbg : true,
    callbacks : {open : function() { $('html').css('margin-right', 0); }}
  });
  $(document).on('click', '.popup-modal-dismiss', function(e) {
    e.preventDefault();
    $.magnificPopup.close();
  });

  /*==============================================================*/
  // Modal popup - zoom animation - START CODE
  /*==============================================================*/
  $('.popup-with-zoom-anim').magnificPopup({
    type : 'inline',
    fixedContentPos : false,
    fixedBgPos : true,
    overflowY : 'auto',
    closeBtnInside : true,
    preloader : false,
    midClick : true,
    removalDelay : 300,
    blackbg : true,
    mainClass : 'my-mfp-zoom-in'
  });

  $('.popup-with-move-anim').magnificPopup({
    type : 'inline',
    fixedContentPos : false,
    fixedBgPos : true,
    overflowY : 'auto',
    closeBtnInside : true,
    preloader : false,
    midClick : true,
    removalDelay : 300,
    blackbg : true,
    mainClass : 'my-mfp-slide-bottom'
  });

  /*==============================================================
   popup with form
   ==============================================================*/
  $('.popup-with-form').magnificPopup({
    type : 'inline',
    preloader : false,
    closeBtnInside : false,
    fixedContentPos : true,
    focus : '#name',
    callbacks : {
      beforeOpen : function() {
        if ($(window).width() < 700) {
          this.st.focus = false;
        } else {
          this.st.focus = '#name';
        }
      }
    }
  });
  /*==============================================================
   video magnific popup
   ==============================================================*/

  $('.popup-youtube, .popup-vimeo, .popup-googlemap').magnificPopup({
    disableOn : 700,
    type : 'iframe',
    mainClass : 'mfp-fade',
    removalDelay : 160,
    preloader : false,
    fixedContentPos : "auto",
    closeBtnInside : false
  });
  /*==============================================================
   ajax magnific popup for onepage portfolio
   ==============================================================*/
  $('.ajax-popup').magnificPopup({
    type : 'ajax',
    alignTop : true,
    fixedContentPos : true,
    overflowY : 'scroll', // as we know that popup content is tall we set scroll
                          // overflow by default to avoid jump
    callbacks : {
      open : function() {
        $('.navbar .collapse').removeClass('show');
        $('.navbar a.dropdown-toggle').addClass('collapsed');
      }
    }
  });

  /*==============================================================
   mega menu width
   ===============================================================*/
  $("ul.mega-menu-full").each(function(idx, elm) {
    var megaMenuWidth = 0;
    $(this).children('li').each(function(idx, elm) {
      var LIheight = 0;
      megaMenuWidth += $(this).outerWidth();
    });
    $(this).width(megaMenuWidth + 95);
    megaMenuWidth = 0;
  });
  /*==============================================================
   fit videos
   ==============================================================*/
  $(".fit-videos").fitVids();

  /*==============================================================
   form to email
   ==============================================================*/
  $("#success-subscribe-newsletter").hide();
  $("#success-subscribe-newsletter2").hide();
  $("#success-contact-form").hide();
  $("#success-project-contact-form").hide();
  $("#success-contact-form-2").hide();
  $("#success-contact-form-3").hide();
  $("#success-project-contact-form-4").hide();

  // Subscribe newsletter form
  $(document).on("click", '#button-subscribe-newsletter', function() {
    var error = ValidationsubscribenewsletterForm();
    if (error) {
      $.ajax({
        type : "POST",
        url : "email-templates/subscribe-newsletter.php",
        data : $("#subscribenewsletterform").serialize(),
        success : function(result) {
          // Un-comment below code to redirect user to thank you page.
          // window.location.href="thank-you.html";

          $('input[type=text],textarea').each(function() { $(this).val(''); });
          $("#success-subscribe-newsletter").html(result);
          $("#success-subscribe-newsletter").fadeIn("slow");
          $('#success-subscribe-newsletter').delay(4000).fadeOut("slow");
        }
      });
    }
  });

  function ValidationsubscribenewsletterForm() {
    var error = true;
    $('#subscribenewsletterform input[type=text]').each(function(index) {
      if (index == 0) {
        if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) {
          $("#subscribenewsletterform")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#subscribenewsletterform")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      }
    });
    return error;
  }

  $(document).on("click", '#button-subscribe-newsletter2', function() {
    var error = ValidationsubscribenewsletterForm2();
    if (error) {
      $.ajax({
        type : "POST",
        url : "email-templates/subscribe-newsletter.php",
        data : $("#subscribenewsletterform2").serialize(),
        success : function(result) {
          // Un-comment below code to redirect user to thank you page.
          // window.location.href="thank-you.html";

          $('input[type=text],textarea').each(function() { $(this).val(''); });
          $("#success-subscribe-newsletter2").html(result);
          $("#success-subscribe-newsletter2").fadeIn("slow");
          $('#success-subscribe-newsletter2').delay(4000).fadeOut("slow");
        }
      });
    }
  });

  function ValidationsubscribenewsletterForm2() {
    var error = true;
    $('#subscribenewsletterform2 input[type=text]').each(function(index) {
      if (index == 0) {
        if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) {
          $("#subscribenewsletterform2")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#subscribenewsletterform2")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      }
    });
    return error;
  }

  // Contact us form
  $(document).on("click", '#contact-us-button', function() {
    var error = ValidationContactForm();
    if (error) {
      $.ajax({
        type : "POST",
        url : "email-templates/contact.php",
        data : $("#contact-form").serialize(),
        success : function(result) {
          // Un-comment below code to redirect user to thank you page.
          // window.location.href="thank-you.html";

          $('input[type=text],textarea').each(function() { $(this).val(''); });
          $("#success-contact-form").html(result);
          $("#success-contact-form").fadeIn("slow");
          $('#success-contact-form').delay(4000).fadeOut("slow");
        }
      });
    }
  });
  function ValidationContactForm() {
    var error = true;
    $('#contact-form input[type=text]').each(function(index) {
      if (index == 0) {
        if ($(this).val() == null || $(this).val() == "") {
          $("#contact-form")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#contact-form")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      } else if (index == 1) {
        if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) {
          $("#contact-form")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#contact-form")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      }
    });
    return error;
  }

  // Contact us form 2
  $('#contact-us-button-2').on("click", function() {
    var error = ValidationContactForm2();
    if (error) {
      $.ajax({
        type : "POST",
        url : "email-templates/contact.php",
        data : $("#contact-form-2").serialize(),
        success : function(result) {
          // Un-comment below code to redirect user to thank you page.
          // window.location.href="thank-you.html";

          $('input[type=text],textarea').each(function() { $(this).val(''); });
          $("#success-contact-form-2").html(result);
          $("#success-contact-form-2").fadeIn("slow");
          $('#success-contact-form-2').delay(4000).fadeOut("slow");
        }
      });
    }
  });
  function ValidationContactForm2() {
    var error = true;
    $('#contact-form-2 input[type=text]').each(function(index) {
      if (index == 0) {
        if ($(this).val() == null || $(this).val() == "") {
          $("#contact-form-2")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#contact-form-2")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      } else if (index == 1) {
        if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) {
          $("#contact-form-2")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#contact-form-2")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      }
    });
    return error;
  }

  // Contact us form 3

  $(document).on("click", '#contact-us-button-3', function() {
    var error = ValidationContactForm3();
    if (error) {
      $.ajax({
        type : "POST",
        url : "email-templates/contact.php",
        data : $("#contact-form-3").serialize(),
        success : function(result) {
          // Un-comment below code to redirect user to thank you page.
          // window.location.href="thank-you.html";
          $('input[type=text],textarea').each(function() { $(this).val(''); });
          $("#success-contact-form-3").html(result);
          $("#success-contact-form-3").fadeIn("slow");
          $('#success-contact-form-3').delay(4000).fadeOut("slow");
        }
      });
    }
  });
  function ValidationContactForm3() {
    var error = true;
    $('#contact-form-3 input[type=text]').each(function(index) {
      if (index == 0) {
        if ($(this).val() == null || $(this).val() == "") {
          $("#contact-form-3")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#contact-form-3")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      } else if (index == 1) {
        if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) {
          $("#contact-form-3")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#contact-form-3")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      }
    });
    return error;
  }

  // Project Contact us form
  $(document).on("click", '#project-contact-us-button', function(e) {
    e.preventDefault();
    var error = ValidationProjectContactForm();
    if (error) {
      $.ajax({
        type : "POST",
        url : "email-templates/project-contact.php",
        data : $("#project-contact-form").serialize(),
        success : function(result) {
          // Un-comment below code to redirect user to thank you page.
          // window.location.href="thank-you.html";

          $('input[type=text],textarea').each(function() { $(this).val(''); });
          $("#success-project-contact-form").html(result);
          $("#success-project-contact-form").fadeIn("slow");
          $('#success-project-contact-form').delay(4000).fadeOut("slow");
        }
      });
    }
  });
  function ValidationProjectContactForm() {
    var error = true;
    $('#project-contact-form input[type=text]').each(function(index) {
      if (index == 0) {
        if ($(this).val() == null || $(this).val() == "") {
          $("#project-contact-form")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#project-contact-form")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      } else if (index == 2) {
        if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) {
          $("#project-contact-form")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#project-contact-form")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      }
    });
    return error;
  }

  // Project Contact us form 2
  $(document).on("click", '#project-contact-us-4-button', function() {
    var error = ValidationProjectContactForm4();
    if (error) {
      $.ajax({
        type : "POST",
        url : "email-templates/project-contact.php",
        data : $("#project-contact-form-4").serialize(),
        success : function(result) {
          // Un-comment below code to redirect user to thank you page.
          // window.location.href="thank-you.html";

          $('input[type=text],textarea').each(function() { $(this).val(''); });
          $("#success-project-contact-form-4").html(result);
          $("#success-project-contact-form-4").fadeIn("slow");
          $('#success-project-contact-form-4').delay(4000).fadeOut("slow");
        }
      });
    }
  });
  function ValidationProjectContactForm4() {
    var error = true;
    $('#project-contact-form-4 input[type=text]').each(function(index) {
      if (index == 0) {
        if ($(this).val() == null || $(this).val() == "") {
          $("#project-contact-form-4")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#project-contact-form-4")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      } else if (index == 2) {
        if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) {
          $("#project-contact-form-4")
              .find("input:eq(" + index + ")")
              .addClass("required-error");
          error = false;
        } else {
          $("#project-contact-form-4")
              .find("input:eq(" + index + ")")
              .removeClass("required-error");
        }
      }
    });
    return error;
  }

  /*==============================================================
   wow animation - on scroll
   ==============================================================*/
  var wow = new WOW({
    boxClass : 'wow',
    animateClass : 'animated',
    offset : 0,
    mobile : false,
    live : true
  });
  $(window).imagesLoaded(function() { wow.init(); });
  /*==============================================================
   counter
   ==============================================================*/
  $(function($) { animatecounters(); });
  function animatecounters() {
    $('.timer').each(count);
    function count(options) {
      var $this = $(this);
      options = $.extend({}, options || {}, $this.data('countToOptions') || {});
      $this.countTo(options);
    }
  }
  /* ===================================
   counter number reset while scrolling
   ====================================== */
  $('.timer').appear();
  $(document.body).on('appear', '.timer', function(e) {
    // this code is executed for each appeared element
    if (!$(this).hasClass('appear')) {
      animatecounters();
      $(this).addClass('appear');
    }
  });
  $('.countdown')
      .countdown($('.countdown').attr("data-enddate"))
      .on('update.countdown', function(event) {
        $(this).html(event.strftime(
            '' +
            '<div class="counter-container"><div class="counter-box first"><div class="number">%-D</div><span>Day%!d</span></div>' +
            '<div class="counter-box"><div class="number">%H</div><span>Hours</span></div>' +
            '<div class="counter-box"><div class="number">%M</div><span>Minutes</span></div>' +
            '<div class="counter-box last"><div class="number">%S</div><span>Seconds</span></div></div>'));
      });

  /* ===================================
   left nav
   ====================================== */
  $(document).on('click', '.right-menu-button',
                 function(e) { $('body').toggleClass('left-nav-on'); });

  /*==============================================================*/
  //    hamburger menu
  /*==============================================================*/
  $(document).on('click', '.btn-hamburger', function() {
    $('.hamburger-menu').toggleClass('show-menu');
    $('body').removeClass('show-menu');
  });

  /*==============================================================*/
  // sidebar nav open
  /*==============================================================*/
  $(document).on(
      'click', '#mobileToggleSidenav',
      function() { $(this).closest('nav').toggleClass('sidemenu-open'); });

  /*=================================
   //justified Gallery
   =================================*/
  $(document).imagesLoaded(function() {
    if ($(".justified-gallery").length > 0) {
      $(".justified-gallery").justifiedGallery({
        rowHeight : 400,
        maxRowHeight : false,
        captions : true,
        margins : 10,
        waitThumbnailsLoad : true
      });
    }
  });

  $('.atr-nav').on("click", function() {
    $(".atr-div").append("<a class='close-cross' href='#'>X</a>");
    $(".atr-div").animate({width : "toggle"});
  });

  $('.close-cross').on("click", function() { $(".atr-div").hide(); });

  var menuRight = document.getElementById('cbp-spmenu-s2'),
      showRightPush = document.getElementById('showRightPush'),
      body = document.body;
  if (showRightPush) {
    showRightPush.onclick = function() {
      classie.toggle(this, 'active');
      if (menuRight)
        classie.toggle(menuRight, 'cbp-spmenu-open');
    };
  }

  var test = document.getElementById('close-pushmenu');
  if (test) {
    test.onclick = function() {
      classie.toggle(this, 'active');
      if (menuRight)
        classie.toggle(menuRight, 'cbp-spmenu-open');
    };
  }

  // blog page header animation
  $(".blog-header-style1 li")
      .hover(
          function() {
            $('.blog-header-style1 li.blog-column-active')
                .removeClass('blog-column-active');
            $(this).addClass('blog-column-active');
          },
          function() {
            $(this).removeClass('blog-column-active');
            $('.blog-header-style1 li:first-child')
                .addClass('blog-column-active');
          });

  /*==============================================================*/
  // big menu open close start
  /*==============================================================*/
  $('.big-menu-open')
      .on("click", function() { $('.big-menu-right').addClass("open"); });

  $('.big-menu-close')
      .on("click", function() { $('.big-menu-right').removeClass("open"); });

  /*==============================================================*/
  // magnificPopup Start
  /*==============================================================*/
  $('.header-search-form').magnificPopup({
    mainClass : 'mfp-fade',
    closeOnBgClick : true,
    preloader : false,
    // for white backgriund
    fixedContentPos : false,
    closeBtnInside : false,
    callbacks : {
      open : function() {
        setTimeout(function() { $('.search-input').focus(); }, 500);
        $('#search-header').parent().addClass('search-popup');
        if (!isMobile) {
          $('body').addClass('overflow-hidden');
          //$('body').addClass('position-fixed');
          $('body').addClass('width-100');
          document.onmousewheel = ScrollStop;
        } else {
          $('body, html').on('touchmove', function(e) { e.preventDefault(); });
        }
      },
      close : function() {
        if (!isMobile) {
          $('body').removeClass('overflow-hidden');
          //$('body').removeClass('position-fixed');
          $('body').removeClass('width-100');
          $('#search-header input[type=text]').each(function(index) {
            if (index == 0) {
              $(this).val('');
              $("#search-header").find("input:eq(" + index + ")").css({
                "border" : "none",
                "border-bottom" : "2px solid rgba(255,255,255,0.5)"
              });
            }
          });
          document.onmousewheel = ScrollStart;
        } else {
          $('body, html').unbind('touchmove');
        }
      }
    }
  });

  $("input.search-input").on("keypress", function(event) {
    if (event.which == 13 && !isMobile) {
      $("button.search-button").trigger("click");
      event.preventDefault();
    }
  });

  $("input.search-input").on("keyup", function(event) {
    if ($(this).val() == null || $(this).val() == "") {
      $(this).css({"border" : "none", "border-bottom" : "2px solid red"});
    } else {
      $(this).css({
        "border" : "none",
        "border-bottom" : "2px solid rgba(255,255,255,0.5)"
      });
    }
  });

  $("form.search-form, form.search-form-result").submit(function(event) {
    var error = validationSearchForm();
    if (error) {
      var action = $(this).attr('action');
      action =
          action == '#' || action == '' ? 'blog-grid-3columns.html' : action;
      action = action + '?' + $(this).serialize();
      window.location = action;
    }

    event.preventDefault();
  });

  $(document).on(
      "click",
      '.navbar .navbar-collapse a.dropdown-toggle, .accordion-style1 .panel-heading a, .accordion-style2 .panel-heading a, .accordion-style3 .panel-heading a, .toggles .panel-heading a, .toggles-style2 .panel-heading a, .toggles-style3 .panel-heading a, a.carousel-control, .nav-tabs a[data-toggle="tab"], a.shopping-cart',
      function(e) { e.preventDefault(); });

  $(document).on('touchstart click', 'body', function(e) {
    if ($(window).width() < 992) {
      if (!$('.navbar-collapse').has(e.target).is('.navbar-collapse') &&
          $('.navbar-collapse').hasClass('show') &&
          !$(e.target).hasClass('navbar-toggle')) {
        $('.navbar-collapse').collapse('hide');
      }
    } else {
      if (!$('.navbar-collapse').has(e.target).is('.navbar-collapse') &&
          $('.navbar-collapse').hasClass('show')) {
        $('.navbar-collapse').find('a.dropdown-toggle').addClass('collapsed');
        $('.navbar-collapse').find('ul.dropdown-menu').removeClass('show');
        $('.navbar-collapse a.dropdown-toggle').removeClass('active');
      }
    }
  });

  $('.navbar-collapse a.dropdown-toggle').on('touchstart', function(e) {
    $('.navbar-collapse a.dropdown-toggle').not(this).removeClass('active');
    if ($(this).hasClass('active'))
      $(this).removeClass('active');
    else
      $(this).addClass('active');
  });

  $('button.navbar-toggle').on("click", function(e) {
    if (isMobile) {
      $(".cart-content").css('opacity', '0');
      $(".cart-content").css('visibility', 'hidden');
    }
  });

  $('a.dropdown-toggle').on("click", function(e) {
    if (isMobile) {
      $(".cart-content").css('opacity', '0');
      $(".cart-content").css('visibility', 'hidden');
    }
  });

  $(document).on('touchstart click',
                 '.navbar-collapse [data-toggle="dropdown"]', function(event) {
                   var $innerLinkLI = $(this)
                                          .parents('ul.navbar-nav')
                                          .find('li.dropdown a.inner-link')
                                          .parent('li.dropdown');
                   if (!$(this).hasClass('inner-link') &&
                       !$(this).hasClass('dropdown-toggle') &&
                       $innerLinkLI.hasClass('show')) {
                     $innerLinkLI.removeClass('show');
                   }
                   var target = $(this).attr('target');
                   if ($(window).width() <= 991 && $(this).attr('href') &&
                       $(this).attr('href').indexOf("#") <= -1 &&
                       !$(event.target).is('i')) {
                     if (event.ctrlKey || event.metaKey) {
                       window.open($(this).attr('href'), "_blank");
                       return false;
                     } else if (!target)
                       window.location = $(this).attr('href');
                     else
                       window.open($(this).attr('href'), target);

                   } else if ($(window).width() > 991 &&
                              $(this).attr('href').indexOf("#") <= -1) {
                     if (event.ctrlKey || event.metaKey) {
                       window.open($(this).attr('href'), "_blank");
                       return false;
                     } else if (!target)
                       window.location = $(this).attr('href');
                     else
                       window.open($(this).attr('href'), target);

                   } else if ($(window).width() <= 991 &&
                              $(this).attr('href') &&
                              $(this).attr('href').length > 1 &&
                              $(this).attr('href').indexOf("#") >= 0 &&
                              $(this).hasClass('inner-link')) {
                     $(this)
                         .parents('ul.navbar-nav')
                         .find('li.dropdown')
                         .not($(this).parent('.dropdown'))
                         .removeClass('show');
                     if ($(this).parent('.dropdown').hasClass('show')) {
                       $(this).parent('.dropdown').removeClass('show');
                     } else {
                       $(this).parent('.dropdown').addClass('show');
                     }
                     $(this).toggleClass('active');
                   }
                 });

  /* ===================================
   skillbar
   ====================================== */
  $('.skillbar').appear();
  $('.skillbar')
      .skillBars({from : 0, speed : 4000, interval : 100, decimals : 0});

  $(document.body).on('appear', '.skillbar', function(e) {
    // this code is executed for each appeared element
    if (!$(this).hasClass('appear')) {
      $(this).addClass('appear');
      $(this).find('.skillbar-bar').css("width", "0%");
      $(this).skillBars({from : 0, speed : 4000, interval : 100, decimals : 0});
    }
  });

  /*==============================================================*/
  // Set Resize Header Menu - START CODE
  /*==============================================================*/
  $('nav.full-width-pull-menu ul.panel-group li.dropdown a.dropdown-toggle')
      .on("click", function(e) {
        if ($(this).parent('li').find('ul.dropdown-menu').length > 0) {
          if ($(this).parent('li').hasClass('show')) {
            $(this).parent('li').removeClass('show');
          } else {
            $(this).parent('li').addClass('show');
          }
        }
      });

  /*==============================================================*/
  // accordion  - START CODE
  /*==============================================================*/
  $('.accordion-style1 .collapse').on('show.bs.collapse', function() {
    var id = $(this).attr('id');
    $('a[href="#' + id + '"]')
        .closest('.panel-heading')
        .addClass('active-accordion');
    $('a[href="#' + id + '"] .panel-title span')
        .html('<i class="ti-minus"></i>');
  });

  $('.accordion-style1 .collapse').on('hide.bs.collapse', function() {
    var id = $(this).attr('id');
    $('a[href="#' + id + '"]')
        .closest('.panel-heading')
        .removeClass('active-accordion');
    $('a[href="#' + id + '"] .panel-title span')
        .html('<i class="ti-plus"></i>');
  });

  $(document).on('click', '.nav.navbar-nav a.inner-link', function(e) {
    $(this).parents('ul.navbar-nav').find('a.inner-link').removeClass('active');
    var $this = $(this);
    $(this).parents('.navbar-collapse').collapse('hide');

    setTimeout(function() { $this.addClass('active'); }, 1000);
  });

  $('.accordion-style2 .collapse').on('show.bs.collapse', function() {
    var id = $(this).attr('id');
    $('a[href="#' + id + '"]')
        .closest('.panel-heading')
        .addClass('active-accordion');
    $('a[href="#' + id + '"] .panel-title')
        .find('i')
        .addClass('fa-angle-up')
        .removeClass('fa-angle-down');
  });

  $('.accordion-style2 .collapse').on('hide.bs.collapse', function() {
    var id = $(this).attr('id');
    $('a[href="#' + id + '"]')
        .closest('.panel-heading')
        .removeClass('active-accordion');
    $('a[href="#' + id + '"] .panel-title')
        .find('i')
        .removeClass('fa-angle-up')
        .addClass('fa-angle-down');
  });

  $('.accordion-style3 .collapse').on('show.bs.collapse', function() {
    var id = $(this).attr('id');
    $('a[href="#' + id + '"]')
        .closest('.panel-heading')
        .addClass('active-accordion');
    $('a[href="#' + id + '"] .panel-title')
        .find('i')
        .addClass('fa-angle-up')
        .removeClass('fa-angle-down');
  });

  $('.accordion-style3 .collapse').on('hide.bs.collapse', function() {
    var id = $(this).attr('id');
    $('a[href="#' + id + '"]')
        .closest('.panel-heading')
        .removeClass('active-accordion');
    $('a[href="#' + id + '"] .panel-title')
        .find('i')
        .removeClass('fa-angle-up')
        .addClass('fa-angle-down');
  });

  /*==============================================================*/
  // toggles  - START CODE
  /*==============================================================*/
  $('.toggles .collapse').on('show.bs.collapse', function() {
    var id = $(this).attr('id');
    $('a[href="#' + id + '"]')
        .closest('.panel-heading')
        .addClass('active-accordion');
    $('a[href="#' + id + '"] .panel-title span')
        .html('<i class="ti-minus"></i>');
  });

  $('.toggles .collapse').on('hide.bs.collapse', function() {
    var id = $(this).attr('id');
    $('a[href="#' + id + '"]')
        .closest('.panel-heading')
        .removeClass('active-accordion');
    $('a[href="#' + id + '"] .panel-title span')
        .html('<i class="ti-plus"></i>');
  });

  $('.toggles-style2 .collapse').on('show.bs.collapse', function() {
    var id = $(this).attr('id');
    $('a[href="#' + id + '"]')
        .closest('.panel-heading')
        .addClass('active-accordion');
    $('a[href="#' + id + '"] .panel-title span')
        .html('<i class="fa fa-angle-up"></i>');
  });

  $('.toggles-style2 .collapse').on('hide.bs.collapse', function() {
    var id = $(this).attr('id');
    $('a[href="#' + id + '"]')
        .closest('.panel-heading')
        .removeClass('active-accordion');
    $('a[href="#' + id + '"] .panel-title span')
        .html('<i class="fas fa-angle-down"></i>');
  });

  /* ===================================
   blog hover box
   ====================================== */
  $(document).on(
      "mouseenter", ".blog-post-style4 .grid-item",
      function(
          e) { $(this).find("figcaption .blog-hover-text").slideDown(300); });
  $(document).on(
      "mouseleave", ".blog-post-style4 .grid-item",
      function(
          e) { $(this).find("figcaption .blog-hover-text").slideUp(300); });
  SetResizeContent();

  var $allNonRatinaImages = $("img:not([data-rjs])");
  $allNonRatinaImages.attr('data-no-retina', '');

  /*==============================================================*/
  // demo button  - START CODE
  /*==============================================================*/
  /* var $buythemediv = '<div class="buy-theme alt-font md-display-none"><a
  href="https://themeforest.net/item/pofo-creative-agency-corporate-and-portfolio-multipurpose-template/20645944?ref=themezaa"
  target="_blank"><i class="ti-shopping-cart"></i><span>Buy
  Theme</span></a></div><div class="all-demo alt-font md-display-none"><a
  href="mailto:info@themezaa.com?subject=POFO - Creative Agency, Corporate and
  Portfolio Multi-purpose Template - Quick Question"><i
  class="ti-email"></i><span>Quick Question?</span></a></div>';
  $('body').append($buythemediv); */

  $(document).on("touchstart", ".sidebar-wrapper", function() { clearOpen(); });

  var getNav = $("nav.navbar.bootsnav"),
      getIn = getNav.find("ul.nav").data("in"),
      getOut = getNav.find("ul.nav").data("out");
  function clearOpen() {
    $('li.dropdown').removeClass("on").removeClass("show");
    $(".dropdown-menu").stop().fadeOut('fast');
    $(".dropdown-menu").removeClass(getIn);
    $(".dropdown-menu").addClass(getOut);
  }
});
/* ===================================
 END READY
 ====================================== */

/* ===================================
 START Page Load
 ====================================== */
$(document).on('load', function() {
  var hash = window.location.hash.substr(1);
  if (hash != "") {
    setTimeout(function() {
      $(document).imagesLoaded(function() {
        var scrollAnimationTime = 1200, scrollAnimation = 'easeInOutExpo';
        var target = '#' + hash;
        if ($(target).length > 0) {

          $('html, body')
              .stop()
              .animate({'scrollTop' : $(target).offset().top},
                       scrollAnimationTime, scrollAnimation,
                       function() { window.location.hash = target; });
        }
      });
    }, 500);
  }

  fullScreenHeight();
});

function nascondi_tag(el) {
  var IDtag = $(el).attr('id');
  var classe = ' ';
  if ($('.portfolio-filter.nav div.nav.active')) {
    classe = $('.nav.active a.nav_filtro').attr('data-filter');
  }

  if (classe == '*') {
    classe = ' ';
  }

  if ($(el).hasClass('tag_attivo')) {
    $('.nascondi_tag').removeClass('tag_attivo');
    $(classe + '.filtri_tag').fadeIn(200);
  } else {
    $('.nascondi_tag').removeClass('tag_attivo');
    $(el).addClass('tag_attivo');
    $(classe + '.filtri_tag').fadeOut(100).filter('.' + IDtag + '').fadeIn(200);
  }
}

function scroll_to_index(id) {
  $('html,body').animate({scrollTop : $('#' + id).offset().top}, 'slow');
}

function sendmail() {
  var nome = $('input[name=name]').val();
  var email = $('input[name=email]').val();
  var tel = $('input[name=telefono]').val();
  var nota = $('textarea[name=message]').val();

  var privacy = 0;

  if ($('#privacy').is(':checked')) {
    privacy = 1;
  }
  loading(1);
  $.post(
      'config/sendmail.php',
      {nome : nome, email : email, nota : nota, privacy : privacy, tel : tel},
      function(html) {
        loading();
        var num = html.indexOf("error");
        if (num >= 0) {
          alert('Compila i campi* e Riprova');
        } else {
          alert('Inviata con Successo');
        }
      });
}

function controlla_brochure_corso() {
  var scidoo_cliente_p = leggiCookie('area_privata_pacchetti_514');
  if (scidoo_cliente_p == '') {
    if ($('.btn_brochure').length > 0) {
      $('.btn_brochure').removeAttr('download');
      $('.btn_brochure').removeAttr('target');
      var IDcorso = $('[data-servizio]').data('servizio')
      $('.btn_brochure')
          .attr('href', 'area_privata.php?brochure=1&cod=' + IDcorso);
    }
  }
}

function leggi_cookie_policy() {
  window.open('cookie-policy.php', '_blank', false);
  $('#cookie').fadeOut('slow');
}

function leggi_privacy_policy() {
  window.open('privacy-policy.php', '_blank', false);
  $('#cookie').fadeOut('slow');
}

function cookie() {
  var cookie = $('#cookie');
  if (window.pageYOffset >= 400) {
    accetta_cookie();
  }
}

window.addEventListener("scroll", cookie, false);

function accetta_cookie() {
  $('#cookie').fadeOut('slow');
  scriviCookiepolicy('cookie policy');
}

$(document).ready(function() {
  var risultato = leggiCookiepolicy('cookie policy');
  if (risultato == 1) {
    $('#cookie').css('display', 'inline-block').fadeIn('slow');
  }
});

function scriviCookiepolicy(nomeCookie) {
  var scadenza = new Date();
  var adesso = new Date();
  scadenza.setTime(adesso.getTime() + (2592000000));
  document.cookie =
      nomeCookie + '= informativa; expires=' + scadenza.toGMTString();
}

function leggiCookiepolicy(nomeCookie) {
  if (document.cookie.length > 0) {
    var inizio = document.cookie.indexOf(nomeCookie + "=");
    if (inizio != -1) {
      inizio = inizio + nomeCookie.length + 1;
      var fine = document.cookie.indexOf(";", inizio);
      if (fine == -1)
        fine = document.cookie.length;
      return unescape(document.cookie.substring(inizio, fine));
    } else {
      return 1;
    }
  }
  return 1;
}

function goToForm(idCorso) {
  var params = new URLSearchParams({
    idCorso: idCorso,
}).toString();

window.location.href = "contatti.php?" + params + "#start-your-project";

}