//i love my job.
jQuery(document).ready(function($) {





if ($("#wp-admin-bar-toggle_block_edit_links .ab-item").length) {
	$("#wp-admin-bar-toggle_block_edit_links .ab-item").on( 'click', function(event ) {
		event.preventDefault();
    	$('.admnlnk' ).toggleClass('hide');
    });
}

if ($("#wp-admin-bar-toggle_bar .ab-item").length) {
	$("#wp-admin-bar-toggle_bar .ab-item").on( 'click', function(event ) {
		event.preventDefault();
    	$('body' ).toggleClass('logged-in admin-bar');
        $('#wpadminbar' ).toggleClass('hide');
		$('html').toggleClass('nomar');
		$('#dev_tools').toggleClass('hide');
    });
}

////////////////////////////////////////////////////////////// SIM- for WP is_customizer
$(function() {
      $("#preview_iPhone").click( function() { $('iFrame', window.parent.document).width('414px'); });
	  $("#preview_iPad").click( function() { $('iFrame', window.parent.document).width('768px'); });
	  $("#preview_Full").click( function() { $('iFrame', window.parent.document).width('100%'); });
});
////////////////////////////////////////////////////////////// SIM- for WP is_customizer



/*////////////////////////////////////////////////////////////// parallax depricated
if ($(".parallax_window").length) {
	if($(document).width() > 1024) { // paralax does not work on mobile devices
	 $('.parallax_window').each(function(index) {
		var _img = jQuery(this).attr('data-image-src');
		jQuery(this).css("background", "none");
		$('.parallax_window').parallax({imageSrc: _img });
	  });
	}
}
////////////////////////////////////////////////////////////// parallax */





////////////////////////////////////////////////////////////// smooth-scroll extras
// Add smooth scrolling to any links - NOTE: not the same as scroll-to main menu items
if ($(".smooth-scroll").length) {
	$(function() {
	  $('a.smooth-scroll[href*="#"]:not([href="#"])').click(function() {
		if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') && location.hostname === this.hostname) {
		  var target = $(this.hash);
		  target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
		  if (target.length) {
			  //console.log(target.offset());
			  //console.log(target.attr('id'));
			  
			$('html, body').animate({
			  scrollTop: target.offset().top
			}, 1000);
			return false;
		  }
		}
	  });
	});
}
////////////////////////////////////////////////////////////// smooth-scroll




////////////////////////////////////////////////////////////// Masonry
		 //$('.force_v_3').css({ 'height': (cw*3) + 'px' });
		/*  var totalHeight = 0;
				$(".masonry.grid").children().each(function(){
					totalHeight = totalHeight + $(this).outerHeight(true);
				});
				$('.masonry.grid').css({ 'height':totalHeight + 'px' }); */	
////////////// for loops	 
if ($(".masonry").length) {
	
	 var isotope_on = false;
	 var $container = $('.grid');
	 var isoOptions = {
			 itemSelector: '.a_loop_item',
			 layoutMode: 'masonry', //fitRows
			 masonry: {
			  columnWidth: 1,
			  resize: true
			}
			//fitRows: {columnWidth: 220, rowHeight: 220},
		};
	 
	 $container.imagesLoaded( function(){
		  $container.isotope(isoOptions);
		});
	 setTimeout(fadeIsotope, 150);
	 function fadeIsotope() {
		 $container.css("opacity", "1.0");
	 }
  
  	if ($(".filter-button-group").length) {
		$('.filter-button-group').each( function( i, buttonGroup ) {
			var $buttonGroup = $( buttonGroup );
			
			$buttonGroup.on( 'click', '.filter-button', function(event ) {
				event.preventDefault();
				$buttonGroup.find('.selected').removeClass('selected');
				$( this ).addClass('selected');
				var filterValue = $(this).attr('data-filter');
				$container.isotope({ filter: filterValue });
				//$container.isotope('layout');
				// in case it was destroyed somewhere else
			});
			
			
		});// each
	}// if
}	
////////////////////////////////////////////////////////////// Masonry



////////////////////////////////////////////////////////////// accordian
if ($(".accordian").length) {
	
//////////////////////////////////////////////////////////////
//$('#only-one [data-accordion]').accordion();
	$('.accordian [data-accordion]').each(function(index) {
		
		$(this).accordion({
			transition_speed: $(this).parent().attr('data-transition_speed'),
			transition_easing: $(this).parent().attr('data-transition_easing'),
			control_element: $(this).parent().attr('data-control_element'),
			content_element: $(this).parent().attr('data-content_element'),
			group_element: $(this).parent().attr('data-group_element'),
			single_open: $(this).parent().attr('data-single_open'),
			open_ico: $(this).parent().attr('data-open_ico'),
			close_ico: $(this).parent().attr('data-close_ico'),
		  //single_open: false
		});
		
	 });
	 
	 // what about accordian WITH isotope...
			if ($(".masonry .accordian-item").length) {
				
				$('.masonry .accordian-item').on('click', function(event) {
					
					
					 $container.isotope('layout');
					 
					var timeout = ($(this).data('transition_speed') / 1.011);
					
					setTimeout(function () {
						
					}, timeout);
					//$container.delay("slow").isotope( isoOptions ); // re-initialize
					//console.log('initialize');
					//$container.isotope('layout'); 
					// $container.isotope('reloadItems');
					//$container.isotope('destroy');
					//$container.isotope('layout');
			  });
			}// if
	 
	 

	/*$('#single[data-accordion]').accordion({
	  transition_easing: 'cubic-bezier(0.455, 0.030, 0.515, 0.955)',
	  transition_speed: 200
	});*/

//////////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////////// accordian







////////////////////////////////////////////////////////////// Flickity
if ($(".mini_slider").length) {
	 // sliders - flickity
	var sliders = [].slice.call(document.querySelectorAll('.mini_slider'));
	var	flkties = [];
	// array where the flickity instances are going to be stored

		function initFlickity() {
		sliders.forEach(function(slider){
			//console.log(jQuery(slider).attr('data-autoplay'));
			//alert(jQuery(slider).attr('data-autoplay'));
			var flkty = new Flickity(slider, {
				prevNextButtons: false,
				wrapAround: true,
				cellAlign: 'left',
				contain: true,
				resize: false,
				setGallerySize: false,
				//autoPlay: 1000,
				//autoPlay: false
			});

			// store flickity instances
			flkties.push(flkty);
		});
	}
		
		initFlickity();
 
 		/*change is-checked class on buttons
	  	$('.mini_slider').each( function( i, mini_slider ) {
			var $mini_slider = $( mini_slider );
			$mini_slider.hover(
			  function() {$( this ).flickity().flickity('next' ); }, function() { console.log(this.id);}
			);
	  }); */
 
	 /* recalcFlickities();
		function recalcFlickities() {
			for(var i = 0, len = flkties.length; i < len; ++i) {
				flkties[i].resize();
			}
		}
		// window resize / recalculate sizes for both flickity and isotope/masonry layouts
			window.addEventListener('resize', throttle(function(ev) {
				recalcFlickities()
				iso.layout();
			}, 50));
		*/
}
////////////////////////////////////////////////////////////// Flickity

	
	
////////////////////////////////////////////////////////////// mobile date picker
if ($("#booking_z").length) {
	var endDate = new Date();
	endDate = new Date(endDate.setDate(endDate.getDate() + 365));
		$('#booking_z').mobiscroll().range({
			theme: 'mobiscroll',
			display: 'modal',
			layout: 'liquid',
			startInput: '#checkin',
			endInput: '#checkout',
			headerText: '{value}',
			swipeDirection: 'vertical', // horizontal 
			defaultValue: [],
			//layout: '',
			minDate: new Date(),
			maxDate: endDate,
			rangeTap: true,
			setText: 'Book Now',
			onSelect: function () {
				$('#booking_form').submit();
			},
		   // onSetDate: function(valueText, inst) {
				//alert(this);
			//},
			//onDayChange: function(valueText, inst) {
				//alert(startInput.value());
			//},
			//focusOnClose	  
		});
}
////////////////////////////////////////////////////////////// mobile date picker
	
	
	
////////////////////////////////////////////////////////////// review_slider
if ($(".post_slider").length) {
	//http://bxslider.com/options
	//////////////////////////////////////////////////////////////
	$('.post_slider').bxSlider({
		slideWidth: 800,
		minSlides: 1,
		maxSlides: 1,
		pager: true,
		slideMargin: 0,
		//mode: 'horizontal', 'vertical', 'fade',
		//speed: 500,
		//infiniteLoop: true, //boolean (true / false)
		//auto: true, //boolean (true / false)
		preloadImages: 'visible',
		nextText: '&gt;',
		prevText: '&lt;',
		onSliderLoad: function(currentIndex) {
			// cleanup for massive expansion
		}
	});
	//////////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////////// review_slider
	
 

	
////////////////////////////////////////////////////////////// popups
if ($(".popup_trigger").length) {
	//////////////////////////////////////////////////////////////
	$(document).on("click", ".popup_trigger", function() {
		return false;
	});
	$('.popup_trigger').each(function(index) {
		var type = jQuery(this).attr('data-type'),
			width = jQuery(this).attr('data-width'),
			height = jQuery(this).attr('data-height'),
			popclass = jQuery(this).attr('data-popclass'),
			navclose = jQuery(this).attr('data-navclose'),
			navprev = jQuery(this).attr('data-navprev'),
			navnext = jQuery(this).attr('data-navnext'),
			target = jQuery(this).attr('data-target'),
			header = jQuery(this).attr('data-header'),
			group = jQuery(this).attr('data-group'),
			total = jQuery(this).attr('data-total');
			
		jQuery(this).zpop_popup({
			'target': target,
			'width': width,
			'height': height,
			'type': type,
			'popclass': popclass,
			'navclose': navclose,
			'navprev': navprev,
			'navnext': navnext,
			'header': header,
			'group': group,
			'total': total,
			'autoplay': 'true'
		});
		// console.log( index + ": " + $( this ).text() );
	});
	//////////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////////// popups
	
	
////////////////////////////////////////////////////////////// menu_hovers
if ($(".hova_class").length) {
	//////////////////////////////////////////////////////////////
	jQuery('.hova_class').hover(function() { 
		var _target = jQuery(this).attr('data-hover-target');
		var _imgsrc = jQuery(this).attr('data-hover-url');
		var _mlink = jQuery(this).attr('href');
		//console.log( _img );
		jQuery('#'+_target).css("background-image", "url("+_imgsrc+")"); 
		jQuery('#'+_target).css("cursor", "pointer"); 
		jQuery('#'+_target+' .txt').html("View Gallery &raquo;"); 
		// clears onclick then sets click using jQuery
		jQuery('#'+_target).attr('onclick', '').click(function() { window.location.href=_mlink;});
	}); 
	//////////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////////// menu_hovers

	




////////////////////////////////////////////////////////////// Masonry




if ($(".masonry_area").length) {



	var $masonry_footer = $('.masonry_area');
	 // init Isotope
		$masonry_footer.each(function(){
            process_masonry(this);
		}); // each
		// layout Masonry after each image loads
		
		
		$(window).resize(function () { 
            $masonry_footer.each(function(){
                process_masonry(this);
            }); // each
		});
        
        
        function process_masonry(element) {
            var $masonry_footer = $(element);
                
            var mobile_cutoff = 426;
            if (typeof  $masonry_footer.data('mobile-cutoff') !== 'undefined') {mobile_cutoff = $masonry_footer.data('mobile-cutoff');}
            var window_width = $(window).innerWidth()
            //console.log(window_width);
        
        // if there is already masonry data, then...
        if ( $masonry_footer.data('isotope') ) {
        
                if (window_width >= mobile_cutoff) {
                    $masonry_footer.isotope('layout'); 
                    //console.log("relayout")
                } else {
                     //console.log("destroy")
                    // https://stackoverflow.com/questions/6021692/how-to-toggle-between-isotopes-layout-modes
                     //$masonry_footer.isotope('destroy'); //could destory and recreate again... ugh...
                    // process_masonry(this);
                    // note the disabler: .footer_wrap .masonry_area .widget
                }
        } else {
        // create it then...
        
        if (window_width >= mobile_cutoff) {
                
                var layoutMode = $masonry_footer.data('layout-mode'),
                columnWidth = Number($masonry_footer.data('column-width')),
                rowHeight = $masonry_footer.data('row-height'),
                percentPosition = $masonry_footer.data('percent-position');
                
                if(columnWidth == 0) { 
                    console.log(".grid-sizer used");
                    columnWidth = ".grid-sizer";
                }
                //http://codepen.io/desandro/pen/ClgeH
                $masonry_footer.isotope({
                          itemSelector: '.widget',
                          layoutMode: layoutMode,
                          masonry: { 
                            columnWidth: columnWidth 
                            },
                          cellsByRow: {
                            columnWidth: columnWidth, // (columnWidth*100),
                            rowHeight: rowHeight, //(columnWidth*100)
                          },
                          masonryHorizontal: {
                            rowHeight: rowHeight,
                            columnWidth: columnWidth, // (columnWidth*100),
                          },
                          cellsByColumn: {
                            columnWidth: columnWidth, //$masonry_footer.width() / columnWidth,
                            rowHeight: rowHeight
                          },
                          isResizable: true,
                          percentPosition: false,
                          animate: true
                        });
                //http://isotope.metafizzy.co/v1/demos/fluid-responsive.html
                $masonry_footer.imagesLoaded().progress(function(){ 
                    $masonry_footer.isotope('layout'); 
                });
                
            } // end mobile
            
        
        } // end if exists check
        
                
        } // end function
                
		
} //length
////////////////////////////////////////////////////////////// Masonry



////////////////////////////////////////////////////////////// Masonry
if ($("#scroll_to_top").length) {
// ===== Scroll to Top ==== 
$(window).scroll(function() { stt(); });
$(window).load(function() { stt(); });
$(window).resize(function(event) {stt();});
function stt() {
	if ($(window).scrollTop() >= 50) {        // If page is scrolled more than 50px
        $('#scroll_to_top').removeClass('inactive').addClass('active');    // Fade in the arrow
    } else {
        $('#scroll_to_top').removeClass('active').addClass('inactive');   // Else fade out the arrow
    }
}
$('#scroll_to_top').click(function() {      // When arrow is clicked
    $('body,html').animate({
        scrollTop : 0                       // Scroll to top of body
    }, 500);
});} //length
////////////////////////////////////////////////////////////// Scroll to Top


///////////////////////////////////////////////////////////////////// 
}); // END JQ
