// source --> https://xn--harkebrgge-geb.de/wp-content/plugins/wp-facebook-login/public/js/facebook-login.js?ver=1.2.3.5 
window.FBL = {};
function fbl_loginCheck() {
    window.FB.getLoginStatus( function(response) {
        FBL.handleResponse(response);
    } );
}
(function( $ ) {
	'use strict';
	FBL.renderFinish = function () {
        $('.fbl-spinner').hide();
    }

    FBL.handleResponse = function( response ) {
        var button          =  $('.fbl-button'),
            $form_obj       = button.parents('form') || false,
            $redirect_to    = $form_obj.find('input[name="redirect_to"]').val() || button.data('redirect'),
            running         = false;
        /**
         * If we get a successful authorization response we handle it
         */
        if (response.status == 'connected' && ! running) {
            running = true;
            var fb_response = response;
            $('.fbl-spinner').fadeIn();
            $('.fb-login-button').hide();

            /**
             * Send the obtained token to server side for extra checks and user data retrieval
             */
            $.ajax({
                data: {
                    action: "fbl_facebook_login",
                    fb_response: fb_response,
                    security: button.data('fb_nonce')
                },
                global: false,
                type: "POST",
                url: fbl.ajaxurl,
                success: function (data) {
                    if (data && data.success) {
                        if( data.redirect && data.redirect.length ) {
                            location.href = data.redirect;
                        } else if ( $redirect_to.length ) {
                            location.href = $redirect_to;
                        } else {
                            location.href = fbl.site_url;
                        }
                    } else if (data && data.error) {
                        $('.fbl-spinner').hide();
                        $('.fb-login-button').show();

                        if ($form_obj.length) {
                            $form_obj.append('<p class="fbl_error">' + data.error + '</p>');
                        } else {
                            // we just have a button
                            $('<p class="fbl_error">' + data.error + '</p>').insertAfter(button);
                        }
                        // if we had any error remove user from app so we request again permissions
                        FB.api(
                            "/"+data.fb.id+"/permissions",
                            "DELETE",
                            function (response) {
                                if (response && !response.error) {
                                }
                            }
                        );
                    }
                },
                error: function (data) {
                    $('.fbl-spinner').hide();
                    $('.fb-login-button').show();
                    $form_obj.append('<p class="fbl_error">' + data + '</p>');
                }
            });

        } else {
            button.removeClass('fbl-loading');
            if( navigator.userAgent.match('CriOS') )
                window.open('https://www.facebook.com/dialog/oauth?client_id=' + fbl.appId + '&redirect_uri=' + document.location.href + '&scope='+fbl.scopes, '', null);

            if( "standalone" in navigator && navigator.standalone )
                window.location.assign('https://www.facebook.com/dialog/oauth?client_id=' + fbl.appId + '&redirect_uri=' + document.location.href + '&scope='+fbl.scopes);
        }
    };
})( jQuery );
// source --> https://xn--harkebrgge-geb.de/wp-content/themes/spacious/js/spacious-custom.js?ver=6.9.4 
jQuery( document ).ready( function () {
	jQuery( '#scroll-up' ).hide();
	jQuery( function () {
		jQuery( window ).scroll( function () {
			if ( jQuery( this ).scrollTop() > 1000 ) {
				jQuery( '#scroll-up').fadeIn();
			} else {
				jQuery( '#scroll-up' ).fadeOut();
			}
		});
		jQuery( 'a#scroll-up' ).click( function () {
			jQuery( 'body, html' ).animate({
				scrollTop: 0
			}, 800 );
			return false;
		});
	});

	/**
	 * Responsive menu with toggle
	 */
	 jQuery('.better-responsive-menu .menu-primary-container .menu-item-has-children').
	 append('<span class="sub-toggle"> <span class="fa fa-caret-right"></span> </span>');

	 jQuery('.better-responsive-menu .menu-primary-container .sub-toggle').click(function() {
		jQuery(this).parent('.menu-item-has-children').children('ul.sub-menu').first().slideToggle('1000');
		jQuery(this).children('.sub-toggle .fa').first().toggleClass('fa-caret-down fa-caret-right');
	});

	/**
	 * Search
	 */
	var hideSearchForm = function() {
		jQuery( '.header-search-form' ).removeClass( 'show' );
	};

	// On Search icon click.
	jQuery( '#header-right-section .search, .bottom-menu .search' ).click( function () {
		jQuery( this ).next( '.header-search-form' ).toggleClass( 'show' );

		// focus after some time to fix conflict with toggleClass
		setTimeout( function () {
			jQuery( '.header-search-form.show input' ).focus();
		}, 200 );

		// For esc key press.
		jQuery( document ).on( 'keyup', function ( e ) {

			// on esc key press.
			if ( 27 === e.keyCode ) {
				// if search box is opened
				if ( jQuery( '.header-search-form' ).hasClass( 'show' ) ) {
					hideSearchForm();
				}

			}
		} );

		jQuery( document ).on( 'click.outEvent', function( e ) {
			if ( e.target.closest( '.search-wrapper' )  ) {
				return;
			}

			hideSearchForm();

			// Unbind current click event.
			jQuery( document ).off( 'click.outEvent' );
		} );

	} );
});

/**
 * Slider Setting
 *
 * Contains all the slider settings for the featured post/page slider.
 */
jQuery(window).on('load',function() {
	if ( typeof jQuery.fn.cycle !== 'undefined' ) {
		jQuery( '.slider-cycle' ).cycle( {
			fx               : 'fade',
			timeout          : 4000,
			speed            : 1000,
			slides           : '> div',
			pager            : '> #controllers',
			pagerActiveClass : 'active',
			pagerTemplate    : '<a></a>',
			pauseOnHover     : true,
			autoHeight       : 'container',
			swipe            : true,
			swipeFx          : 'scrollHorz',
			log              : false
		} );
	}
});