jQuery(document).ready(function($){
"use strict";
var window_width, window_height, scroll_top;
var adminbar=$('#wpadminbar');
var adminbar_height=0;
var header=$('#cshero-header');
var header_top=0;
var is_entry_like=null;
var scroll_status='';
$(".tnp-email").attr("placeholder", "Your email...");
function initWow(){
var wow=new WOW( { mobile: false, });
wow.init();
};
$(window).on('load', function(){
if($('.wow').length){
initWow();
};
scroll_top=$(window).scrollTop();
window_width=$(window).width();
window_height=$(window).height();
adminbar_height=adminbar.length > 0 ? adminbar.outerHeight(true):0 ;
header_top=header.length > 0 ? header.offset().top - adminbar_height:0 ;
cms_lightbox_popup();
cms_stiky_menu();
setTimeout(function(){adjust_row_width();},2000);
$('[data-toggle="tooltip"]').tooltip();
cms_service_carousel();
$('p').each(function(){
var $this=$(this);
if($this.html().replace(/\s|&nbsp;/g, '').length==0)
$this.remove();
});
});
if($('.ef3-back-to-top').length){
$('.ef3-back-to-top').on('click', function(event){
event.stopPropagation();
$('html, body').stop().animate({
scrollTop: 0
}, 1500, 'swing');
});
$(window).on('scroll', function(){
if($(window).scrollTop() > 480){
$('.ef3-back-to-top').addClass('active');
}else{
$('.ef3-back-to-top').removeClass('active');
}});
}
window.onbeforeunload=function(){
}
$(window).on('resize', function(event, ui){
window_width=$(event.target).width();
window_height=$(window).height();
scroll_top=$(window).scrollTop();
cms_stiky_menu();
adjust_row_width();
});
$(window).on('scroll', function(){
scroll_top=$(window).scrollTop();
cms_stiky_menu();
});
function cms_stiky_menu(){
if(header.hasClass('sticky-desktop')&&(header_top + 1) < scroll_top&&window_width > 1199){
header.addClass('header-fixed');
$('body').addClass('hd-fixed');
$('.sticky-desktop').addClass('fadeInDown');
$('.sticky-desktop').addClass('animated');
}else{
header.removeClass('header-fixed');
$('body').removeClass('hd-fixed');
$('.sticky-desktop').removeClass('fadeInDown');
}}
function cms_service_carousel(){
$('.cms-service-carousel').each(function(){
$(this).owlCarousel({
items:1,
autoplay:false,
responsiveClass:true,
loop:false,
nav: false,
dots: true,
margin:0,
dotsData: true,
});
});
}
function cms_lightbox_popup(){
$('.cms-video-popup').magnificPopup({
type: 'iframe',
mainClass: 'mfp-fade',
removalDelay: 160,
preloader: false,
fixedContentPos: false
});
$('.cms-gallerys').magnificPopup({
delegate: '.magic-popups',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-3d-unfold',
removalDelay: 500,
callbacks: {
beforeOpen: function(){
this.st.image.markup=this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
}},
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0,1]
},
image: {
tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
}});
}
$('.post-gallery-carousel').each(function(){
$(this).owlCarousel({
items:3,
autoplay:false,
responsiveClass:true,
loop:false,
nav: true,
dots: false,
margin: 40,
responsive:{
0: {
items:2,
nav: false,
},
480: {
items:3,
nav: true,
},
992:{
items:2,
nav: true,
},
1200:{
items:3,
nav: true,
}}
});
});
$('.page-title-carousel').each(function(){
$(this).owlCarousel({
items:1,
autoplay:false,
responsiveClass:true,
loop:true,
nav: true,
dots: false,
margin: 0,
});
$(this).on('changed.owl.carousel', updateCurrentTotal);
});
var status=$(".beside_slider");
function updateCurrentTotal(e){
updateResult(".total", e.item.count);
updateResult(".current", e.relatedTarget.relative(e.item.index) + 1);
}
function updateResult(pos,value){
status.find(pos).text(value);
}
$('body').on('click', '.ef3-back-to-top', function (){
$('body, html').animate({scrollTop:0}, '1000');
})
$('.entry-like').on('click', function (event){
var bt_like=$(this);
is_entry_like=$(this);
var post_id=bt_like.attr('data-id');
if(post_id!=undefined&&post_id!=''){
$.post(ajax_data.url, {
'action':'cms_post_like',
'id':post_id
}, function(response){
if(response!=''){
bt_like.find('i').attr('class', 'fa fa-heart')
bt_like.find('span').html(response);
}});
}
event.preventDefault();
});
var $sideHeader=$('.page_header_side');
if($sideHeader.length){
var $body=$('body');
$('.toggle_menu_side').on('click', function(){
if($(this).hasClass('header-slide')){
$sideHeader.toggleClass('active-slide-side-header');
}else{
if($(this).parent().hasClass('header_side_right')){
$body.toggleClass('active-side-header slide-right');
}else{
$body.toggleClass('active-side-header');
}}
});
$('body').on('click', function(e){
if(!($(e.target).closest('.page_header_side').length)&&!($sideHeader.hasClass('page_header_side_sticked'))){
$sideHeader.removeClass('active-slide-side-header');
$body.removeClass('active-side-header slide-right');
}});
}
if(typeof(one_page_options)!="undefined"){
one_page_options.speed=parseInt(one_page_options.speed);
$('#site-navigation').singlePageNav(one_page_options);
}
$(document).on('click','.cms-projects .menu_filter [data-group]',function (e){
e.preventDefault();
var $this=$(this),current_area=$this.closest('.cms-projects'),target=$this.attr('data-group');
current_area.find('.menu_filter [data-group]').removeClass('active');
$this.addClass('active');
current_area.find('.menu_content [data-menu]').removeClass('active');
current_area.find('.menu_content [data-menu="'+target+'"]').addClass('active');
});
function adjust_row_width(){
var window_width=$(window).width();
var row_full_width=$('.row.stretch-row').parent('.cms-content').width();
var halp_width=(window_width - (row_full_width + 30)) / 2;
$('.row.stretch-row').css({
'position': 'relative',
'left': -halp_width,
'box-sizing': 'border-box',
'width': window_width,
'padding-left': halp_width,
'padding-right': halp_width
});
}
$('.post-gallery .cms-carousel-item img').on('click', function(){
$('.post-gallery .first-gallery img').attr('src',$(this).attr('src'));
$('.post-gallery .first-gallery a').attr('href',$(this).attr('data-src'));
});
});