jQuery( document ).ready( function( $ ){
	var timeout = ( function(){
 		var timers = {};
 		return function( callback, ms, x_id ){
		   if ( !x_id ){ x_id = ''; }
		   if ( timers[x_id] ){ clearTimeout( timers[x_id] ); }
		   timers[x_id] = setTimeout( callback, ms );
 		};
	})();
	var header_height = $('.site-header').outerHeight();
	$('.wpctp-search-icon').click(function(e) {
		if($('.wpctp-search-form').css('display') == 'block'){
			$('.wpctp-search-form').hide();
		}else{
			$('.wpctp-search-form').show();
		}
	});
	if($('.testimonial-slider').length){
		$('.testimonial-slider').bxSlider({
			mode: 'fade',
			responsive: true,
			auto: true,
			autoStart: true,
			pause: 8000,
			//infiniteLoop: false,
			controls: false,
			adaptiveHeight: true
		});
	}
	$('.site-container').css('padding-top',header_height);
	if($('body.wpctp-has-image .entry-header-wrap').length){
		$('body.wpctp-has-image .entry-header-wrap').css('height',(255 - header_height));
	}
	$(window).scroll(function() {
		$('.header-wrap').css('height',$('.header-wrap .custom-header').outerHeight());
		if($(this).scrollTop() >= header_height && $('#page').outerHeight() > 768){
			$('body').addClass('wpctp-has-scroll');
			//$('#masthead').css('padding-top',header_height + 'px');
			$('img#wpctp-logo').attr('src',$('img#wpctp-logo').attr('data-sticky'));
			$('body.wpctp-boxed #masthead .custom-header').width($('body.wpctp-boxed #masthead').width());
			$('.wpctp-has-scroll .default-header').css('top',$('html').css('margin-top'));
		}else{
			$('.wpctp-has-scroll .default-header').css('top','');
			$('body').removeClass('wpctp-has-scroll');
			//$('#masthead').css('padding-top','');
			$('img#wpctp-logo').attr('src',$('img#wpctp-logo').attr('data-main'));
		}
	});
	header_width();
	$(window).resize(function(){
		timeout(function(){
			header_width();
		},200);
	});
//	$(window).bind('load',function(){
		if($('.wpctp-sliders').length && $('.wpctp-sliders li').length > 1 ){
			$( '.wpctp-sliders' ).animate({opacity:1}, function(){
				$(this).bxSlider({
					  controls: true,
					  pager: false,
					  speed: 900,
					  pause: 6000,
					  auto: true,
					  mode: 'fade',
					  captions: true,
					  autoHover: true,
					  adaptiveHeight: true,
					  useCSS: false,
					  nextText:"",
					  prevText:"",
				});
			});
		}else{
			$( '.wpctp-sliders' ).animate({opacity:1},function(){
				$(this).bxSlider({
					controls: false,
					pager: false,
					speed: 900,
					pause: 6000,
					auto: true,
					mode: 'fade',
					captions: true,
					autoHover: true,
					adaptiveHeight: true,
					useCSS: false,
					nextText:"",
					prevText:"",
					infiniteLoop: false,
				});
			});
		}
//	});
	function header_width(){
		if($('body.wpctp-boxed .site-container').length){
			$('body.wpctp-boxed .site-header').width($('body.wpctp-boxed .site-container').width());
		}
	}
});