$(document).ready(function(){
// Each Container
$('.flip-container').each(function(i,flipper) {
// Variables
var vid = $(flipper).find('video').get(0),
mask = $(flipper).find('.mask');
// Modal Button
$(flipper).find('.button-modal').click(function(e){
e.preventDefault();
var modal = $(this).closest('section').next();
modal.show();
if(Modernizr.mq('(max-width: 640px)')) {
//$("html, body").animate({ scrollTop: modal.offset().top }, "fast");
modal.closest('.flip-container').addClass('turn');
checkModal($(flipper));
setTimeout(function() {}, 1000);
}
mask.show();
});
// on load functions
checkVideo(vid);
// check on window resize
$(window).on('throttledresize',function() {
checkVideo(vid);
checkModal($(flipper));
});
}); // each container
// Check Video
function checkVideo(vid) {
if(Modernizr.mq('(max-width: 640px)')) {
vid.pause();
} else {
vid.play();
}
}
function setSectionStillImage() {
// get img src
var src,
imgMarkup;
if(Modernizr.mq('(max-width: 640px)')) {
imgMarkup = $('.section-still-image.mobile').html();
src = $('.section-still-image.mobile').attr('data-src');
if(imgMarkup == '' || imgMarkup == undefined) {
$('.section-still-image').html('');
$('.section-still-image.mobile').html('');
}
} else {
imgMarkup = $('.section-still-image.desktop').html();
src = $('.section-still-image.desktop').attr('data-src');
if(imgMarkup == '' || imgMarkup == undefined) {
$('.section-still-image').html('');
$('.section-still-image.desktop').html('');
}
}
}
// Close All Modals
function closeModals() {
$('.modal-wrapper').hide();
$('.modal-wrapper').closest('.flip-container').removeClass('turn');
$('.front, .back, .flip-container').removeAttr('style');
$('.mask').hide();
}
// Check Modal
function checkModal(flipper) {
if(Modernizr.mq('(max-width: 640px)')) {
if(flipper.hasClass('turn')) {
var backHeight = flipper.find('.back .modal').outerHeight();
var frontHeight = flipper.find('.front').outerHeight();
var flipHeight;
if(backHeight < frontHeight) {
flipHeight = backHeight;
} else {
flipHeight = frontHeight;
}
flipper.find('.front,.back').css({'height':flipHeight,'width':'100%'});
flipper.css({'height':flipHeight,'width':'100%'});
} else {
closeModals();
}
} else {
if(flipper.hasClass('turn')) {
closeModals();
}
}
} // checkModal()
// Buttons
$('.button,.nav-button').not('.button-modal').click(function(e){
console.log('click');
var link = $(this).attr('href');
if(link.charAt(0) == '#' && link.length > 1) {
e.preventDefault();
setTimeout(function() {
$("html, body").animate({ scrollTop: $(link).offset().top }, "slow");
}, 200);
closeModals();
}
});
$('.button').not('.button-modal').click(function(e){
var href = $(this).attr('href');
});
// Close Modal Button
$('.close-modal').click(function(e) {
e.preventDefault();
closeModals();
});
// Escape
$(document).keyup(function(e) {
if (e.keyCode == 27) {
closeModals();
}
});
// FAQ
$('.faq-question').click(function(){
$(this).toggleClass('active');
$(this).parent().find('.faq-answer').toggleClass('expand');
});
});