jQuery.noConflict();
(function( $ ) {

	var upcomingHeighter = function() {
		if ( $('.event').length ){
			var blockHeight = $('.event').closest('.row').height(),
				leftColumnHeight = 0,
				rightColumnHeight = 0;

			$('.event').height('');

			$('.event').each(function() {
				if ( $(this).hasClass('closest') ) {
					leftColumnHeight = $(this).outerHeight();
				} else {
					rightColumnHeight = rightColumnHeight + $(this).outerHeight();
				}
				return rightColumnHeight, leftColumnHeight;
			});

			var iCount = $('.event').not('.closest').length;

			if ( leftColumnHeight > (rightColumnHeight+10) ) {
				$('.event').not('.closest').outerHeight( (leftColumnHeight-(10*(iCount-1)))/iCount );
			} else {
				$('.event.closest').outerHeight(rightColumnHeight+(10*(iCount-1)));
			}
		}
	};
	
	$(document).ready(function(){


		if( $('.answer-survey ').length >0 ){
		$('.answer-survey .btn-primary').removeClass('btn-primary').addClass('btn btn-red');
			$('.control-label').each(function(){
				var h = $(this).html();
				$(this).html( '<h3>'+h+'</h3>');
			})
			$('label').each(function() {
			  if( $(this).find('input').length ){
			    var inputId = $(this).find('input').attr('id');
			    $(this).attr('for', inputId).find('input').insertBefore(this);
			  }
			});
		}
		$('footer .menu').addClass('footer-links');
		$('.blog-witget ul').addClass('side-links');
		$('.fill-screen-height').outerHeight( $(window).height() );

		$('.main-menu>li').hover(function() {
			$(this).find('ul.sub-menu').stop().slideToggle();
		}, function() {
			$(this).find('ul.sub-menu').stop().slideToggle();
		});

		if( $(window).scrollTop() > $(window).height() ){
			$('.main-nav').addClass('sticky');
		} else {
			$('.main-nav').removeClass('sticky');
		};

		$('.panel-toggle').on('click', function() {
			var target = $(this).attr('href');

			if( $(this).hasClass('slide') ){
				$(target).stop().slideToggle();
			} else {
				$(target).stop().fadeToggle();
			}
			$(this).toggleClass('panel-opened');

			return false;
		});

		upcomingHeighter();

		$('body, body.subpage').css('padding-top' ,$('.main-nav').outerHeight() +'px');


		if( $('.gallery-tile').length >0 ){ 
			lightbox.option({
				'fitImagesInViewport' : false,
				'maxWidth' : '90%',
				'alwaysShowNavOnTouchDevices' : true
			});
		}

		if ( $('.ammenity-content').length ) {
			$(document).on('click','.ammenity-toggle', function() {
				var targetContent = $(this).data('target');
				if ( !$(targetContent).hasClass('show-full') ){
					$(targetContent).addClass('show-full');
					$(this).text('Read Less').blur();
				} else {
					$(targetContent).removeClass('show-full');
					$(this).text('Read More').blur();
				}
			});
		}
	});
	
	$(window).resize(function(){
		$('.fill-screen-height').outerHeight( $(window).height() );

		upcomingHeighter();
	});

	$(window).scroll(function(){
		if( $(window).scrollTop() > $(window).height() ){
			$('.main-nav').addClass('sticky');
		} else {
			$('.main-nav').removeClass('sticky');
		}
	});
	
	$(window).load(function(){
		$('body').css('padding-top', $('.main-nav').outerHeight() +'px');

		if( $('.announcement-top').length >0 ){
			var top = $('.announcement-top').offset().top;
			$('html, body').animate({scrollTop: top-20-$('.always-sticky').height() }, 500);
		}
	});
	
})(jQuery);