/**
* isMobile
* responsiveMenu
* simpleSlider
* imagesSingleSlider
* popupGallery
* headerFixed
* progressBar
* parallax
* flatCountdown
* memberSlider
* blogpostSlider
* blogSlider
* gallery_project
* ajaxContactForm
* alertBox
* flatTabs
* flatCounter
* flatTestimonial
* flatBrands
* flatAccordion
* flatFilterPrice
* goTop
* googleMap
* flatSearch
* onepage_nav
* detectViewport
* removePreloader
*/
;(function($) {
'use strict'
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
var responsiveMenu = function() {
var menuType = 'desktop';
$(window).on('load resize', function() {
var currMenuType = 'desktop';
if ( matchMedia( 'only screen and (max-width: 991px)' ).matches ) {
currMenuType = 'mobile';
}
if ( currMenuType !== menuType ) {
menuType = currMenuType;
if ( currMenuType === 'mobile' ) {
var $mobileMenu = $('#mainnav').attr('id', 'mainnav-mobi').hide();
var hasChildMenu = $('#mainnav-mobi').find('li:has(ul)');
$('#header').after($mobileMenu);
hasChildMenu.children('ul').hide();
hasChildMenu.children('a').after('');
$('.btn-menu').removeClass('active');
} else {
var $desktopMenu = $('#mainnav-mobi').attr('id', 'mainnav').removeAttr('style');
$desktopMenu.find('.submenu').removeAttr('style');
$('#header').find('.nav-wrap').append($desktopMenu);
$('.btn-submenu').remove();
}
}
});
$('.btn-menu').on('click', function() {
$('#mainnav-mobi').slideToggle(300);
$(this).toggleClass('active');
});
$(document).on('click', '#mainnav-mobi li .btn-submenu', function(e) {
$(this).toggleClass('active').next('ul').slideToggle(300);
e.stopImmediatePropagation()
});
}
var simpleSlider = function() {
if ( $().flexslider ) {
$('.flexslider').flexslider({
animation : "slide",
direction : "horizontal", // vertical
pauseOnHover : true,
useCSS : false,
pausePlay : false,
easing : "swing",
animationSpeed : 500,
slideshowSpeed : 5000,
controlNav : true,
directionNav : true,
slideshow : true,
prevText : '',
nextText : '',
smoothHeight : true
}); // flexslider
// }); // simple-slider
}
};
var imagesSingleSlider = function() {
if ( $().flexslider ) {
$('.images-single-flexslider').flexslider({
animation : "fade",
direction : "horizontal", // vertical
pauseOnHover : true,
useCSS : false,
pausePlay : false,
easing : "swing",
animationSpeed : 500,
slideshowSpeed : 5000,
controlNav : false,
directionNav : true,
slideshow : true,
prevText : '',
nextText : '',
smoothHeight : true
}); // flexslider
// }); // simple-slider
}
};
var popupGallery = function () {
$('.popup').each(function() {
if ( $('a').hasClass('popup-gallery') ) {
$(".popup-gallery").magnificPopup({
type: "image",
tLoading: "Loading image #%curr%...",
removalDelay: 600,
mainClass: "my-mfp-slide-bottom",
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [ 0, 1 ]
},
image: {
tError: 'The image #%curr% could not be loaded.'
}
});
}
});
}
var headerFixed = function() {
if ( $('body').hasClass('header-sticky') ) {
$('#header').sticky();
}
if ( $('body').hasClass('header-sticky-v2') ) {
$('#flat-site-navigator').sticky().css({"z-index": 9999999});
}
}
var progressBar = function() {
$('.progress-bar').on('on-appear', function() {
$(this).each(function() {
var percent = $(this).data('percent');
$(this).find('.progress-animate').animate({
"width": percent + '%'
},3000);
$(this).parent('.roll-progress').find('.perc').addClass('show').animate({
"width": percent + '%'
},3000);
});
});
};
var parallax = function() {
if ( $().parallax && isMobile.any() == null ) {
$('.parallax1').parallax("50%", -0.1);
$('.parallax2').parallax("50%", 0.4);
$('.parallax3').parallax("50%", 0.5);
$('.parallax4').parallax("50%", 0.5);
$('.parallax5').parallax("50%", 0.5);
$('.parallax6').parallax("50%", 0.5);
$('.parallax7').parallax("50%", 0.5);
}
};
var flatCountdown = function() {
var anycar_style = function(data) {
$(this.el).html(
"
" +
"
" + this.leadingZeros(data.days, 2) + "
" +
"
Days
" +
"
" +
"" +
"
" + this.leadingZeros(data.hours, 2) + "
" +
"
Hours
" +
"
" +
"" +
"
" + this.leadingZeros(data.min, 2) + "
" +
"
Minutes
" +
"
" +
"" +
"
" + this.leadingZeros(data.sec, 2) + "
" +
"
Seconds
" +
"
");
}
$('.countdown').each(function() {
$(this).countdown({
date: $(this).attr('data-date'),
render: anycar_style
});
});
};
var memberSlider = function() {
$('.flat-row').each(function(){
if ( $().owlCarousel ) {
$(this).find('.member-carousel').owlCarousel({
loop: true,
margin: 30,
auto:true,
dots: false,
nav:true,
responsive:{
0:{
items: 1
},
480:{
items: 2
},
767:{
items: 2
},
991:{
items: 2
},
1200:{
items: 4
}
}
});
}
});
};
var blogpostSlider = function() {
$('.flat-row').each(function(){
if ( $().owlCarousel ) {
$(this).find('.post-carousel').owlCarousel({
loop: true,
margin: 0,
auto:true,
dots: false,
nav: false,
responsive:{
0:{
items:1
},
480:{
items:2
},
767:{
items:2
},
991:{
items:2
},
1200:{
items:3
}
}
});
}
});
};
var blogSlider = function() {
$('.flat-row').each(function(){
if ( $().owlCarousel ) {
$(this).find('.blog-carousel-slider').owlCarousel({
loop: true,
margin: 30,
auto:true,
dots: false,
nav:true,
responsive:{
0:{
items:1
},
480:{
items:2
},
767:{
items:2
},
991:{
items:2
},
1200:{
items:3
}
}
});
}
});
};
var gallery_project = function() {
if ( $().isotope ) {
var $container = $('.project-wrap');
$container.imagesLoaded(function(){
$container.isotope({
itemSelector: '.project-item',
transitionDuration: '1s'
});
});
};
};
var ajaxContactForm = function() {
$('#contactform').each(function() {
$(this).validate({
submitHandler: function( form ) {
var $form = $(form),
str = $form.serialize(),
loading = $('', { 'class': 'loading' });
$.ajax({
type: "POST",
url: $form.attr('action'),
data: str,
beforeSend: function () {
$form.find('.send-wrap').append(loading);
},
success: function( msg ) {
var result, cls;
if ( msg == 'Success' ) {
result = 'Email Sent Successfully. Thank you, Your application is accepted - we will contact you shortly';
cls = 'msg-success';
} else {
result = 'Error sending email.';
cls = 'msg-error';
}
$form.prepend(
$('', {
'class': 'flat-alert ' + cls,
'text' : result
}).append(
$('')
)
);
$form.find(':input').not('.submit').val('');
},
complete: function (xhr, status, error_thrown) {
$form.find('.loading').remove();
}
});
}
});
}); // each contactform
};
var alertBox = function() {
$(document).on('click', '.close', function(e) {
$(this).closest('.flat-alert').remove();
e.preventDefault();
})
}
var flatTabs = function () {
$('.flat-tabs').each(function() {
$(this).children('.content-tab').children().hide();
$(this).children('.content-tab').children().first().show();
$(this).find('.menu-tabs').children('li').on('click', function(e) {
var liActive = $(this).index(),
contentActive = $(this).siblings().removeClass('active').parents('.flat-tabs').children('.content-tab').children().eq(liActive);
contentActive.addClass('active').fadeIn('slow');
contentActive.siblings().removeClass('active');
$(this).addClass('active').parents('.flat-tabs').children('.content-tab').children().eq(liActive).siblings().hide();
e.preventDefault();
});
});
};
var flatCounter = function() {
$('.counter').on('on-appear', function() {
$(this).find('.numb-count').each(function() {
var to = parseInt( ($(this).attr('data-to')),10 ), speed = parseInt( ($(this).attr('data-speed')),10 );
if ( $().countTo ) {
$(this).countTo({
to: to,
speed: speed
});
}
});
});
};
var flatTestimonial = function() {
$('.flat-row').each(function() {
if ( $().owlCarousel ) {
$(this).find('.flat-testimonial-owl').owlCarousel({
loop: true,
margin: 30,
nav: true,
dots: false,
autoplay: true,
responsive:{
0:{
items: 1
},
767:{
items: 1
},
991:{
items: 1
},
1200: {
items: 1
}
}
});
}
});
};
var flatBrands = function() {
$('.flat-row').each(function() {
if ( $().owlCarousel ) {
$(this).find('.brands').owlCarousel({
loop: true,
margin: 30,
nav: false,
dots: false,
autoplay: true,
responsive:{
0:{
items: 1
},
480:{
items: 3
},
767:{
items: 3
},
991:{
items: 3
},
1200: {
items: 4
}
}
});
}
});
};
var flatAccordion = function() {
var args = {duration: 600};
$('.flat-toggle .toggle-title.active').siblings('.toggle-content').show();
$('.flat-toggle.enable .toggle-title').on('click', function() {
$(this).closest('.flat-toggle').find('.toggle-content').slideToggle(args);
$(this).toggleClass('active');
}); // toggle
$('.flat-accordion .toggle-title').on('click', function () {
if( !$(this).is('.active') ) {
$(this).closest('.flat-accordion').find('.toggle-title.active').toggleClass('active').next().slideToggle(args);
$(this).toggleClass('active');
$(this).next().slideToggle(args);
} else {
$(this).toggleClass('active');
$(this).next().slideToggle(args);
}
}); // accordion
};
var flatFilterPrice = function() {
if( $().slider ) {
$( ".price_slider" ).slider({
range: true,
min: 25,
max: 550,
values: [ 25, 550 ],
slide: function( event, ui ) {
$( ".price_label > input " ).val( "£" + ui.values[ 0 ] + " - £" + ui.values[ 1 ] );
}
});
$( ".price_label > input " ).val( "£" + $( ".price_slider" ).slider( "values", 0 ) +
" - £" + $( ".price_slider" ).slider( "values", 1 ) );
$( ".ui-slider-handle").append("");
}
};
var goTop = function() {
$(window).scroll(function() {
if ( $(this).scrollTop() > 800 ) {
$('.go-top').addClass('show');
} else {
$('.go-top').removeClass('show');
}
});
$('.go-top').on('click', function() {
$("html, body").animate({ scrollTop: 0 }, 1000 , 'easeInOutExpo');
return false;
});
};
var googleMap = function() {
if ( $().gmap3 ) {
$("#flat-map").gmap3({
map:{
options:{
zoom: 12,
mapTypeId: 'anycar_style',
mapTypeControlOptions: {
mapTypeIds: ['anycar_style', google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID]
},
scrollwheel: false
}
},
getlatlng:{
address: "66 Nicholson St Buffalo New York US",
callback: function(results) {
if ( !results ) return;
$(this).gmap3('get').setCenter(new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()));
$(this).gmap3({
marker:{
latLng:results[0].geometry.location,
options:{
icon: 'http://themesflat.com/html/anycar/images/icon/marker.png'
}
}
});
}
},
styledmaptype:{
id: "anycar_style",
options:{
name: "Anycar Map"
},
styles: [
{
"featureType": "landscape",
"stylers": [
{
"saturation": -100
},
{
"lightness": 65
},
{
"visibility": "on"
}
]
},
{
"featureType": "poi",
"stylers": [
{
"saturation": -100
},
{
"lightness": 51
},
{
"visibility": "simplified"
}
]
},
{
"featureType": "road.highway",
"stylers": [
{
"saturation": -100
},
{
"visibility": "simplified"
}
]
},
{
"featureType": "road.arterial",
"stylers": [
{
"saturation": -100
},
{
"lightness": 30
},
{
"visibility": "on"
}
]
},
{
"featureType": "road.local",
"stylers": [
{
"saturation": -100
},
{
"lightness": 40
},
{
"visibility": "on"
}
]
},
{
"featureType": "transit",
"stylers": [
{
"saturation": -100
},
{
"visibility": "simplified"
}
]
},
{
"featureType": "administrative.province",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "water",
"elementType": "labels",
"stylers": [
{
"visibility": "on"
},
{
"lightness": -25
},
{
"saturation": -100
}
]
},
{
"featureType": "water",
"elementType": "geometry",
"stylers": [
{
"hue": "#000000"
},
{
"lightness": -25
},
{
"saturation": -100
}
]
}
]
},
});
}
};
var flatSearch = function () {
$(document).on('click', function(e) {
var clickID = e.target.id;
if ( ( clickID != 's' ) ) {
$('.top-search').removeClass('show');
}
});
$('.search-box').on('click', function(event){
event.stopPropagation();
});
$('.search-form').on('click', function(event){
event.stopPropagation();
});
$('.search-box').on('click', function () {
if(!$('.top-search').hasClass( "show" ))
$('.top-search').addClass('show');
else
$('.top-search').removeClass('show');
});
}
var onepage_nav = function () {
$('.page-template-front-page .mainnav > ul > li > a').on('click',function() {
var anchor = $(this).attr('href').split('#')[1];
var largeScreen = matchMedia('only screen and (min-width: 992px)').matches;
var headerHeight = 0;
headerHeight = $('.header').height();
if ( anchor ) {
if ( $('#'+anchor).length > 0 ) {
if ( $('.header-sticky').length > 0 && largeScreen ) {
headerHeight = headerHeight;
} else {
headerHeight = 0;
}
var target = $('#'+anchor).offset().top - headerHeight;
$('html,body').animate({scrollTop: target}, 1000, 'easeInOutExpo');
}
}
return false;
})
$('.mainnav ul > li > a').on( 'click', function() {
$( this ).addClass('active').parent().siblings().children().removeClass('active');
});
}
var detectViewport = function() {
$('[data-waypoint-active="yes"]').waypoint(function() {
$(this).trigger('on-appear');
}, { offset: '90%', triggerOnce: true });
$(window).on('load', function() {
setTimeout(function() {
$.waypoints('refresh');
}, 100);
});
};
var removePreloader = function() {
$('.loading-overlay').fadeOut('slow',function () {
$(this).remove();
});
};
// Dom Ready
$(function() {
if ( matchMedia( 'only screen and (min-width: 991px)' ).matches ) {
headerFixed();
}
responsiveMenu();
simpleSlider();
imagesSingleSlider();
popupGallery();
progressBar();
flatTabs();
flatCounter();
flatTestimonial();
flatBrands();
flatAccordion();
flatFilterPrice();
memberSlider();
blogSlider();
blogpostSlider();
flatCountdown();
flatSearch();
onepage_nav();
parallax();
googleMap();
gallery_project();
detectViewport();
ajaxContactForm();
alertBox();
goTop();
removePreloader();
});
})(jQuery);