/*-----------------------------------------------------------*/
// Theme Scripts
/*-----------------------------------------------------------*/
//add Bootstrap styles to hard-to-reach WordPress places
jQuery(document).ready(function() {
	//comment form fields
	jQuery('#commentform').find('input[type="text"], textarea').addClass('form-control');
	//submit comment button
	jQuery('#comments').find('input[type="submit"]').addClass('btn btn-default');
	//edit post link
	jQuery('a.post-edit-link').addClass('btn btn-default btn-xs');
});
//scroll menu
jQuery(document).ready(function() {
	var scrollMenu = jQuery('#scroll-menu');
	var headerComponent = jQuery('.component.header');
	if (headerComponent.length > 0) {
		headerHeight = headerComponent.outerHeight();
	} else {
		headerHeight = 250;
	}
	jQuery(window).on('scroll', function() {
		var scrollTop = jQuery(window).scrollTop();
		if (scrollTop > headerHeight) {
			if (Modernizr.csstransitions && Modernizr.csstransforms) {
				scrollMenu.addClass('in');
			} else {
				scrollMenu.stop(true, false).fadeIn(200);
			}
		} else {
			if (Modernizr.csstransitions && Modernizr.csstransforms) {
				scrollMenu.removeClass('in');
			} else {
				scrollMenu.stop(true, false).fadeOut(200);
			}
		}
	});
});
//deep linking
jQuery(window).load(function() {
	var targetID = window.location.hash
	var targetTabTrigger = jQuery('a[data-toggle="tab"][href="'+ targetID +'"]');
	var targetModalTrigger = jQuery('a[data-toggle="modal"][href="'+ targetID +'"]');
	if (targetTabTrigger.length > 0) {
		if (jQuery('body').hasClass('admin-bar')) {
			var offset = targetTabTrigger.offset().top - 132;
		} else {
			var offset = targetTabTrigger.offset().top - 100;
		}
		jQuery(window).scrollTop(offset);
		targetTabTrigger.trigger('click');
	} else if (targetModalTrigger.length > 0) {
		targetModalTrigger.first().trigger('click');
	} else if (targetID != '') {
		targetID = targetID == '#home-menus' ? '#menus' : targetID;
		var target = jQuery(targetID);
		if (target.length > 0 && jQuery('#scroll-menu').length > 0 && jQuery('#scroll-menu').is(':visible')) {
			if (jQuery('body').hasClass('admin-bar')) {
				var offset = target.offset().top - (jQuery('#scroll-menu').outerHeight()) - 32;
			} else {
				var offset = target.offset().top - (jQuery('#scroll-menu').outerHeight());
			}
			jQuery(window).scrollTop(offset);
		}
	}
});
//scroll to anchor
jQuery(document).ready(function() {
	jQuery('a[href*="#"]:not([href="#"]):not([data-toggle])').on('click', function(event) {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = jQuery(this.hash);
			target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
			if (target.length > 0 && jQuery('#scroll-menu').length > 0 && jQuery('#scroll-menu').is(':visible')) {
				if (jQuery('body').hasClass('admin-bar')) {
					var offset = target.offset().top - (jQuery('#scroll-menu').outerHeight()) - 32;
				} else {
					var offset = target.offset().top - (jQuery('#scroll-menu').outerHeight());
				}
				jQuery('html, body').animate({
					scrollTop: offset
				}, 1000);
				return false;
			}
		}
	});
});
/**
 * Text Slider
 */
