;(function($, window, document, undefined) {
	//'use strict';

	var $win = $(window);
	var $doc = $(document);

	$doc.ready(function() {

		// Foundation Init
		$doc.foundation();

		$imageContainerLinks = $(".wp-block-gallery figure a"),
		$imageCaption = $(".wp-block-gallery figure"),

		// Fresco Gallery
		$imageContainerLinks.each(function () {
			jQuery(this).addClass("fresco");
			jQuery(this).attr("data-fresco-group", "gal-1");
		});

		// Fresco Caption
		$imageCaption.each(function(){
			var captiontext = $(this).find("figcaption").text();
			$(this).find("a").attr("data-fresco-caption", captiontext);
		});

		// Fullscreener
		$('.fullscreener img').fullscreener();

		// Progressbar
		$('.progressbar-inner').each(function() {
			var width = $(this).data('progress');

			$(this).width(width + '%');
		});

		// Unselect radio button
		$('#field-amount').on("click",function (e) {
			$(".list-radios input:radio").attr("checked", false);
		});
		// Unselect radio button for PayPal
		$('#field-amount-pp').on("click",function (e) {
			$(".list-radios input:radio").attr("checked", false);
		});

		// Slider Intro
		$('.slider-intro .slides').owlCarousel({
			loop: true,
			autoplay: true,
			autoplayHoverPause : true,
			autoplayTimeout: 5000,
			smartSpeed: 500,
			nav: true,
			lazyLoad : true,
			navContainer: '.slider-intro .slider-actions',
			navText: ['<i class="fas fa-chevron-left"></i>', '<i class="fas fa-chevron-right"></i>'],
			items: 1,
			margin: 0
		});

		// Slider Featured
		$('.slider-featured .slides').owlCarousel({
			loop: false,
			center: false,
			nav: false,
			dots: true,
			dotsEach: 2,
			//navContainer: '.slider-featured .slider-actions',
			//navText: ['<i class="fas fa-chevron-left"></i>', '<i class="fas fa-chevron-right"></i>'],
			items: 1,
			autoWidth: true,
			margin: 30,
			responsive: {
				320: {
					items: 2
				},
				640: {
					items: 2
				},
				1024: {
					items: 3
				},
				1200: {
					items: 4
				}
			}
		});

		// Slider Sponsor
		$('.slider-sponsor .slides').owlCarousel({
			loop: true,
			nav: true,
			smartSpeed: 500,
			navContainer: '.slider-sponsor .slider-actions',
			navText: ['<i class="fas fa-chevron-left"></i>', '<i class="fas fa-chevron-right"></i>'],
			items: 1
		});

		// Slider News
		$('.slider-news .slides').owlCarousel({
			loop: true,
			nav: true,
			navContainer: '.slider-news .slider-actions',
			navText: ['<i class="fas fa-chevron-left"></i>', '<i class="fas fa-chevron-right"></i>'],
			items: 1
		});

		// Slider Staff
		$('.slider-staff .slides').owlCarousel({
			loop: true,
			mouseDrag: false,
			touchDrag: false,
			nav: true,
			smartSpeed: 500,
			navContainer: '.slider-staff .slider-actions',
			navText: ['<i class="fas fa-chevron-left"></i>', '<i class="fas fa-chevron-right"></i>'],
			items: 1
		});

		// Slider Testimonials
		$('.slider-testimonials .slides').owlCarousel({
			loop: true,
			dots: true,
			autoplay: true,
			autoplayTimeout: 5000,
			smartSpeed: 500,
			items: 1
		});

		// Slider Widgets
		$('.slider-widget .slides').owlCarousel({
			loop: true,
			dots: true,
			smartSpeed: 500,
			items: 1,
			margin: 30,
		});

		// Post Format Gallery Slider
		$('.format-gallery .post-image ul').owlCarousel({
			loop: true,
			nav: true,
			smartSpeed: 500,
			navText: ['<i class="fas fa-chevron-left"></i>', '<i class="fas fa-chevron-right"></i>'],
			items: 1
		});

		// Mobile Navigation
		var $nav = $('.nav');

		$nav.find('li').each(function() {
			if ( $(this).children('ul').length ) {
				$(this).append('<span>+</span>')
			}
		});

		$nav.find('li > span').on('click', function(e) {
			e.preventDefault();

			$(this).text( $(this).text() == "+" ? "-" : "+");
			$(this).siblings('ul').slideToggle(300);
		});

		$('.button-burger').on('click', function (event) {
			$(this).toggleClass('active');

			$nav.slideToggle(300);
			event.preventDefault();
		});

		// Share btn
		jQuery( ".share-post" ).click(function() {
			window.open( jQuery(this).data("share-url"), "sharewin", "height=400,width=550,resizable=1,toolbar=0,menubar=0,status=0,location=0" ) ;
		});

		// Google Maps
		if( $( '.wplook-google-map' ).length > 0 ) {
			$( '.wplook-google-map' ).each( function( index, element ) {
				$( element ).wplGoogleMaps();
			} );
		}

		// Aplication Fees
		if( jQuery( '.js_cc_fees' ).length > 0 ) {

			function the_amout_fee(fee) {
				var feepercent 	= parseFloat($('.js_cc_fees').data('percent-fee'));
				var feefixed 	= parseFloat($('.js_cc_fees').data('fixed-fee'));
				var feecurency 	= $('.js_cc_fees').data('curency-code');
				fee = parseFloat(fee);
				var fee_final 	= 0;

				if ( feepercent > 0 && feefixed > 0 ) {
					fee_final =  ( ( ( fee + feefixed ) / ( 1 - feepercent ) ) - fee ).toFixed(2) ;
					$( '.js_cc_fees' ).html('+ '+fee_final+' '+feecurency);
				}
			}

			jQuery( "input[name='amount_cc']" ).each( function(index) {
				var inputamount = 0;
				var thisinput = $(this);
				var inputtype = thisinput.attr('type');

				if ( inputtype == 'number' ) {
					thisinput.bind('keyup mouseup input change', function () {
						inputamount = $(this).val();
						the_amout_fee(inputamount);

					});
				}
				if ( inputtype == 'radio' ){
					thisinput.on("click", function(){
						inputamount = $(this).val();
						the_amout_fee(inputamount);

					});
				}
			})
		}
	});

	// Like post
	$(".post-like a").click(function(){

		heart = $(this);
		post_id = heart.data("post_id");

		$.ajax({
			type: "post",
			url: ajax_var.url,
			data: "action=post-like&nonce="+ajax_var.nonce+"&wplook_post_like=&post_id="+post_id,
			success: function(count){
				if(count != "already") {
					heart.addClass("voted");
					heart.siblings(".count").text(count);

					heart.addClass("voted");
					heart.find('i.fa').removeClass("fa-heart-o");
					heart.find('i.fa').addClass("fa-heart");
					heart.siblings(".count").text(count);
				}
			}
		});

		return false;
	});

	/* Text Widget */
	jQuery(".page-template-template-homepage .widget_text").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_text").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );


	/* Audio Widget */
	jQuery(".page-template-template-homepage .widget_media_audio").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_media_audio").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );


	/* Video Widget */
	jQuery(".page-template-template-homepage .widget_media_video").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_media_video").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );


	/* Image Widget */
	jQuery(".page-template-template-homepage .widget_media_image").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_media_image").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );


	/* Tag cloud widget*/
	jQuery(".page-template-template-homepage .widget_tag_cloud").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_tag_cloud").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );


	/* Recent Comments */
	jQuery(".page-template-template-homepage .widget_recent_comments").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_recent_comments").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );


	/* Recent Posts */
	jQuery(".page-template-template-homepage .widget_recent_entries").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_recent_entries").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );


	/* Widget pages */
	jQuery(".page-template-template-homepage .widget_pages").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_pages").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );


	/* Widget Meta */
	jQuery(".page-template-template-homepage .widget_meta").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_meta").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );


	/* Widget Categories */
	jQuery(".page-template-template-homepage .widget_categories").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_categories").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );


	/* Widget Calendar */
	jQuery(".page-template-template-homepage .widget_calendar").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_calendar").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );

	/* Widget Archives */
	jQuery(".page-template-template-homepage .widget_archive").wrap( "<div class='custom-widgets-home'></div>" );
	jQuery(".page-template-template-homepage .widget_archive").wrap( "<div class='grid-container'><div class='grid-x'><div class='cell'></div></div></div>" );

	// Add .end to the last .columns element
	$( '.section-upcoming-event .row .columns' ).last().addClass( 'end' );

})(jQuery, window, document);
