(function($) {

	'use strict';

	//header

	var iScrollPos = 0;

	$(window).scroll(function () {
	    var iCurScrollPos = $(this).scrollTop();
	    if (iCurScrollPos > 130) {
	    	$('header').addClass('sticky')
        	$('#header-movil').addClass('sticky')
	    }else{
	    	$('header').removeClass('sticky')
			$('#header-movil').removeClass('sticky')
	    }
	});

	$('.scrollTo').on('click', function(e) {
		e.preventDefault()
		var ancho = $(window).width();
		var target = $(this).attr('href');
		 // animate
		 if(ancho >= 720){
		 	$('html, body').animate({
				 scrollTop: $(target).offset().top -80
			 }, 1000);
			 $(".list-links").removeClass('open')
		 }else{
		 	$('html, body').animate({
				 scrollTop: $(target).offset().top -250
			 }, 1000);
			 $(".list-links").removeClass('open')
		 }
		 
	});

	$(".menu-icon").on("click", function(){
		$(".list-links").toggleClass('open')
	})

	//popup
	$(".open-popup").on("click", function(){
		$("#popup").fadeIn()
	})
	$("#close-popup").on("click", function(){
		$("#popup").fadeOut()
	})

	//Send form
	$('.send-form').on('click', function(){
		var thisForm = $(this)
		$.ajax({
			type: "POST",
			data: $(this).closest("form").serialize(),
			url: "process.php",
			success: function (mje) {

				console.log(mje);

				if (mje == 0){

					thisForm.siblings('.mensajes-form').html("<span style='color:#00C853; font-size: 18px; text-align: center; margin-top:28px; padding-bottom:28px; font-weight:600'>GRACIAS POR CONTACTARNOS");
					$('.form-contact').trigger("reset");

					setTimeout(function(){

						thisForm.siblings('.mensajes-form').html("");

					},3000);

				}else if(mje == 1){
					thisForm.siblings('.mensajes-form').html("<span style='color:red; margin: 15px 0; padding-bottom:28px;'>*TODOS LOS CAMPOS SON REQUERIDOS</span>");

					setTimeout(function(){

						thisForm.siblings('.mensajes-form').html("");

					},2000);

				}else if(mje == 2){
					thisForm.siblings('.mensajes-form').html("<span style='color:red; margin: 15px 0; padding-bottom:28px;'>INGRESE UNA DIRECCIÓN DE CORREO VALIDA</span>");

					setTimeout(function(){

						thisForm.siblings('.mensajes-form').html("");

					},2000);
				}

			},

		});

	});

	$( ".btn" ).hover(
	  function() {
	    $( this ).find("div").css("background","#e8e8e8");
	    $(".btn:hover div").css("color", "")
	  }, function() {
	    $( this ).find("div").css("background","transparent");
	    $(".btn:hover div").css("color", "")
	  }
	);
	var parent, ink, d, x, y;
	$(".btn div").click(function(e){
		console.log("lala")
		parent = $(this).parent();
		//create .ink element if it doesn't exist
		if(parent.find(".ink").length == 0)
			parent.prepend("<span class='ink'></span>");
			
		ink = parent.find(".ink");
		//incase of quick double clicks stop the previous animation
		ink.removeClass("animate");
		
		//set size of .ink
		if(!ink.height() && !ink.width())
		{
			//use parent's width or height whichever is larger for the diameter to make a circle which can cover the entire element.
			d = Math.max(parent.outerWidth(), parent.outerHeight());
			ink.css({height: d, width: d});
		}
		
		//get click coordinates
		//logic = click coordinates relative to page - parent's position relative to page - half of self height/width to make it controllable from the center;
		x = e.pageX - parent.offset().left - ink.width()/2;
		y = e.pageY - parent.offset().top - ink.height()/2;
		
		//set the position and add class .animate
		ink.css({top: y+'px', left: x+'px'}).addClass("animate");
		setTimeout(function(){ 
			$(".btn:hover div").css("background", "transparent")
			$(".btn:hover div").css("color", "white")
		}, 300);
			
	})

	// Carousel paquetes
	$('.carousel-paquetes').owlCarousel({
	    loop:false,
	    margin:10,
	    autoplay:true,
	    responsiveClass:true,
	    navText: ["<i class='glyphicon glyphicon-menu-left left-paquetes'></i>","<i class='glyphicon glyphicon-menu-right right-paquetes'></i>"],
	    responsive:{
	        0:{
	            items:1,
	            dots:false,
	            nav:true
	        },
	        600:{
	            items:1,
	            dots:false,
	            nav:false
	        },
	        1000:{
	            items:1,
	            nav:true,
	            dots:false,
	            loop:false
	        }
	    }
	})
	// Fin

	// Popup image
	$('.pop-image').magnificPopup({
	  type: 'image',
	  gallery:{
	    enabled:true
	  }
	});
	// Fin

})(window.jQuery);
