function viewport(){//get back size of device viewport: { width , height }
        var e = window , a = 'inner';
        if ( !( 'innerWidth' in window ) ){
            a = 'client';
            e = document.documentElement || document.body;
        }
        return { width : e[ a+'Width' ] , height : e[ a+'Height' ] }
}

function imageHeight() {
	if($('.jsMainImage').length && viewport().width >=930){
//		console.log('s');
		var image = $('.jsMainImage');
		var imageHeight = image.height();
		$('.recipeBlurb').height(imageHeight-41);
	}
}

function slideMenuToggleBackground(clickElem, elem) {
	$(clickElem).click(function(){	
		//var e = $('.topMenu, .mobileSearchFunction');
		//$(e).slideUp();
		//$('.opacityBg').removeClass('opacityBgActive');	

		$(elem).stop().slideToggle('fast');
		$(this).toggleClass('closed');
		$(this).toggleClass('open');		
		$('.opacityBg').toggleClass('opacityBgActive');	
	});	
}

$(document).ready(function(){
	
	if( viewport().width <= 930 ) {
		$('body').append('<div class="opacityBg"></div>');

		slideMenuToggleBackground('.jsMobileMenu','.topMenu');
		slideMenuToggleBackground('.mobileSearchIcon','.mobileSearchFunction');
	}
	// if( viewport().width > 946 ) {
	// 	if ( $('.spotlightListing').length ) {
	// 		var h = $('.info').outerHeight();
	// 		$('.spotlightListing img').height(h);
	// 	}
	// }

	$('input, textarea').placeholder();
	
	$('.bxslider').bxSlider({
	  controls: true,
	  pager: false
	});

	$('.gallery').each(function() { // the containers for all your galleries
	    $(this).magnificPopup({
	        delegate: 'a', // the selector for gallery item
	        type: 'image',
	        gallery: {enabled:true},
			image: {
            	titleSrc: 'title' 
            	// this tells the script which attribute has your caption
        	}
	    });
	});

	if( !$('body').hasClass('front') ) {$(this).addClass('otherPages');} //NOTE: Add this class into all other CMS pages other than homepage

	/*if( viewport().width >= 930 ) {
		$('.jsSpotlightsContainer .spotlightImageHeader:nth-child(3n)').css('margin-right','0');
	}*/

	imageHeight();
});

$(window).resize(function(){imageHeight();});

$(window).scroll(function (event) {
    var scroll = $(window).scrollTop();
	//console.log(scroll);
	
	if ( !$('body').hasClass('front') ) { //don't run on homepage
		if ( scroll === 0 ) {
			
			//console.log('at the top!');
			$('#header').removeClass('notAtTop').addClass('atTop');
			
		} else {
			//console.log('somewhere else!')
			$('#header').addClass('notAtTop').removeClass('atTop');
		}
	}
});