function menuevent(){
  var ww = $(window).width();
  if (ww>900) {
    $('li.has-big').off();
    $('li.has-big').hover(function(){
      $(this).children('ul').show();
    },function(){
      $(this).children('ul').hide();
    });
  }
  else{
    $('li.has-big').off();
    // $(window).click(function(){
    //   $('li.has-big>ul').fadeOut();
    // });
    $('li.has-big').click(function(){
      if($(this).hasClass('active')){
        $(this).children('ul').slideUp();
        $(this).removeClass('active');
      }
      else{
        $('li.has-big').removeClass('active');
        $(this).addClass('active');
        $('li.has-big>ul').slideUp();
        $(this).children('ul').slideDown();
      }
    });
  }
}
function auto_grow(element) {
    element.style.height = "5px";
    element.style.height = (element.scrollHeight)+"px";
}
$(document).ready(function() {
  $('.text-st textarea').keyup(function(){
    auto_grow(this)
  });
  $("#events").owlCarousel({
    loop:true,
    margin:10,
    items:3,
    dots: true,
    nav:true,
    responsiveClass:true,
    responsive:{
      0:{
        items:1,
      },
      600:{
        items:2,
      },
      800:{
        items:3,
      },
      992:{
        items:2,
      }
    }
  });
  $('#in-slider').owlCarousel({
    stagePadding: 70,
    loop:true,
    margin:5,
    nav:false,
    items:1,
    lazyLoad: true,
    nav:true,
    autoplay: true,
    autoPlaySpeed: 3000,
    autoPlayTimeout: 3000,
    responsive:{
      0:{
        items:1,
        stagePadding: 10
      },
      600:{
        items:1,
        stagePadding: 30
      },
      1000:{
        items:1,
        stagePadding: 70
      },
      1200:{
        items:1,
        stagePadding: 90
      },
      1400:{
        items:1,
        stagePadding: 100
      },
      1600:{
        items:1,
        stagePadding: 120
      },
      1800:{
        items:1,
        stagePadding: 180
      }
    }
  });
  $("#main-slider").owlCarousel({
        slideSpeed: 500,
        paginationSpeed: 500,
        items:1
    });
  var w_height = $(window).height();
  $('#videobox').css('height',w_height);
  $(window).resize(function() {
    var w_height = $(window).height();
    $('#videoId').css('height',w_height);
  });
  $(window).scroll(function(){
    if ($(this).scrollTop() < 100) {
      $('nav.top-nav').removeClass('closed');
    } else {
      $('nav.top-nav').addClass('closed');
    }
  });
  $('.tubular-play').click(function(){
    $(this).fadeOut();
    $('.tubular-pause').fadeIn();
  });
  $('.tubular-pause').click(function(){
    $(this).fadeOut();
    $('.tubular-play').fadeIn();
  });

  var ns_data = {
    cursorcolor:"#BB3E3E",
    cursoropacitymin:"0.3",
    cursoropacitymax:"0.7",
    cursorwidth:"6px",
    cursorborder:"0",
    cursorborderradius:"3",
    mousescrollstep:"10",
    touchbehavior:false,
    autohidemode:false,
    background:"#ccc"
  };
  $(".jAudio--playlist").niceScroll(ns_data);
  $('.jAudio--playlist').getNiceScroll().hide();
  $(".jAudio--playlist").hover(function(){
    $('.jAudio--playlist').getNiceScroll().show();
    $('.jAudio--playlist').getNiceScroll().resize();
  }, function(){
    $('.jAudio--playlist').getNiceScroll().hide();
  });
  $('ul.hamburger').click(function(){
    $('nav.top-nav').toggleClass('open')
  });
  menuevent();
  $(window).resize(function(){
    menuevent();
  });
  // Gallery Grid
  $('#pinBoot').pinterest_grid({
    no_columns: 3,
    padding_x: 10,
    padding_y: 10,
    margin_bottom: 50,
    single_column_breakpoint: 700
  });

  // $('.books-gp').pinterest_grid({
  //   no_columns: 4,
  //   padding_x: 10,
  //   padding_y: 10,
  //   margin_bottom: 50,
  //   single_column_breakpoint: 700
  // });
  // End Gallery Grid
  $(".gal").colorbox({rel:'gal', transition:"none", maxWidth:'95%', maxHeight:'95%'});
  $(".vid").colorbox({iframe:true, innerWidth:720, innerHeight:577});
  var table = $('#table');

    // Table bordered
    $('#table-bordered').change(function() {
      var value = $( this ).val();
      table.removeClass('table-bordered').addClass(value);
    });

    // Table striped
    $('#table-striped').change(function() {
      var value = $( this ).val();
      table.removeClass('table-striped').addClass(value);
    });

    // Table hover
    $('#table-hover').change(function() {
      var value = $( this ).val();
      table.removeClass('table-hover').addClass(value);
    });

    // Table color
    $('#table-color').change(function() {
      var value = $(this).val();
      table.removeClass(/^table-mc-/).addClass(value);
    });
    $(".holder label span").click(function(){
      $('.holder').toggleClass('hover');
    })
    $(".selectbox input").change(function() {
      $('.holder label').removeClass('active');
      if(this.checked) {
        $(this).parent().addClass('active');
      }
    });
    // $('.selectbox input').click(function(){
    //   $('.holder label').removeClass('active');
    //   if ($(this).is(':checked')) {
    //     $(this).parent().addClass('active');
    //   }
    // })
    $('.datepicker').datetimepicker({
      format: 'DD/MM/YYYY'
    })
}); // End of Document ready
$(window).load(function(){
  $.stellar();
  $("footer").stellar({
    horizontalScrolling: false,
    verticalOffset: 0,
    horizontalOffset: 0
  });
});

