require('./bootstrap');
require('./jquery.touchSwipe');
require('tooltipster');
require('./jquery.jscroll');
// require('./jquery.cookiebar');
window.toastr = require('toastr');

require('./components/article.js')
require('./components/img-zoom.js')
const lightSlider = require('lightslider')


$(".content-slider").lightSlider({
  item: 4,
  responsive: [
    {
        breakpoint:800,
        settings: {
            item:3,
            slideMove:1,
            slideMargin:6,
          }
    },
    {
        breakpoint:575,
        settings: {
            item:2,
            slideMove:1
          }
    },
    {
        breakpoint:480,
        settings: {
            item:1,
            slideMove:1
          }
    }
  ]
})

/*
	SLIDE DOWN BUTTON FUNCTION
*/
+ function($) {
    'use strict';
    $("#slideDown").click(function() {
        $('html, body').animate({
            scrollTop: $("#mainContent").offset().top - 100
        }, 1000);
    });
}(jQuery);

/*
	MAKE THE CONTENT BOX SAME HEIGHT AS THE SIBLINGS
*/
+function($){
	'use strict';
	var $wdwWidth = $(window).width();
	if($wdwWidth > 768){
		$(document).ready(function(){
			$(".section-content").each(function(){
        var $htext = $(this).find('.content-text').height();
        var $himg = $(this).find('.content-image').height();
        var $h = $(this).height();
        var $w = $(this).find('.right').width();
        if($htext > $himg){
          $(this).find('.content-image').css('height',$h+'px');
        }else{
          $(this).find('.content-text').css('height',$h+'px');
        }
				$(this).find('#map').css('height',$h+'px').css('width',$w+'px');
			});
		});
	}else{
		var $h = $('.content-box.right').height();
		var $w = $('.content-box.right').width();
		$('.content-box.right').find('#map').css('height',$h+'px').css('width',$w+'px');
	}
}(jQuery);

// ENTRANCE ANIMATION
+function($){
	'use strict';
    var $animation_elements = $('[data-animate="true"]');
    var $window = $(window);

    $window.on('scroll', check_if_in_view);
    $(document).ready(check_if_in_view);

    function check_if_in_view() {

      var window_height = $window.height();
      var window_top_position = $window.scrollTop();
      var window_bottom_position = (window_top_position + window_height);

      $.each($animation_elements, function() {
        var $element = $(this);
        var $effect = $(this).data('effect');
        var element_height = $element.outerHeight();
        var element_top_position = $element.offset().top;
        var element_bottom_position = (element_top_position + element_height);

        //check to see if this current container is within viewport
        if ((element_bottom_position >= window_top_position) &&
            (element_top_position <= window_bottom_position)) {
          $element.addClass('animated '+$effect);
        }
      });
    }
}(jQuery);

+function($) {
    $(document).ready(function(){

        $(window).scroll(function(){
            if ($(this).scrollTop() > 125) {
                $('.navbar').addClass('scroll');
            } else {
                $('.navbar').removeClass('scroll');
            }
        });

    });
}(jQuery);

+function($){
	'use strict';
	var $wdwWidth = $(window).width();
	if($wdwWidth > 768){
		$(document).ready(function(){
			$("#cards").each(function(){
				var $h = $(this).height();
				$(this).find('.card').css('min-height',$h+'px');
			});
		});
	}else{
    $("#cards").each(function(){
      var $h = $(this).height();
      $(this).find('.card').css('min-height','auto');
    });
	}

	$(window).resize(function(){
		var $wdwWidth = $(window).width();
		if($wdwWidth > 768){
			$("#cards").each(function(){
				var $h = $(this).height();
				$(this).find('.card').css('min-height',$h+'px');
			});
		}else{
			$("#cards").each(function(){
				var $h = $(this).height();
				$(this).find('.card').css('min-height','auto');
			});
		}
	});
}(jQuery);

