(function($) { 
"use strict"; 
// App Script
jQuery(document).ready(function($) {
	var ie = (function(){

	    var undef,
	        v = 3,
	        div = document.createElement('div'),
	        all = div.getElementsByTagName('i');
	    
	    while (
	        div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
	        all[0]
	    );
	   
	    return v > 4 ? v : undef;
	    
	}());

	if (ie == 9) {
		jQuery('body').addClass('ie_9');
	}
	oswald_portfolio_isotope();
	oswald_team_isotope();
	oswald_blog_list_slider();
	oswald_carousel_list();
	oswald_video_play_button();
	oswald_search();
	oswald_mobile_menu();
	oswald_menu_line();
	oswald_sticky_header ();
	oswald_burger_sidebar ();
	oswald_modal_login ();
	oswald_mega_menu();
	oswald_custom_color();
	oswald_flickr_widget ();
	oswald_widget_hover ();	
	oswald_portfolio_load_more_init();
	oswald_team_load_more_init();
	oswald_blog_isotope();
	oswald_blog_load_more_init();
	oswald_message_close();
	oswald_testimonials_list ();
	oswald_back_to_top();

	// WPD Counter
	oswald_initCounter();
	// Column Separators
	oswald_initRowseparator();
	// WPD Services Box
	oswald_services_box ();
	// WPD Video popup
	oswald_popup_video();
	// WPD Countdown
	oswald_countdown_module();
	// Blank Anchors
	jQuery('a[href="#"]').on('click', function(e) {
		e.preventDefault();
	});
});

jQuery(window).resize(function() {
	// WPD Services Box
	oswald_services_box ();
});

jQuery(window).load(function() {
	loginWithAjaxHandlers();
	resize_visual ();
	oswald_one_page_scroll();
});

function resize_visual () {
	if (jQuery('.vc_row-o-full-height').length && !jQuery('.container-full-width').length) {
		var w = window.innerWidth;
		var leftPosition = jQuery('.vc_row-o-full-height')[0].style.left;
		if (leftPosition.length) {
			var re = /\d+/i;
			var found = leftPosition.match(re);
			var found = parseInt(found[0], 10) + 9;
			jQuery('.vc_row-o-full-height')[0].style.width = w + "px";
			jQuery('.vc_row-o-full-height')[0].style.left = -found + "px";
		}		
	}
}
//back to top
function oswald_back_to_top(){
	var W_height = jQuery(window).height();
	var element = jQuery('#back_to_top');
	if (element.length) {
		element.on('click',function(){
			jQuery('body,html').animate({
				scrollTop: 0
			}, 500);
			return false;
		});		
		var show_back_to_top = function (){
			if (jQuery(document).scrollTop() < W_height) {
	        	element.removeClass('show');
	        }else{
	        	element.addClass('show');
	        }
		}
		show_back_to_top();
		jQuery(window).on('scroll',function() {
	        show_back_to_top();
	    });
	}	
}
// Blog
function oswald_blog_isotope(){
	jQuery('.wpd_blog_list_wrapper.blog_type1:not(.items1):not(.wpd_blog_list_wrapper--carousel) .wpd_blog_list').each(function(){
		var element = jQuery(this);
        var element_item;

		element.find('.post:not(.image_loaded)').each(function(){
			element_item = jQuery(this);
			element_item.find('img').imagesLoaded().always(function(instance ){
				jQuery(instance.elements).parents('.post').addClass('image_loaded');
			})
		})

		element.isotope({
            itemSelector: '.post',
            percentPosition: true,
            masonry: {
                columnWidth: '.post'
            }
        });

        element.imagesLoaded(function(){
            setTimeout(function(){
                element.isotope({
                    itemSelector: '.post',
                    percentPosition: true,
                    masonry: {
                        columnWidth: '.post',
                    }
                });
            },1000)
            
        });

	})
}

function oswald_blog_load_more_init (){
	var wpd_blog_list_wrapper = jQuery('.wpd_blog_list_wrapper');
	if (wpd_blog_list_wrapper.length) {
		wpd_blog_list_wrapper.each(function(){
			var element = jQuery(this);
			var loadMoreButton = element.find('.wpdaddy_blog_load_more');
			var blogContainer = element.find('.wpd_blog_list');
            var data_ajax_atts = wpd_blog_list_wrapper.attr('data-ajax-atts');
            var data_page_item = wpd_blog_list_wrapper.attr('data-page-item');
            data_page_item++;

            data_ajax_atts = jQuery.parseJSON(data_ajax_atts);

            loadMoreButton.on('click', function (e) {
                loadMoreButton.addClass('loading');
                e.preventDefault();
                e.stopPropagation(); 
            	var ajaxData = {
            		action: 'wpdaddy_get_blog_item_from_ajax',
                    data_ajax_atts: data_ajax_atts,
                    data_page_item: data_page_item++
            	};
            	jQuery.ajax({
                    type: 'POST',
                    data: ajaxData,
                    url: object_name.wpd_ajaxurl,
                    success: function (data) { 
                    	loadMoreButton.removeClass('loading');
                    	if (data != '') {
                    		var response = jQuery.parseJSON(data);
                        	var responseHtml = response.html;                        	
                        	var img_loader = imagesLoaded( blogContainer );
                        	img_loader.on( 'always', function (){ 
                                setTimeout(function() {
                                    blogContainer
                                    .append( jQuery(responseHtml) )
                                    .isotope( 'appended', jQuery(responseHtml) )
                                    .isotope('reloadItems');    
                                    blogContainer.find('article.post:not(.image_loaded)').each(function(){
                                    	jQuery(this).imagesLoaded().always(function(instance ){
											jQuery(instance.elements).addClass('image_loaded');
										}) 
                                    })  
                                    setTimeout(function(){
                                        blogContainer.isotope({sortby: 'original-order'}); 
                                    },100)                                    
                                    blogContainer.imagesLoaded().always( function( instance ) {
                                        setTimeout(function(){
                                            blogContainer.isotope({sortby: 'original-order'}); 
                                        },100)
                                    })
                                },200);                                
                            }); 
                            if (Number(response.max_num_pages) <= (data_page_item - 1)) {
                            	loadMoreButton.hide(300);
                            }
                    	}                 
                    }
                });
            })
		})
	}
}
// Countdown
function oswald_countdown_module () {
	if (jQuery('.wpd-countdown').length) {
		jQuery('.wpd-countdown').each(function () {
			var year = jQuery(this).attr('data-year');
			var month = jQuery(this).attr('data-month');
			var day = jQuery(this).attr('data-day');
			var hours = jQuery(this).attr('data-hours');
			var min = jQuery(this).attr('data-min');
			var format = jQuery(this).attr('data-format');

			var austDay = new Date();
			austDay = new Date(+year, +month-1, +day, +hours, +min);
			jQuery(this).countdown({
				until: austDay,
				format: format,
				padZeroes: true,
				labels: [jQuery(this).attr('data-label_years'),jQuery(this).attr('data-label_months'),jQuery(this).attr('data-label_weeks'),jQuery(this).attr('data-label_days'),jQuery(this).attr('data-label_hours'),jQuery(this).attr('data-label_minutes'),jQuery(this).attr('data-label_seconds')],
				labels1:[jQuery(this).attr('data-label_year'),jQuery(this).attr('data-label_month'),jQuery(this).attr('data-label_week'),jQuery(this).attr('data-label_day'),jQuery(this).attr('data-label_hour'),jQuery(this).attr('data-label_minute'),jQuery(this).attr('data-label_second')]
			});
		});
	}
}
// Custom Colors
function oswald_custom_color(){
	jQuery('.wpd_custom_color').each(function(){
		var element = jQuery(this);
		var color = element.attr('data-color')
		var hover_color = element.attr('data-hover-color')
		var bg_color = element.attr('data-bg-color')
		var border_color = element.attr('data-border-color')
		var bg_hover_color = element.attr('data-hover-bg-color')
		var border_hover_color = element.attr('data-hover-border-color')

		//set default colors
		if(typeof color !== 'undefined') {
			element.css({'color' : color});
		} else {
			element.css({'color' : ''});
		}
		if (typeof bg_color !== 'undefined') {
			element.css({'background-color' : bg_color});
		}else {
			element.css({'background-color' : ''});
		}

		if (typeof border_color !== 'undefined') {
			element.css({'border-color' : border_color});
		}else {
			element.css({'border-color' : ''});
		}

		//change colors on mouseenter / mouseleave
		element.on('mouseenter',function(){
			// Button Hover Text Color
			if(typeof hover_color !== 'undefined') {
				element.css({'color' : hover_color});				
			}
			if (typeof bg_hover_color !== 'undefined') {
				element.css({'background-color' : bg_hover_color});
			}
			if (typeof border_hover_color !== 'undefined') {
				element.css({'border-color' : border_hover_color});
			}
		}).on('mouseleave',function(){
			// Button Default Text Color
			if(typeof color !== 'undefined') {
				element.css({'color' : color});
			} else {
				element.css({'color' : ''});
			}
			if (typeof bg_color !== 'undefined') {
				element.css({'background-color' : bg_color});
			}else {
				element.css({'background-color' : ''});
			}
			if (typeof border_color !== 'undefined') {
				element.css({'border-color' : border_color});
			}else {
				element.css({'border-color' : ''});
			}
		});		
	})
}
// Header Scripts
// sticky header
function oswald_sticky_header (){
	if (jQuery(window).width() > 1200) {
		var stickyNumber = jQuery('.wpd_header_builder').height();
		var stickyHeader = jQuery('.wpd_header_builder > .sticky_header');
		var docScroll = jQuery(document).scrollTop();
		var docScrollNext = jQuery(document).scrollTop();
		if (stickyHeader.length) {
			var stickyType = stickyHeader.attr('data-sticky-type');
			if (stickyHeader[0].hasAttribute('data-sticky-number')) {
				stickyNumber = stickyHeader.attr('data-sticky-number');
			}
			var stickyOn = function(){
				docScroll = jQuery(document).scrollTop();
				if (stickyType == 'classic') {
					if (docScroll < stickyNumber) {
						stickyHeader.removeClass('sticky_on')
					}else{
						stickyHeader.addClass('sticky_on')
					}
				}else{
					if (( docScrollNext < docScroll) || (docScroll < stickyNumber) ) {
						stickyHeader.removeClass('sticky_on')
					}else{
						stickyHeader.addClass('sticky_on')
					}				
				}	
				docScrollNext = jQuery(document).scrollTop();		

			}
			stickyOn();
			jQuery(window).scroll(function() {
	            stickyOn();
	        });
		}
	}
}
// mobile menu
function oswald_mobile_menu(){
	var windowW = jQuery(window)
	var loaded = false;
	var main_menu = jQuery('.mobile_menu_container .main-menu > ul');
	var sub_menu = jQuery('.mobile_menu_container .main-menu > ul ul');
	var mobile_toggle = jQuery('.mobile-navigation-toggle');
	var burger_menu = jQuery('.wpd_header_builder__burger_sidebar .widget_nav_menu > div > ul');
	var burger_sub_menu = jQuery('.wpd_header_builder__burger_sidebar .widget_nav_menu > div > ul ul');
	if (windowW.width() <= 1200) {
		sub_menu.hide().removeClass('showsub')
		main_menu.hide().addClass('mobile_view_on');
		loaded = true;
		oswald_mobile_menu_switcher(main_menu)		
	}else{
		sub_menu.show();
		main_menu.show();
	}

	if (burger_menu.length) {	
		burger_sub_menu.hide().removeClass('showsub')
		oswald_mobile_burger_menu_switcher(burger_menu)	
	}

	jQuery(window).resize(function() {
		if (windowW.width() <= 1200) {
			if (!mobile_toggle.hasClass('is-active')) {
				sub_menu.hide().removeClass('showsub')
				main_menu.hide().removeClass('showsub').addClass('mobile_view_on');
				mobile_toggle.removeClass('is-active')
			}
			if (loaded == false) {
				loaded = true;
				oswald_mobile_menu_switcher(main_menu)
			}		
		}else{
			sub_menu.show().removeClass('showsub');
			main_menu.show().removeClass('showsub').removeClass('mobile_view_on');
			mobile_toggle.removeClass('is-active')
		}
	});
}
// end mobile menu 

function oswald_mobile_burger_menu_switcher(main_menu){
	if (jQuery(main_menu).find('.menu-item-has-children > .mobile_sitcher').length == 0) {
		jQuery(main_menu).find('.menu-item-has-children').append('<div class="mobile_sitcher"></div>')
	}

	jQuery(main_menu).find('.menu-item-has-children > .mobile_sitcher , .menu-item-has-children > a[href*=#]').on("tap click", function(e) {
		e.preventDefault();
		var element = jQuery(this);
		if (element.hasClass('is-active')) {
			element.prev('ul.sub-menu').removeClass('showsub').slideUp(200)
			element.next('ul.sub-menu').removeClass('showsub').slideUp(200)
			element.removeClass('is-active')
		}else{
			element.prev('ul.sub-menu').addClass('showsub').slideDown(200)
			element.next('ul.sub-menu').addClass('showsub').slideDown(200)
			element.addClass('is-active')
		}
	});
}


function oswald_mobile_menu_switcher(main_menu){
	if (jQuery(main_menu).find('.menu-item-has-children > .mobile_sitcher').length == 0) {
		jQuery(main_menu).find('.menu-item-has-children').append('<div class="mobile_sitcher"></div>')
	}
	jQuery('.mobile-navigation-toggle').on("tap click", function() {
		var element = jQuery(this);
		if (element.hasClass('is-active')) {
			main_menu.removeClass('showsub').slideUp(200)
			element.removeClass('is-active')
		}else{
			main_menu.addClass('showsub').slideDown(200)
			element.addClass('is-active')
		}
	});

	jQuery(main_menu).find('.menu-item-has-children > .mobile_sitcher , .menu-item-has-children > a[href*=#]').on("tap click", function(e) {
		e.preventDefault();
		var element = jQuery(this);
		if (element.hasClass('is-active')) {
			element.prev('ul.sub-menu').removeClass('showsub').slideUp(200)
			element.next('ul.sub-menu').removeClass('showsub').slideUp(200)
			element.removeClass('is-active')
		}else{
			element.prev('ul.sub-menu').addClass('showsub').slideDown(200)
			element.next('ul.sub-menu').addClass('showsub').slideDown(200)
			element.addClass('is-active')
		}
	});
}

function oswald_burger_sidebar(){
	var element = jQuery('.wpd_header_builder_burger_sidebar_component'); 
	var sidebar = jQuery('.wpd_header_builder__burger_sidebar');
	jQuery('.wpd_header_builder_burger_sidebar_component,.wpd_header_builder__burger_sidebar-cover').on('click',function(){
		if (element.hasClass('active')) {
			element.removeClass('active');
			sidebar.removeClass('active');
			jQuery('body').removeClass('active_burger_sidebar');
		}else{
			element.addClass('active');
			sidebar.addClass('active');
			jQuery('body').addClass('active_burger_sidebar');
			if (sidebar.hasClass('wpd_header_builder__burger_sidebar--left')) {
				jQuery('body').addClass('burger_sidebar_left');
			}
			if (sidebar.hasClass('wpd_header_builder__burger_sidebar--right')) {
				jQuery('body').addClass('burger_sidebar_right');
			}
		}		
	})
	jQuery(sidebar).on('swiperight',function(){
		if (element.hasClass('active')) {
			element.removeClass('active');
			sidebar.removeClass('active');
			jQuery('body').removeClass('active_burger_sidebar');
		}else{
			element.addClass('active');
			sidebar.addClass('active');
			jQuery('body').addClass('active_burger_sidebar');
			if (sidebar.hasClass('wpd_header_builder__burger_sidebar--left')) {
				jQuery('body').addClass('burger_sidebar_left');
			}
			if (sidebar.hasClass('wpd_header_builder__burger_sidebar--right')) {
				jQuery('body').addClass('burger_sidebar_right');
			}
		}		
	})
}

function oswald_modal_login(){	
	var element = jQuery('.wpd_header_builder__login-modal');
	if (element.hasClass('lwa') || element.hasClass('not_woo')) {
		return false;
	}
	jQuery('.wpd_header_builder_login_component,.wpd_header_builder__login-modal-close,.wpd_header_builder__login-modal-cover').on('click',function(){
		if (element.hasClass('active')) {
			element.removeClass('active');
		}else{
			element.addClass('active');
		}		
	})
	jQuery('.wpd_header_builder__login-modal_container .wpd_woo_login_switcher').on('click',function(){
		jQuery(this).parents('.wpd_header_builder__login-modal_container').toggleClass('register_active');
	})
}

function oswald_search(){
	var top_search = jQuery('.header_search');

	if (top_search.size() > 0) {
		top_search.each(function () {

			var $ctsearch = jQuery(this),
				$ctsearchinput = $ctsearch.find('input.search_text'),
				$body = jQuery('html, body'),
				openSearch = function () {
					$body.addClass('ct-search-open');
					$ctsearch.data('open', true).addClass('ct-search-open');
					$ctsearchinput.focus();
					return false;
				},
				closeSearch = function () {
					$body.removeClass('ct-search-open');
					$ctsearch.data('open', false).removeClass('ct-search-open');
				};

			$ctsearchinput.on('click', function (e) {
				e.stopPropagation();
				$ctsearch.data('open', true);
			});

			$ctsearch.find('.header_search__icon').on('click', function (e) {
				e.stopPropagation();
				if (!$ctsearch.data('open')) {
					console.log('opened')
					openSearch();
				}
				else {
					if ($ctsearchinput.val() === '') {
						closeSearch();
						return false;
					}
				}
			});

			$ctsearch.find('.header_search__inner_cover').on('click', function (e) {
				closeSearch();
			});
			$ctsearch.find('.header_search__inner_close').on('click', function (e) {
				closeSearch();
			});

			top_search.on('click', function(){
				var element = jQuery(this);
				if (element.hasClass('ct-search-hover')) {
					element.removeClass('ct-search-hover');
				}else{
					element.addClass('ct-search-hover');
					setTimeout(function(){
						element.find('input.search_text').focus();
					}, 100);
				}
			})

		});
	}

	jQuery(".search_form .search_submit").on("mouseover", function(){
		jQuery(this).parents('.search_form').addClass("button-hover");
	})
	jQuery(".search_form .search_submit").on("mouseleave", function(){
		jQuery(this).parents('.search_form').removeClass("button-hover");
	})
}

// menu line
function oswald_menu_line(){
	var menu = jQuery('.main-menu.main_menu_container.menu_line_enable > ul');
	if (menu.length) {
		menu.each(function(){
			var menu = jQuery(this);
			var current = '';
			menu.append('<span class="menu_item_line"></span>');
			var menu_item = menu.find('> .menu-item');
			var currentItem = menu.find('> .current-menu-item');
			var currentItemParent = menu.find('> .current-menu-ancestor');
			var line = menu.find('.menu_item_line');
			if (currentItem.length || currentItemParent.length) {
				current = currentItem.length ? currentItem : (currentItemParent.length ? currentItemParent : '');
				line.css({width: current.find('>a').outerWidth()});
				line.css({left: current.find('>a').offset().left - menu.offset().left});
			}

			menu_item.on('mouseenter',function(){
                line.css({width: jQuery(this).find('> a').outerWidth()});
                line.css({left: jQuery(this).find('> a').offset().left - jQuery(this).parent().offset().left});
            });

            menu.on('mouseleave',function(){
                if (current.length) {
                    line.css({width: current.find('> a').outerWidth()});
                    line.css({left: current.find('> a').offset().left - menu.offset().left});
                } else {
                	line.css({width:'0'});
                    line.css({left:'100%'});
                }
            });


		})
	}
}

function oswald_mega_menu(){
	jQuery('.wpd_header_builder > .wpd_header_builder__container .wpd_megamenu_active > .sub-menu, .wpd_header_builder > .sticky_header > .wpd_header_builder__container .wpd_megamenu_active > .sub-menu').each(function(){
		jQuery(this).find('.wpd_megamenu_triangle').css({
			'margin-left':'0px',
		})
		jQuery(this).css({
			'margin-left':'0px',
		})
		var elementWidth = jQuery(this).outerWidth();
		var windowWidth = jQuery(window).width();
		if (elementWidth > (windowWidth - 50) || jQuery(this).hasClass('huge_number_of_column')) {
			elementWidth = windowWidth - 50;
			jQuery(this).addClass('huge_number_of_column');
			var menu_item_width = jQuery(this).children('.menu-item').outerWidth();
			var namber_item_per_row = Math.floor(elementWidth/menu_item_width);	
			var item_count = jQuery(this).children('.menu-item').length;
			var i = 1;
			var last_item_begin_from = (Math.floor(item_count / namber_item_per_row) * namber_item_per_row);
			jQuery(this).children('.menu-item').each(function(){
				i++;
				if (last_item_begin_from < i) {
					jQuery(this).css('max-width',(menu_item_width - 70/*padding value*/)+'px');
				}
				
			})
		}else{
			jQuery(this).removeClass('huge_number_of_column');
		}
		var halfWidth = Math.round(elementWidth/2);

		var leftOffset = jQuery(this).offset().left - halfWidth;
		var rightOffset = windowWidth - (leftOffset + elementWidth);
		if (rightOffset < 25) {
			halfWidth = halfWidth + 25 - rightOffset;
		}
		if (leftOffset < 25) {
			halfWidth = halfWidth - 25 + leftOffset;
		}
		jQuery(this).find('.wpd_megamenu_triangle').css({
			'margin-left':(halfWidth-34)+'px',
		})
		jQuery(this).css({
			'margin-left':-halfWidth+'px',
		})
	})
}

function oswald_one_page_scroll(){
	var sticky_header = jQuery('.wpd_header_builder .sticky_header');
	var sticky_header_height = 0;
	var offset = 0;
	var windowW = jQuery(window)
	if (sticky_header.length && windowW.width() >= 1200) {		
		sticky_header_height = sticky_header.height();
	}
	
	jQuery('.main-menu li > a[href*="#"]:not([href="#"])').on('click',function(e){
		if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
			e.preventDefault();
			var target = jQuery(this.hash);
			if (target.length) {
				if (target.offset().top < 300) {
					offset = 0;				
				}else{
					offset = target.offset().top - sticky_header_height + 1
				}
		        jQuery('html, body').animate({
		          scrollTop: (offset)
		        }, 1000);
		        return false;
		    }
		}
	})
	var sections = [];
	jQuery('.main-menu li > a[href*="#"]:not([href="#"])').each(function (Key, Value){	
		if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
			jQuery(this).parent('.menu-item').removeClass('current-menu-item');
		}
		var href = jQuery(Value).attr('href');
		var href_array = href.split("#");
		var anchor = '';
		if (href.split("#").length) {
			anchor = href_array[href.split("#").length - 1];
		}
		
		if (anchor.length && jQuery('#'+anchor).length) {
			sections[Key] = [];
	        sections[Key]['id'] = '#'+anchor;
	        sections[Key]['href'] = href;
	    	sections[Key]['value'] = jQuery(sections[Key]['id']).offset().top - sticky_header_height;
	    	sections[Key]['height'] = sections[Key]['value'] + jQuery(sections[Key]['id']).outerHeight();
	    }
       
	})

	jQuery(window).on('scroll',function ()
    {
        var Scroll = jQuery(window).scrollTop();
        for (var I = 0; I < sections.length; I++)
        {
            if ((Scroll >= sections[I]['value'] && Scroll <= sections[I]['height']))
            {
                jQuery('.wpd_header_builder .menu-item.active_item').removeClass('active_item');
                jQuery('.wpd_header_builder [href="' + sections[I]['href'] + '"]').parent('.menu-item').addClass('active_item');
            	
            }else{
            	jQuery('.wpd_header_builder [href="' + sections[I]['href'] + '"]').parent('.menu-item').removeClass('active_item');
            }
        }
    });
}

