$(document).ready(function() {
	
	/* SUBSCRIPTION */
	if ( $( "#subscription-ajax" ).length ) 
	{
		$("#btn-subscription").on("click", function(event){
			var formURL 	= $('#subscription-ajax').attr('action');
			var emailadd 	= $('#email_subscribe').val();
			if (emailadd == '' || emailadd == null)
			{
				alertify.error('Subscription email address is required!');
			}
			else
			{
				$.ajaxSetup ({ cache: false });
				var url 	= $(this).attr('url');
				$.post(formURL,{email_subscribe:emailadd},function(resp)
				{
					var feedback = jQuery.parseJSON( resp );
					
					if (feedback.status == '1')
					{
						alertify.success('Thank you for subscribing our newsletter');
					}
					else if (feedback.status == '2')
					{
						alertify.success('You already have subscription with us!');
					}
					else
					{
						alertify.error('Invalid Subscription');
					}
				});			
			}
		});
	}
	/* LAZY */
	if ( $( "img.lazy" ).length ) 
	{
		$("img.lazy").unveil(600, function() {
			$(this).load(function() {
			 this.style.opacity = 1;
			});
		});
	}

	
	$(".footer-mobile-trigger").on("click", function(event){
		var ww = $( window ).width();
		if (ww <= 768)
		{
			var trigger = $(this).attr('trigger');
			$('#'+trigger).slideToggle();
		}
	});
	$(window).bind('resize', function()
	{
		if ($(window).width() > 768) 
		{
			$('.footer-content').show();
		}
		else
		{
			$('.footer-content').hide();
		}
	});
	
	if ( $( ".video-player" ).length ) 
	{
		$('.video-player').bgVideo({  fadeIn: 1, pauseAfter: 0, fadeOnPause: false, fadeOnEnd: true, showPausePlay: false });
	}
});
$(document).ready(function() {
	$( "div[data-background]" ).each(function( index ) {
	  $(this).css('background-image', 'url(' + $(this).attr('data-background') + ') ');
	});
});

$(document).ready(function() {

	function onScrollInit( items, trigger ) 
	{
		items.each( function() 
		{
			var osElement 			= $(this),
			osAnimationType		= osElement.attr('animation-type'),
			osAnimationDelay 		= osElement.attr('animation-delay');
			osAnimationDuration 	= osElement.attr('animation-duration');

		

			if (typeof osAnimationType == "undefined" || osAnimationType == false) 
			{
				osAnimationType = "fadeIn";
			}

			if (typeof osAnimationDuration == "undefined" || osAnimationDuration == false) 
			{
				osAnimationDuration = "1";
			}
		
			if (typeof osAnimationDelay == "undefined" || osAnimationDelay == false) 
			{
				osAnimationDelay = "0";
			}

			osElement.css("animation-delay", osAnimationDelay + "s");
			osElement.css("animation-duration", osAnimationDuration + "s");

			var osTrigger = ( trigger ) ? trigger : osElement;

			osTrigger.waypoint(function() 
			{
				osElement.addClass('animated');
				osElement.addClass(osAnimationType);
			}
			,
			{
				triggerOnce: true,
				offset: '100%'
			});
		});
	}
	onScrollInit( $('.do-animation') );
	
	// function animateExpired()
	// {
		// $( ".animate-once" ).each(function( index ) {
			
			// $(this).removeClass('do-animation');
			// $(this).removeClass('animated');
		  
		// });
	// }
	// setTimeout(animateExpired, 3000);
	
});



$(document).ready(function() {
	if ( $( ".btn-filters" ).length ) 
	{
		$(".btn-filters").on("click", function(event){
			var header = $(this).attr('header-filter');
		  $('#header-filter').html(header);
		});
	}
	if ( $( "#shuffle" ).length ) 
	{
		$(function(){
			 $('#shuffle').mixItUp();
		});
	}
});



	$(document).ready(function() {
	  $("body").on("click", "#btn-promo-code",function(event){
			$('#promo-code-before-container').hide();
			$('#promo-code-process-container').show();
			console.log('aa');
	  });
	  $("body").on("click", "#verify-promo-btn",function(event){
		  
		  var url = $('#promo_code_check_url').val();
		  var code = $('#promo_code_check').val();
		  
		  if (code == '')
		  {
				alertify.error('Please enter promo code');$('#promo_code').val('');
		  }
		  else
		  {
			  $.ajaxSetup ({ cache: false }); 
			
			  $.post(url,{promo_code:code},function(data)
			  {
					var status = jQuery.parseJSON( data );
					if (status.success == 1)
					{
						alertify.success(status.msg);
						$('#promo_info').html(status.html);
						$('#promo_info').html(status.html);
						$('#promo-code-process-container').hide();
						$('#promo-code-after-container').show();
						$('#promo_code').val(code);
					}
					else
					{
						alertify.error(status.msg);
						$('#promo_code').val('');
					}
			  });
		  }
	  });
	});