jQuery(window).load(function() {
	var textSliders = jQuery('.text-slider-layout');
	textSliders.each(function() {
		var textSlider = jQuery(this);
		var textSliderID = textSlider.attr('data-slider-id');
		var textSliderControls = textSlider.attr('data-controls');
		var textSliderControlNav = true;
		var textSliderDirectionNav = false;
		var textSliderSlideshow = textSlider.attr('data-slideshow');
		if (textSliderSlideshow !== undefined) {
			textSliderSlideshow = true;
		} else {
			textSliderSlideshow = false;
		}
		switch(textSliderControls) {
			case 'paging':
				textSliderControlNav = true;
				textSliderDirectionNav = false;
				break;
			case 'direction':
				textSliderControlNav = false;
				textSliderDirectionNav = true;
				break;
			case 'both':
				textSliderControlNav = true;
				textSliderDirectionNav = true;
				break;
			case 'none':
				textSliderControlNav = false;
				textSliderDirectionNav = false;
				break;
		}
		//init slider
		textSlider.flexslider({
			animation: 'fade',
			animationLoop: true,
			multipleKeyboard: true,
			slideshow: textSliderSlideshow,
			controlsContainer: '.controls-'+ textSliderID,
			directionNav: textSliderDirectionNav,
			controlNav: textSliderControlNav,
		});
	});
});
/**
* Open table widget
*/
jQuery(document).ready(function() {
	setupDatepickers();
});
function setupDatepickers(){
	//date pickers
	var now = new Date();
	var currentDate = now.getDate();
	if (currentDate < 10) { currentDate = '0' + currentDate; }
	var currentMonth = now.getMonth()+1;
	if (currentMonth < 10) { currentMonth = '0' + currentMonth; }
	var today = currentDate + '/' + currentMonth + '/' + now.getFullYear();
	jQuery('.openTableForm').each(function() {
		var bookingDate = jQuery(this).find('.bs-datepicker[name="startDate"]');
		bookingDate.val(today);
		bookingDate.datepicker({
			format: 'dd/mm/yyyy',
			startDate: now,
			autoclose: true
		}).data('datepicker');
	});
	//mobile datepickers
	var mobileStartDate = moment();
	mobileBookingFieldString = moment(mobileStartDate).format('DD/MM/YYYY');
	var mobileBookingForm = jQuery('.openTableForm');
	mobileBookingForm.each(function() {
		var currentForm = jQuery(this);
		var bookingField = currentForm.find('.mobile_feedFormfieldCalendar[type="date"]');
		var bookingDate = currentForm.find('.bs-datepicker[name="startDate"]');
		bookingField.val(mobileBookingFieldString);
		bookingField.on('change', function() {
			var newBookingDateVal = jQuery(this).val();
			var newBookingDate = moment(newBookingDateVal).format('DD/MM/YYYY');
			bookingDate.val(newBookingDate);
		});
	});
}
/**
 * Notifications
 */
//Notifications - Title & CTA layout
jQuery(document).ready(function() {
	notificationBars = jQuery('.ad-layout-notifications.ob_bar');
	notificationBars.each(function() {
		var notification = jQuery(this);
		notification.closest('.col-sm-12').css('min-height','0px');
		var notificationsClose = notification.find('.notifications-bar-close');
		notificationsClose.on('click', function(event) {
			event.preventDefault();
			notification.toggleClass('putaway');
			//setTimeout(function() {
				//notification.remove();
			//}, 310);
			var dismissID = jQuery(this).parent().attr('data-notification-id');
			if (dismissID) {
				document.cookie = 'notification'+dismissID+'=closed; path=/';
			}
		});
		//ie8 fix
		if (jQuery('html').hasClass('lt-ie9')) {
			notification.find('.ad-layout-notification > a').each(function() {
				jQuery(this).after('');
			});
		}
		var notificationsSliders = jQuery(notification).find('.flexslider');
		notificationsSliders.each(function() {
			var notificationsSlider = jQuery(this);
			var notificationsSliderID = jQuery(this).attr('data-slider-id');
			var dismissID = jQuery(this).parent().attr('data-notification-id');
			notificationsSlider.flexslider({
				animation: 'fade',
				slideshow: true,
				multipleKeyboard: true,
				pauseOnAction: false,
				controlsContainer: '.controls-'+notificationsSliderID,
				controlNav: false,
				start:function(slider) {
					if (getCookie('notification'+dismissID) != '') {
						slider.closest('.ad-layout-notifications').remove();
					} else {
						slider.closest('.ad-layout-notifications').removeClass('dismissed');
					}
				}
			});
		});
	});
	//track notification clicks
	jQuery('.ad-layout-notifications.ob_bar .ad-layout-notification a').on('click',function(event){
		var post_id = jQuery(this).parent().data('notification-id');
		notificationClickCount(post_id);
	});
});
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i 300) {
			backToTop.addClass('in');
		} else {
			backToTop.removeClass('in');
		}
	});
/*
	if (Modernizr.touch) {
		var lastY;
		jQuery(document).bind('touchmove', function (e){
			var currentY = e.originalEvent.touches[0].clientY;
			if(currentY > lastY){
				backToTop.addClass('in');
			} else if(currentY < lastY){
				backToTop.removeClass('in');
			}
			lastY = currentY;
		});
	}
*/
	backToTop.on('click', function(event) {
		event.preventDefault();
		jQuery('html, body').animate({
			scrollTop : 0
		}, 500);
	});;
});
/* Contact Form 7 show recaptcha */
jQuery(document).ready(function() {
	var contactForm = jQuery('.ad-layout-contact-form');
	contactForm.find('input, textarea').on('click', function () {
		contactForm.find('.contact-recaptcha').addClass('active');
	});
});
/**
 * Google Analytics Event Tracking
 */