jQuery(window).on('resize',function() {
	if (jQuery(window).width() >= 1200) {
		oswald_mega_menu();
	}
})
// login With Ajax
function loginWithAjaxHandlers() {
    if (jQuery('.lwa-modal').length) {

        jQuery('.js-lwa-open-remember-form').on('click', function(e) {
            e.stopPropagation();
            e.preventDefault();
            jQuery('.js-lwa-login, .js-lwa-remember').toggleClass('form-visible');
        });

        jQuery('.js-lwa-close-remember-form').on('click', function() {
            jQuery('.js-lwa-login, .js-lwa-remember').toggleClass('form-visible');
        });

        jQuery('.js-lwa-open-register-form').on('click', function(e) {
            e.stopPropagation();
            e.preventDefault();
            jQuery('.js-lwa-login, .js-lwa-register').toggleClass('form-visible');
        });

        jQuery('.js-lwa-close-register-form').on('click', function() {
            jQuery('.js-lwa-login, .js-lwa-register').toggleClass('form-visible');
        });

        jQuery('.lwa-login-link').on('touchstart', function() {
            closeMenu();
        });
    }
}
// Message box
function oswald_message_close(){
	jQuery(".wpd_message_box-closable").each(function(){
		var element = jQuery(this);
		element.find('.wpd_message_box__close').on('click',function(){
			element.slideUp(300);
		})
	})
}
// Portfolio
function oswald_portfolio_isotope(){
	jQuery('.wpdaddy_portfolio_list__posts-container').each(function(){
		var element = jQuery(this);
        var element_item;
		var layoutMode = element.attr('data-practice_layout') === 'grid' ? 'fitRows' : 'masonry';

		element.find('.wpdaddy_portfolio_list__item:not(.image_loaded)').each(function(){
			element_item = jQuery(this);
			element_item.find('img').imagesLoaded().always(function(instance ){
				jQuery(instance.elements).parents('.wpdaddy_portfolio_list__item').addClass('image_loaded');
			})
		})

		element.isotope({
            itemSelector: '.wpdaddy_portfolio_list__item',
            percentPosition: true,
            masonry: {
                columnWidth: '.wpdaddy_portfolio_list__grid-sizer',
                gutter: '.wpdaddy_portfolio_list__grid-gutter'
            }
        });

        element.imagesLoaded(function(){
            element.isotope({
                itemSelector: '.wpdaddy_portfolio_list__item',
                percentPosition: true,
                layoutMode: layoutMode,
                masonry: {
                    columnWidth: '.wpdaddy_portfolio_list__grid-sizer',
                    gutter: '.wpdaddy_portfolio_list__grid-gutter'
                }
            });
        });

        element.parent('.wpdaddy_portfolio_list').find(".wpdaddy_portfolio_list__filter.isotope-filter a").on( 'click', function(){
        	var filter_item = jQuery(this);
            filter_item.siblings().removeClass('active');
            filter_item.addClass("active");
            var selector = filter_item.attr('data-filter');             
            element.isotope({
                filter: selector,
            });
            return false;
        }); 

	})
}