+function($){
  $(".carousel").swipe({

    swipe: function(event, direction, distance, duration, fingerCount, fingerData) {

      if (direction == 'left') $(this).carousel('next');
      if (direction == 'right') $(this).carousel('prev');

    },
    allowPageScroll:"vertical"

  });
}(jQuery);
//
// + function($) {
//     'use strict';
//     var toggled = false;
//     $("#shareButton").on('click', function() {
//         var children = $("#shareLinks a").first();
//         if (toggled == false) {
//             $(children).animate({ "margin-left": 0 }, 100);
//             $('#shareLinks').delay(100).queue(function(next) {
//                 $(this).css("overflow", "visible");
//                 next();
//             });
//             toggled = true;
//         } else {
//             $(children).animate({ "margin-left": "-150px" }, 100);
//             $('#shareLinks').css("overflow", "hidden");
//             toggled = false;
//         }
//     });
// }(jQuery);

+ function($) {
  $(document).ready(function(){
    var divs = $("#categories-collapse > div");
    for(var i = 0; i < divs.length; i+=6) {
      divs.slice(i, i+6).wrapAll("<div class='row'></div>");
    }

    $("#showCategories").mouseenter(function () {
      $("#categories-collapse").collapse('show');
      var $img_h = $("#categories-collapse .category-item").find("img").height();
      $("#categories-collapse .category-item:first").find('span.icon').css('min-height',($img_h-2)+'px');

      $(".navbar .navbar-nav > li > a:not(#showCategories)").mouseenter(function () {
        $("#categories-collapse").collapse('hide');
      });

      $(".triggerClose").mouseenter(function () {
        $("#categories-collapse").collapse('hide');
      });
    });
    $("#categories-collapse").mouseleave(function(){
      $("#categories-collapse").collapse('hide');
    });

    $('#modal_cart').on('shown.bs.modal', function () {
      var $sprt_h = $("#modal_cart .modal-footer").height();
      $("#modal_cart .modal-footer .row form > div:last").css("height",$sprt_h+"px");
    });
  });
}(jQuery);

+ function($) {
  $(".radio-area").on("click",function(){
    $(this).find("input").attr("checked","checked");
    $(".radio-area input").each(function(){
      if($($(this)).is(':checked')) {
        $($(this)).parents('.radio-area').addClass('active');
      }else{
        $($(this)).parents('.radio-area').removeClass('active');
        $($(this)).removeAttr("checked");
      }
    });
  });
}(jQuery);

var updateBubble = function($url){
  jQuery.get( $url, function( data ) {
    alert(data);
  });
}

$(document).ready(function(){
  $('ul.pagination').hide()
  $('.infinite-scroll').jscroll({
    loadingHtml: '<div class="col-xs-12 col-lg-12 text-center">Loading...</div>',
    autoTrigger: true,
    padding: 0,
    nextSelector: '.pagination li.active + li a',
    contentSelector: 'div.infinite-scroll',
    callback: function() {
        $('ul.pagination').remove()
    }
  })
})


//+function($){
//  $(document).ready(function(){
//    $.cookieBar();

//      function getCookie(cname) {
//        var name = cname + "=";
//        var decodedCookie = decodeURIComponent(document.cookie);
//        var ca = decodedCookie.split(';');
//        for(var i = 0; i <ca.length; i++) {
//            var c = ca[i];
//            while (c.charAt(0) == ' ') {
//                c = c.substring(1);
//            }
//            if (c.indexOf(name) == 0) {
//                return c.substring(name.length, c.length);
//            }
//        }
//        return "";
//      }

//      var $cookie = getCookie("econception");
//      var $wWidth = $(window).width();
//      if($cookie != "accepted" && $wWidth > 768){
//        var $h = $("#cookie-bar").height();
//        $("nav").next().css("margin-top",($h*3)+"px");
//      }

//      $(".cb-enable").click(function(){
//        $("nav").next().removeAttr("style");
//      });
//  });
//}(jQuery);


$('.carousel').carousel({
  interval: 15000
})