jQuery(document).ready(function() {
	//newsletter signup
	jQuery('form[name="mc-embedded-subscribe-form"]').on('submit', function() {
		//send event to GA tracking
		if (jQuery(this).closest('.notifications-popover').length > 0) {
			ga('send','event','Forms','Submit','Popover Newsletter Signup');
		} else {
			ga('send','event','Forms','Submit','Newsletter Signup');
		}
	});
	//reservations
	jQuery('#OT_searchWrapperAll').on('submit', 'form', function() {
		//send event to GA tracking
		ga('send','event','Forms','Submit','Reservations');
	});
	//reservations
	jQuery('.fsnOpenTableForm').on('submit', function() {
		//send event to GA tracking
		ga('send','event','Forms','Submit','Reservations');
	});
	//contact form submissions
	document.addEventListener( 'wpcf7mailsent', function(e) {
		ga('send','event','Forms','Submit','Contact Form Submission');
	}, false );
});
//IE8 placeholders
jQuery(document).ready(function() {
	if (!Modernizr.placeholder) {
		/* HTML5 Placeholder jQuery Plugin - v2.1.1
		 * Copyright (c)2015 Mathias Bynens
		 * 2015-02-19
		 */
		!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){function b(b){var c={},d=/^jQuery\d+$/;return a.each(b.attributes,function(a,b){b.specified&&!d.test(b.name)&&(c[b.name]=b.value)}),c}function c(b,c){var d=this,f=a(d);if(d.value==f.attr("placeholder")&&f.hasClass(m.customClass))if(f.data("placeholder-password")){if(f=f.hide().nextAll('input[type="password"]:first').show().attr("id",f.removeAttr("id").data("placeholder-id")),b===!0)return f[0].value=c;f.focus()}else d.value="",f.removeClass(m.customClass),d==e()&&d.select()}function d(){var d,e=this,f=a(e),g=this.id;if(""===e.value){if("password"===e.type){if(!f.data("placeholder-textinput")){try{d=f.clone().attr({type:"text"})}catch(h){d=a("").attr(a.extend(b(this),{type:"text"}))}d.removeAttr("name").data({"placeholder-password":f,"placeholder-id":g}).bind("focus.placeholder",c),f.data({"placeholder-textinput":d,"placeholder-id":g}).before(d)}f=f.removeAttr("id").hide().prevAll('input[type="text"]:first').attr("id",g).show()}f.addClass(m.customClass),f[0].value=f.attr("placeholder")}else f.removeClass(m.customClass)}function e(){try{return document.activeElement}catch(a){}}var f,g,h="[object OperaMini]"==Object.prototype.toString.call(window.operamini),i="placeholder"in document.createElement("input")&&!h,j="placeholder"in document.createElement("textarea")&&!h,k=a.valHooks,l=a.propHooks;if(i&&j)g=a.fn.placeholder=function(){return this},g.input=g.textarea=!0;else{var m={};g=a.fn.placeholder=function(b){var e={customClass:"placeholder"};m=a.extend({},e,b);var f=this;return f.filter((i?"textarea":":input")+"[placeholder]").not("."+m.customClass).bind({"focus.placeholder":c,"blur.placeholder":d}).data("placeholder-enabled",!0).trigger("blur.placeholder"),f},g.input=i,g.textarea=j,f={get:function(b){var c=a(b),d=c.data("placeholder-password");return d?d[0].value:c.data("placeholder-enabled")&&c.hasClass(m.customClass)?"":b.value},set:function(b,f){var g=a(b),h=g.data("placeholder-password");return h?h[0].value=f:g.data("placeholder-enabled")?(""===f?(b.value=f,b!=e()&&d.call(b)):g.hasClass(m.customClass)?c.call(b,!0,f)||(b.value=f):b.value=f,g):b.value=f}},i||(k.input=f,l.value=f),j||(k.textarea=f,l.value=f),a(function(){a(document).delegate("form","submit.placeholder",function(){var b=a("."+m.customClass,this).each(c);setTimeout(function(){b.each(d)},10)})}),a(window).bind("beforeunload.placeholder",function(){a("."+m.customClass).each(function(){this.value=""})})}});
		//# sourceMappingURL=jquery.placeholder.min.js.map
		jQuery('input, textarea').placeholder();
	}
});