function oswald_portfolio_load_more_init (){
	var wpdaddy_portfolio_list = jQuery('.wpdaddy_portfolio_list');
	if (wpdaddy_portfolio_list.length) {
		wpdaddy_portfolio_list.each(function(){
			var element = jQuery(this);
			var loadMoreButton = element.find('.wpdaddy_portfolio_load_more');
			var portfolioContainer = element.find('.wpdaddy_portfolio_list__posts-container');
			var nextPage = 2;
            var max_num_pages = 3;
            if (typeof portfolioContainer.data('max_num_pages') !== 'undefined' && portfolioContainer.data('max_num_pages') !== false) {  
                max_num_pages = portfolioContainer.data('max_num_pages');
            }

            loadMoreButton.on('click', function (e) {
                loadMoreButton.addClass('loading');
                e.preventDefault();
                e.stopPropagation(); 
                if (nextPage <= max_num_pages) {
                	var ajaxData = {
                		action: 'wpdaddy_get_practice_item_from_ajax',
                		build_query: portfolioContainer.attr('data-build_query'),
                		portfolio_style: portfolioContainer.attr('data-portfolio_style'),
                		portfolio_layout: portfolioContainer.attr('data-portfolio_layout'),
                		columns_with_spaces: portfolioContainer.attr('data-columns_with_spaces'),
                		rounded_images: portfolioContainer.attr('data-rounded_images'),
                		posts_per_line: portfolioContainer.attr('data-posts_per_line'),
                		image_proportional: portfolioContainer.attr('data-image_proportional'),
                		items_load: portfolioContainer.attr('data-items_load'),
                		post_count: portfolioContainer.attr('data-post_count'),
                	};
                	ajaxData['next_page'] = nextPage;
                	jQuery.ajax({
                        type: 'POST',
                        data: ajaxData,
                        url: object_name.wpd_ajaxurl,
                        success: function (data) { 
                        	loadMoreButton.removeClass('loading');
                        	if (data != '') {
                        		var response = jQuery.parseJSON(data);
	                        	var responseHtml = response.html;                        	
	                        	var img_loader = imagesLoaded( portfolioContainer );
	                        	img_loader.on( 'always', function (){ 
	                                setTimeout(function() {
                                        portfolioContainer
                                        .append( jQuery(responseHtml) )
                                        .isotope( 'appended', jQuery(responseHtml) )
                                        .isotope('reloadItems');    
                                        portfolioContainer.find('.wpdaddy_portfolio_list__item:not(.image_loaded)').each(function(){
                                        	jQuery(this).imagesLoaded().always(function(instance ){
												jQuery(instance.elements).addClass('image_loaded');
											}) 
                                        })                                      
                                        setTimeout(function(){
                                            portfolioContainer.isotope({sortby: 'original-order'}); 
                                        },100)
                                        portfolioContainer.imagesLoaded().always( function( instance ) {
                                            setTimeout(function(){
                                                portfolioContainer.isotope({sortby: 'original-order'}); 
                                            },100)
                                        })

                                    },200);                                
	                            }); 
	                            if (Number(response.items_left) <= '0') {
	                            	loadMoreButton.hide(300);
	                            }
	                            portfolioContainer.attr('data-post_count',Number(ajaxData.post_count) + Number(ajaxData.items_load));
                        	}                 
                        }
                    });
                }
            })
		})
	}
}
// Post Like
jQuery(document).on("click", ".post_likes_add", function(event) {
	var post_likes_this = jQuery(this);
	if (!jQuery.cookie(post_likes_this.attr('data-modify')+post_likes_this.attr('data-postid'))) {
		jQuery.post(object_name.wpd_ajaxurl, {
			action:'add_like_attachment',
			attach_id:jQuery(this).attr('data-postid')
		}, function (response) {
			jQuery.cookie(post_likes_this.attr('data-modify')+post_likes_this.attr('data-postid'), 'true', { expires: 7, path: '/' });
			post_likes_this.addClass('already_liked');
			post_likes_this.find('span.like_count').text(response);
			var title_text = '';
			if (typeof post_likes_this.attr('title') != undefined) {
				title_text = post_likes_this.attr('title').split(/[0-9]+/);
			}
			post_likes_this.attr('title',response+title_text[1])
			//.split(/[0-9]+/)

		});
	}
});
// Slick
function oswald_blog_list_slider(){
	if (!jQuery('.wpd_blog_list__media .slickSlider').length) {
		return;
	}

	setTimeout(function(){
		jQuery('.wpd_blog_list__media .slickSlider').slick({
		  infinite: true,
		  speed: 500,
		  fade: true,
		  cssEase: 'linear',
		  dots: true,
		  adaptiveHeight: true,
		  autoplay: true,
	  	  autoplaySpeed: 3000,
		  prevArrow: '<div class="slickSlider__arrow slickSlider__arrow--prev"></div>',
		  nextArrow: '<div class="slickSlider__arrow slickSlider__arrow--next"></div>'
		});
	},100)	
	
}

