/*
* jQuery throttle / debounce - v1.1 - 3/7/2010
* http://benalman.com/projects/jquery-throttle-debounce-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this);
jQuery(document).ready(function() {
if (jQuery.isFunction(jQuery.fn.owlCarousel)) {
jQuery('.owl-carousel').owlCarousel({
items:3,
margin:30,
nav:true,
slideBy:'page',
rewind:false,
onInitialized: function(event) {
var $target = jQuery(event.target);
$target.find('div.owl-item').height('');
$target.find('div.owl-item').height($target.height());
},
onRefreshed: function(event) {
var $target = jQuery(event.target);
$target.find('div.owl-item').height('');
$target.find('div.owl-item').height($target.height());
},
responsive: {
0:{items:1},
790:{items:2},
1180:{items:3}
}
});
}
var $body = jQuery('body');
var $menuwrap = jQuery('#menuwrap');
jQuery('button.togglemenu').click(function(e) {
e.preventDefault();
if ($body.hasClass('menuopen')) {
$body.removeClass('menuopen');
$menuwrap.stop().slideUp(300,function() {
jQuery(this).css('height','');
});
} else {
$body.addClass('menuopen');
$menuwrap.stop().slideDown(300,function() {
jQuery(this).css('height','');
});
}
});
var dropdownToggle = jQuery('',{
'class':'dropdown-toggle'
}).append(jQuery('',{
'class':'screen-reader-text',
text:'Toggle submenu'
}));
$menuwrap.find('#menu>ul>li.menu-item-has-children').append(dropdownToggle);
$menuwrap.find('#menu>ul>li.menu-item-has-children.current-menu-item>.dropdown, #menu>ul>li.menu-item-has-children.current-menu-ancestor>.dropdown').show().parent().addClass('open');
$menuwrap.on('click','.dropdown-toggle',function(e) {
var $li = jQuery(this).closest('li');
var $dropdown = $li.children('.dropdown');
if ($li.hasClass('open')) {
$li.removeClass('open');
$dropdown.stop().slideUp(300,function() {
jQuery(this).css('height','');
});
} else {
$li.addClass('open');
$dropdown.stop().slideDown(300,function() {
jQuery(this).css('height','');
});
}
});
jQuery('.postlist .plcontent').not('.owl-carousel .plcontent').matchHeight();
jQuery('#menu .megamenu>ul>li>ul').matchHeight();
jQuery('.services>ol>li>.li-a').matchHeight();
jQuery('.sections .section-testimonial').each(function() {
var $quotes = jQuery(this).find('blockquote');
var want = Math.floor(Math.random()*$quotes.length);
$quotes.eq(want).show();
});
var $indexnav = jQuery('nav.indexnav .navnext a');
$window = jQuery(window);
var navloading = false;
if ($indexnav.length) {
var btntext = $indexnav.text();
$indexnav.click(function(e) {
e.preventDefault();
var $btn = jQuery(this);
if ($btn.hasClass('loading')) return;
$btn.addClass('loading');
$btn.text('Loading...');
navloading = true;
jQuery.ajax({
dataType:"json",
url:this.href,
data: {
ajaxpagination:1,
commentpagination:jQuery(this).closest('.indexnav').hasClass('commentsnav')?1:0
},
success:function(data) {
var com = $btn.closest('.indexnav').hasClass('commentsnav');
if (data.pagelink=='') {
$btn.closest('.indexnav').remove();
} else {
$btn.attr('href',data.pagelink);
$btn.removeClass('loading');
$btn.text(btntext);
navloading = false;
}
if (com) {
jQuery('#comments ul.commentlist').append(data.html);
} else {
jQuery('#main .postlist ul').append(data.html);
jQuery('#main .postlist .plcontent').matchHeight('remove').matchHeight();
}
}
});
});
$window.scroll(jQuery.throttle(250,function() {
if (!navloading) {
var scrolled = jQuery(window).scrollTop() + jQuery(window).height();
var position = $indexnav.offset().top;
if (scrolled+500>=position) {
$indexnav.triggerHandler('click');
}
}
})).triggerHandler(scroll);
}
});