//lazy load
$(window).on('load', function () {
    $("<span class='loading'><i class='fa fa-circle-o-notch fa-spin'></i></span>").insertAfter($('img.lazy'));
});

$('.lazy').lazy({
    delay: 3000,
    //effect: "fadeIn",
    //effectTime: 1000,
    //threshold: 0,
    //placeholder: "data:image/gif;base64,R0lGODlhEALAPQAPzl5uLr9Nrl8e7...",
     
    /*beforeLoad: function(element) {
        var imageSrc = element.data('src');
        //$("<span class='loading'><i class='fa fa-circle-o-notch fa-spin'></i></span>").insertAfter($(element));
        console.log('image "' + imageSrc + '" is about to be loaded');
    },*/
    
    // called after an element was successfully handled
    afterLoad: function(element) {
        var imageSrc = element.data('src');
        $(element).addClass('show-img');
        $(element).next("span.loading").remove();
        //console.log('image "' + imageSrc + '" was loaded successfully');
    },
    
    /*// called whenever an element could not be handled
    onError: function(element) {
        var imageSrc = element.data('src');
        console.log('image "' + imageSrc + '" could not be loaded');
    },
    
    // called once all elements was handled
    onFinishedAll: function() {
        console.log('finished loading all images');
    }*/
});



//link ancora
$("a.linkAnchor").click(function(e){
    
    e.preventDefault();
    
	linkAncor = $(this).attr('href');
	
	event.preventDefault();
    $('html, body').animate(
    {
        scrollTop: $(linkAncor).offset().top
    },1000);
   
});

//nav-link
$(".navbar-nav a.nav-link").on("click", function(){
    $(this).parents().find(".active").removeClass("active");
    $(this).addClass("active");
});

$("a.logo-top").on("click", function(){
    $("a.section-top").trigger("click");
});

//form captura
$('.formCaptura').submit(function(e){
    e.stopPropagation();
    e.preventDefault();
    
    loadButton($('.formCaptura button'));
	
	base_ajax = base_url == "https://comdono.com/" ? base_site : base_url;
	
	$.ajax({
		url: base_ajax+"landingpage/ajax/captura_ajax/captura_interessado_empreendimento",
		dataType: 'json',
		type: 'POST',
		data: get_form('.formCaptura'),
		success: function(retorno)
		{	
			if (retorno.valid == true)
			{
			    window.location.href = retorno.data.redirect;
			}
			else
			{
			    loadButton(null,false);
    	        $('.formCaptura .content_result').html('<p class="text-danger">'+retorno.msg+'</p>');
			}
		},
		error: function(error)
		{
		    loadButton(null,false);
			$('.formCaptura .content_result').html('<p class="text-danger">'+retorno.msg+'</p>');
		}
	});
	
});