// Wpd Carousel List
function oswald_carousel_list () {
	var carousel_tag = jQuery('.wpd_carousel_list');
	if (carousel_tag.length) {
		carousel_tag.each(function(){
			jQuery(this).slick({
			});
		});
	}
}
// team
function oswald_team_isotope(){
	jQuery('.wpdaddy_team_list__posts-container').each(function(){
		var element = jQuery(this);
        var element_item;
		var layoutMode = element.hasClass('isotope_packery') ? 'masonry' : 'fitRows';

		element.find('.wpdaddy_team_list__item:not(.image_loaded)').each(function(){
			element_item = jQuery(this);
			element_item.find('img').imagesLoaded().always( function(instance ){
				jQuery(instance.elements).parents('.wpdaddy_team_list__item').addClass('image_loaded');
			})
		})

		element.isotope({
            itemSelector: '.wpdaddy_team_list__item',
            percentPosition: true,
            masonry: {
                columnWidth: '.wpdaddy_team_list__grid-sizer',
                gutter: '.wpdaddy_team_list__grid-gutter'
            }
        });

        element.imagesLoaded(function(){
            element.isotope({
                itemSelector: '.wpdaddy_team_list__item',
                percentPosition: true,
                masonry: {
                    columnWidth: '.wpdaddy_team_list__grid-sizer',
                    gutter: '.wpdaddy_team_list__grid-gutter'
                }
            });
        });

        element.parent('.wpdaddy_team_list').find(".wpdaddy_team_list__filter.isotope-filter a").on( 'click', function(){
        	var filter_item = jQuery(this);
            filter_item.siblings().removeClass('active');
            filter_item.addClass("active");
            var selector = filter_item.attr('data-filter');             
            element.isotope({
                filter: selector,
            });
            return false;
        }); 
	})
}

