$(function(){
	'use strict';
	//Slider
	var $owl = $('.owl');
	$owl.each( function() {
		var $a = $(this);
		$a.owlCarousel({
			transitionStyle: $a.attr('data-transitionstyle'),
			autoPlay:true,
			singleItem: JSON.parse($a.attr('data-singleItem')),
			items : $a.attr('data-items'),
			itemsDesktop : [1199,$a.attr('data-itemsDesktop')],
			itemsDesktopSmall : [992,$a.attr('data-itemsDesktopSmall')],
			itemsTablet:  [797,$a.attr('data-itemsTablet')],
			itemsMobile :  [479,$a.attr('data-itemsMobile')],
			navigation : JSON.parse($a.attr('data-buttons')),
			pagination: JSON.parse($a.attr('data-pag')),
			navigationText: ["",""],
			touchDrag: false,
			mouseDrag: false
		});
	});
	//Menu
	$('.menu-btn').on('click',function(e){
		//e.stopPropagation();
		
		
		if($(this).hasClass('active'))
		{
			$('.menu-rs').animate({right: '-250px'},500);
		}
		else
		{
			$('.menu-rs').animate({right: '0px'},500);
		}
	});
	$('.r-mv').on('click',function(){
		$('.menu-rs').animate({right: '-250px'},500);
	});
	
	//$('.max-w-900').waypoint(function() {
		//$('.max-w-900').addClass('animated');
		//$('.max-w-900').addClass('slideInDown');
	//},{ offset: '100%'});

	//Preloader
	$(window).load(function()
	{
		$('.preloader i').fadeOut();
		$('.preloader').delay(500).fadeOut('slow');
		$('body').delay(600).css({'overflow':'visible'});
	});
	//Menu
	$('.navbar-toggle').on('click',function(){
		height_w(); 
	});
	function height_w()
	{
		$('.navbar-nav').css('max-height',$(window).height()-165);
	}
	window.onresize = function()
	{
		height_w();
		ft();
		set_height();
		align_mid();
	}
	function bg11(){
		$('.bg-offset').each(function(){
			var $t=$(this).attr('data-image-src');
			if($t){
				$(this).css('background-image','url("' + $t + '")');
			}
		});
	}
	bg11();
	//align middle
	function set_height()
	{
		if((/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) || $(window).width()<700 )
		{
			$('.offset_h').removeAttr('style');
		}
		else
		{
			$('.offset_h').css('height',$('.target_h').height());
		}
	}
	set_height();
	function align_mid()
	{
		var $out_item=$('.align_middle');
		$out_item.each(function(){
		var $h_parent=$(this).height();
		var $h_child=$(this).find('.align_item').height();
		$(this).find('.align_item').css('margin-top',($h_parent-$h_child)/2);
		});
	} 
	align_mid();
	//cart dropdown 
	$('.cart .dropdown-menu').on('click',function(e) {
		e.stopPropagation();  
	});
	
	$('.search-box').removeClass('active');
	$('.icon-search').on('click',function(e) 
	{
		e.preventDefault();
		var $searchb = $('.search-box');
		if(!$searchb.hasClass('active'))
		{
			$searchb.addClass('active');
			$('.search-box input').val('');
			$searchb.fadeIn();
			$('.search-box input').focus();
			$(this).addClass('fa-remove');
			$(this).removeClass('fa-search');
		}
		else
		{
			$searchb.fadeOut();
			$searchb.removeClass('active');
			$(this).removeClass('fa-remove');
			$(this).addClass('fa-search');
			
		}
	});
	$('.search-box .btn').on('click',function(e) 
	{
		var $searchb = $('.search-box');
		$('.icon-search').removeClass('fa-remove');
		$('.icon-search').addClass('fa-search');
		$searchb.removeClass('active');
		$searchb.fadeOut();
	});
	$('.search-box input').keypress(function(event){
	  if(event.keyCode == 13){
		$('.search-box .btn').click();
	  }
	});
	//Header resize
	function ft(){
		if((/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) || $(window).width()<700 )
		{
			$('.header-1').next().removeAttr('style');
		}
		else
		{
			$('.header-1').next().css('marginTop',($('header').height())+'px');
		}
	}
	ft();
	$('header').removeClass('smaller');
	$('.main-header').removeClass('animated').removeClass('slideInUp').removeClass('slideInDown');
	window.addEventListener('scroll', function(e){
		var $tr=0;
		if($('header').height())
		{
			$tr=$('header').height();
		}
		else
		{
			$tr=0;
		}
		var distanceY = window.pageYOffset || document.documentElement.scrollTop,
			shrinkOn = $tr;
			var header = document.querySelector("header");
		if (distanceY > shrinkOn) {
			classie.add(header,"smaller");
			$('.main-header').removeClass('animated').removeClass('bounceInUp');
			$('.main-header').addClass('animated').addClass('slideInDown');
		} else {
			if (classie.has(header,"smaller")) {
				$('.main-header').removeClass('animated').removeClass('slideInDown');
				classie.remove(header,"smaller");
			}
		}
	});
	
	
});