// source --> https://cruxx.eu/wp-content/plugins/age-checker/inc/assets/js/initialize.js?ver=1.1.8 
jQuery( document ).ready( function( $ ) {
	if ( document.cookie.indexOf( "agc_verified_" + agc.age + "=" ) == -1 || agc.preview == 1 ) {
		// Setup viewport for agc screen
		if( !$( 'meta[name="viewport"]' ).length ) {
			$( 'head' ).append( '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>' );
		}
		else {
			$( 'meta[name="viewport"]' ).attr( 'content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' );
		}
		$( 'html, body' ).addClass( 'agc_no_scroll' );
		
		// iOS and Android won't autoplay unless video is muted
		var windowsize = $( window ).width();
		if( windowsize < 992 ) {
			agc.screen = agc.screen.replace( "<video class='agc_screen' id='agc_bg_video' autoplay playsinline loop>", "<video class='agc_screen' id='agc_bg_video' autoplay playsinline loop muted>" );
		}
		$( 'body' ).append( agc.screen );	
	}
});
// source --> https://cruxx.eu/wp-content/plugins/age-checker/inc/assets/js/js.js?ver=1.1.8 
jQuery( document ).ready( function( $ ) {
	$( 'body' ).on( 'click', '.agc_select', function() {
		var wrap = $( this ).closest( '.agc_select_wrap' );
		if( !wrap.find( '.agc_options' ).hasClass( 'agc_active' ) ) {
			$( '.agc_options' ).removeClass( 'agc_active' );
			wrap.find( '.agc_options' ).addClass( 'agc_active' );
			wrap.find( '.agc_options' ).find( 'li:contains("' + wrap.find( '.agc_select_val' ).html() + '")' ).addClass( 'agc_active' );
		}
		else {
			wrap.find( '.agc_options' ).removeClass( 'agc_active' );
		}
	});
	
	$( 'body' ).on( 'click', '.agc_options ul li', function() {
		var wrap = $( this ).closest( '.agc_select_wrap' );
		wrap.find( '.agc_select_val' ).html( $( this ).html() );
		wrap.find( 'select' ).val( $( this ).attr( 'data-val' ) );
		wrap.find( '.agc_options' ).removeClass( 'agc_active' );
	});
	
	$( 'body' ).on( 'mouseover', '.agc_options ul li', function() {
		if ( $( '.agc_options ul li' ).hasClass( 'agc_active' ) ) {
			$( '.agc_options ul li' ).removeClass( 'agc_active' );
		}
	});
	
	$( document ).click( function(e) {
		if( $( e.target ).attr( 'class' ) != 'agc_select' && !$( '.agc_select' ).find( $( e.target ) ).length ) {
			if( $( '.agc_options.agc_active' ).length ) {
				$( '.agc_options' ).removeClass( 'agc_active' );
			}
		}
	});

	$( 'body' ).on( 'submit', '#agc_verify_form', function(event) {
		event.preventDefault();
		var form = $( this );
		form.find( '.agc_result' ).remove();
		$.ajax({
			type: "POST",
			url: form.attr( 'data-url' ),
			data: form.serialize(),
			cache: false,
			success: function (result) {
				try {
					result = jQuery.parseJSON( result );
					if ( result['result'] == 'success' ) {
						$( 'html, body' ).removeClass( 'agc_no_scroll' );
						$( '.agc_screen' ).remove();
					}
					else if ( result['result'] == 'validate' ) {
						$( '#agc_verify_submit' ).append( '<div class="agc_result"><span class="agc_icon_exclamation_circle"></span> ' + result['output'] + '</div>' );
					}
					else {
						throw 0;
					}
				}
				catch(err) {
					$( '#agc_verify_submit' ).append( '<div class="agc_result"><span class="agc_icon_exclamation_circle"></span> Failed, please try again.</div>' );
				}
			}
		});
	});
	
});