function oswald_team_load_more_init (){
	var wpdaddy_team_list = jQuery('.wpdaddy_team_list');
	if (wpdaddy_team_list.length) {
		wpdaddy_team_list.each(function(){
			var element = jQuery(this);
			var loadMoreButton = element.find('.wpdaddy_team_load_more');
			var teamContainer = element.find('.wpdaddy_team_list__posts-container');
			var nextPage = 2;
            var max_num_pages = 3;
            if (typeof teamContainer.data('max_num_pages') !== 'undefined' && teamContainer.data('max_num_pages') !== false) {  
                max_num_pages = teamContainer.data('max_num_pages');
            }

            loadMoreButton.on('click', function (e) {
                loadMoreButton.addClass('loading');
                e.preventDefault();
                e.stopPropagation(); 
                if (nextPage <= max_num_pages) {
                	var ajaxData = {
                		action: 'wpdaddy_get_team_item_from_ajax',
                		build_query: teamContainer.attr('data-build_query'),
                		team_style: teamContainer.attr('data-team_style'),
                		posts_per_line: teamContainer.attr('data-posts_per_line'),
                		items_load: teamContainer.attr('data-items_load'),
                		post_count: teamContainer.attr('data-post_count'),
                	};
                	ajaxData['next_page'] = nextPage;
                	jQuery.ajax({
                        type: 'POST',
                        data: ajaxData,
                        url: object_name.wpd_ajaxurl,
                        success: function (data) { 
                        	loadMoreButton.removeClass('loading');
                        	if (data != '') {
                        		var response = jQuery.parseJSON(data);
	                        	var responseHtml = response.html;                        	
	                        	var img_loader = imagesLoaded( teamContainer );
	                        	img_loader.on( 'always', function (){ 
	                                setTimeout(function() {
                                        teamContainer
                                        .append( jQuery(responseHtml) )
                                        .isotope( 'appended', jQuery(responseHtml) )
                                        .isotope('reloadItems');    
                                        teamContainer.find('.wpdaddy_team_list__item:not(.image_loaded)').each(function(){
                                        	jQuery(this).imagesLoaded().always(function(instance ){
												jQuery(instance.elements).addClass('image_loaded');
											}) 
                                        })  
                                        setTimeout(function(){
                                            teamContainer.isotope({sortby: 'original-order'}); 
                                        },100)
                                        teamContainer.imagesLoaded().always( function( instance ) {
                                            setTimeout(function(){
                                                teamContainer.isotope({sortby: 'original-order'}); 
                                            },100)
                                        })
                                    },200);                                
	                            }); 
	                            if (Number(response.items_left) <= '0') {
	                            	loadMoreButton.hide(300);
	                            }
	                            teamContainer.attr('data-post_count',Number(ajaxData.post_count) + Number(ajaxData.items_load));
                        	}                 
                        }
                    });
                }
            })
		})
	}
}
// Testimonials
function oswald_testimonials_list () {
	if (jQuery('.module_testimonial.type2').length) {
		jQuery('.module_testimonial.type2').each(function(){
			var cur_img = jQuery(this).find('.testimonials_photo');
			var wrapper_img = '';
			for (var i=0; i < cur_img.length; i++) {
				wrapper_img += cur_img[i].outerHTML;
			}
			jQuery(this).find('.testimonials-photo-wrapper').append(wrapper_img);
		})
	}
	if (jQuery('.module_testimonial.active-carousel').length) {
		jQuery('.module_testimonial.active-carousel').each(function(){
			var cur_slidesToShow = jQuery(this).attr('data-slides-per-line')*1;
			var cur_sliderAutoplay = jQuery(this).attr('data-autoplay-time')*1;
			var cur_fade = jQuery(this).attr('data-slider-fade') == 1;
			var rotator = jQuery(this).find('.testimonials_rotator');
			var photo_wrapper = jQuery(this).find('.testimonials-photo-wrapper');
			jQuery(this).find('.testimonials_rotator').slick({
				slidesToShow: cur_slidesToShow,
				slidesToScroll: cur_slidesToShow,
				autoplay: true,
				autoplaySpeed: cur_sliderAutoplay,
				speed: 500,
				dots: true,
				fade: cur_fade,
				focusOnSelect: true,
				arrows: false,
				infinite: true,
				asNavFor: photo_wrapper,
				responsive: [
		        {
		          breakpoint: 800,
		          settings: {
		            slidesToShow: 1,
		            slidesToScroll: 1
		          }
		        }
		        ]
			});
			var centerMode = false;
			if (jQuery(this).hasClass('testimonials_align_center')) {
				centerMode = true;
			}
			jQuery(this).find('.testimonials-photo-wrapper').slick({
				slidesToShow: 3,
				slidesToScroll: 1,
				asNavFor: rotator,
				dots: false,
				centerMode: centerMode,
				focusOnSelect: true
			})
			var data_pagination_color = jQuery(this).attr('data-pagination-color');
			if (typeof data_pagination_color != 'undefined') {
				jQuery(this).find('.slick-dots').addClass('custom_color').css({
					'color':data_pagination_color,
					'border-color':data_pagination_color,
				});
			}
		});
	}
	if (jQuery('.module_testimonial.type5').length) {
		jQuery('.module_testimonial.type5').each(function(){
			var cur_img = jQuery(this).attr('data-image-width');
			jQuery(this).find('.slick-dots').css({
				'width':cur_img+'px',
				'top':cur_img+'px',
			});
		});
	}
}
// Video
function oswald_video_play_button(){
	jQuery('.wpd_video__wrapper').each(function(){
		var iframe = jQuery(this).find('.wpd_video_wrapper__iframe iframe');
		var iframe_wrapper = jQuery(this).find('.wpd_video_wrapper__iframe');
		var thumb = jQuery(this).find('.wpd_video_wrapper__thumb');
		jQuery(this).find('.wpd_video__play_button').on('click',function(){
			var video_autoplay = jQuery(this).attr('data-video-autoplay');
			iframe[0].src += video_autoplay;
			iframe_wrapper.addClass('play_video');
			thumb.addClass('play_video');
		})
		
	})
}
function oswald_popup_video () {
	if (jQuery(".swipebox-video, .swipebox").length) {
		jQuery( '.swipebox-video, .swipebox' ).swipebox( {
			useCSS : true, // false will force the use of jQuery for animations
			useSVG : true, // false to force the use of png for buttons
			initialIndexOnArray : 0, // which image index to init when a array is passed
			hideCloseButtonOnMobile : false, // true will hide the close button on mobile devices
			removeBarsOnMobile : true, // false will show top bar on mobile devices
			hideBarsDelay : 3000, // delay before hiding bars on desktop
			videoMaxWidth : 1140,
			autoplayVideos: false,
			beforeOpen: function() {}, // called before opening
			afterOpen: null, // called after opening
			afterClose: function() {}, // called after closing
			loopAtEnd: false // true will return to the first image after the last image is reached
		} );
	}
}
// Widgets Scripts