;(function ($, window, document, undefined) {
  var pluginName = 'pinterest_grid',
  defaults = {
    padding_x: 10,
    padding_y: 10,
    no_columns: 3,
    margin_bottom: 50,
    single_column_breakpoint: 700
  },
  columns,
  $article,
  article_width;

  function Plugin(element, options) {
    this.element = element;
    this.options = $.extend({}, defaults, options) ;
    this._defaults = defaults;
    this._name = pluginName;
    this.init();
  }

  Plugin.prototype.init = function () {
    var self = this,
    resize_finish;

    $(window).resize(function() {
      clearTimeout(resize_finish);
      resize_finish = setTimeout( function () {
        self.make_layout_change(self);
      }, 11);
    });

    self.make_layout_change(self);

    setTimeout(function() {
      $(window).resize();
    }, 500);
  };

  Plugin.prototype.calculate = function (single_column_mode) {
    var self = this,
    tallest = 0,
    row = 0,
    $container = $(this.element),
    container_width = $container.width();
    $article = $(this.element).children();

    if(single_column_mode === true) {
      article_width = $container.width() - self.options.padding_x;
    } else {
      article_width = ($container.width() - self.options.padding_x * self.options.no_columns) / self.options.no_columns;
    }

    $article.each(function() {
      $(this).css('width', article_width);
    });

    columns = self.options.no_columns;

    $article.each(function(index) {
      var current_column,
      left_out = 0,
      top = 0,
      $this = $(this),
      prevAll = $this.prevAll(),
      tallest = 0;

      if(single_column_mode === false) {
        current_column = (index % columns);
      } else {
        current_column = 0;
      }

      for(var t = 0; t < columns; t++) {
        $this.removeClass('c'+t);
      }

      if(index % columns === 0) {
        row++;
      }

      $this.addClass('c' + current_column);
      $this.addClass('r' + row);

      prevAll.each(function(index) {
        if($(this).hasClass('c' + current_column)) {
          top += $(this).outerHeight() + self.options.padding_y;
        }
      });

      if(single_column_mode === true) {
        left_out = 0;
      } else {
        left_out = (index % columns) * (article_width + self.options.padding_x);
      }

      $this.css({
        'left': left_out,
        'top' : top
      });
    });

    this.tallest($container);
    $(window).resize();
  };

  Plugin.prototype.tallest = function (_container) {
    var column_heights = [],
    largest = 0;

    for(var z = 0; z < columns; z++) {
      var temp_height = 0;
      _container.find('.c'+z).each(function() {
        temp_height += $(this).outerHeight();
      });
      column_heights[z] = temp_height;
    }

    largest = Math.max.apply(Math, column_heights);
    _container.css('height', largest + (this.options.padding_y + this.options.margin_bottom));
  };

  Plugin.prototype.make_layout_change = function (_self) {
    if($(window).width() < _self.options.single_column_breakpoint) {
      _self.calculate(true);
    } else {
      _self.calculate(false);
    }
  };

  $.fn[pluginName] = function (options) {
    return this.each(function () {
      if (!$.data(this, 'plugin_' + pluginName)) {
        $.data(this, 'plugin_' + pluginName,
          new Plugin(this, options));
      }
    });
  }

})(jQuery, window, document);

(function(removeClass) {

  jQuery.fn.removeClass = function( value ) {
    if ( value && typeof value.test === "function" ) {
      for ( var i = 0, l = this.length; i < l; i++ ) {
        var elem = this[i];
        if ( elem.nodeType === 1 && elem.className ) {
          var classNames = elem.className.split( /\s+/ );

          for ( var n = classNames.length; n--; ) {
            if ( value.test(classNames[n]) ) {
              classNames.splice(n, 1);
            }
          }
          elem.className = jQuery.trim( classNames.join(" ") );
        }
      }
    } else {
      removeClass.call(this, value);
    }
    return this;
  }

})(jQuery.fn.removeClass);