// Flickr Widget
function oswald_flickr_widget () {
	var flickr_widget_wrapper_tag = jQuery('.flickr_widget_wrapper');
	if (flickr_widget_wrapper_tag.length) {
		flickr_widget_wrapper_tag.each(function () {
			var flickrid = jQuery(this).attr('data-flickrid');
			var widget_id = jQuery(this).attr('data-widget_id');
			var widget_number = jQuery(this).attr('data-widget_number');
			jQuery(this).addClass('flickr_widget_wrapper_'+flickrid);

			jQuery.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id="+widget_id+"&lang=en-us&format=json&jsoncallback=?", function(data){
				jQuery.each(data.items, function(i,item){
					if(i<widget_number){
						jQuery("<img/>").attr("src", item.media.m).appendTo(".flickr_widget_wrapper_"+flickrid).wrap("<div class=\'flickr_badge_image\'><a href=\'" + item.link + "\' target=\'_blank\' title=\'Flickr\'></a></div>");
					}
				});
			});
		});
	}
}

// Widget Hover
function oswald_widget_hover () {
	var widget_tag = jQuery('.widget');
	if (widget_tag.size() > 0) {
		widget_tag.each(function () {
			jQuery(this).find('li > a').on('mouseenter',function(){
				jQuery(this).parent().addClass('active_list_item');
			}).on('mouseleave',function(){
				jQuery(this).parent().removeClass('active_list_item');
			});
		});
	}
}

// Counter Module
function oswald_initCounter() {
	if (jQuery('.wpd_module_counter').length) {
		if (jQuery(window).width() > 760) {
			jQuery('.wpd_module_counter').each(function(){
				if (jQuery(this).offset().top < jQuery(window).height()) {
					var cur_this = jQuery(this);
					if (!jQuery(this).hasClass('done')) {
						var stat_count = cur_this.find('.stat_count'),
							set_count = stat_count.attr('data-value'),
							counter_suffix = stat_count.attr('data-suffix'),
							counter_prefix = stat_count.attr('data-prefix');

						jQuery(this).find('.stat_temp').stop().animate({width: set_count}, {duration: 3000, step: function(now) {
							var data = Math.floor(now);
							stat_count.text(counter_prefix + data + counter_suffix);
						}
						});
						jQuery(this).addClass('done');
					}
				} else {
					var cur_this = jQuery(this);
					jQuery(this).waypoint(function(){
						if (!cur_this.hasClass('done')) {
							var stat_count = cur_this.find('.stat_count'),
								set_count = stat_count.attr('data-value'),
								counter_suffix = stat_count.attr('data-suffix'),
								counter_prefix = stat_count.attr('data-prefix');
							cur_this.find('.stat_temp').stop().animate({width: set_count}, {duration: 3000, step: function(now) {
								var data = Math.floor(now);
								stat_count.text(counter_prefix + data + counter_suffix);
							}
							});
							cur_this.addClass('done');
						}
					},{offset: 'bottom-in-view'});
				}
			});
		} else {
			jQuery('.wpd_module_counter').each(function(){
				var stat_count = jQuery(this).find('.stat_count'),
					set_count = stat_count.attr('data-value'),
					counter_suffix = stat_count.attr('data-suffix'),
					counter_prefix = stat_count.attr('data-prefix');
				jQuery(this).find('.stat_temp').stop().animate({width: set_count}, {duration: 3000, step: function(now) {
					var data = Math.floor(now);
					stat_count.text(counter_prefix + data + counter_suffix);
				}
				});
			},{offset: 'bottom-in-view'});
		}
	}
}
// Column Separators
function oswald_initRowseparator() {
	var row_has_column_separator_tag = jQuery('.row_has_column_separator');
	if (row_has_column_separator_tag.length) {
		row_has_column_separator_tag.each(function () {
			var border_color = jQuery(this).attr('data-separator-color');
			jQuery(this).find('.wpb_column > .vc_column-inner > .wpb_wrapper').addClass('column_separator_wrap').css("border-color", border_color).parent().addClass('column_separator_parent');
		});
	}
}
// Services Box Module
function oswald_services_box () {
	jQuery(".wpd_services_box").each(function(){
		if (jQuery(this).find('.text_wrap').length) {
			var text_h = jQuery(this).find('.text_wrap').height();
			jQuery(this).find('.fake_space').height(text_h);
		}
	});
}

})(jQuery);