/*=========== sticy header ===========*/

$=jQuery;

$(document).ready(function() {

	var toggleAffix = function(affixElement, scrollElement, wrapper) {
		var height = affixElement.outerHeight(),
			top = wrapper.offset().top;
		
		if (scrollElement.scrollTop() >= top) {
			affixElement.addClass("affix");
			wrapper.height(height);
		}
		else {
			affixElement.removeClass("affix");
			wrapper.height('auto');
		}	
	};

	var header_ht = $( '.site-header' ).height();
	if ($(document).scrollTop() > header_ht) {
		$('.bg-dark').addClass('affix');
		$('.mean-bar').addClass('affix');
	} 
	else {
		$('.bg-dark').removeClass('affix');
		$('.mean-bar').removeClass('affix');
	}


	$('[data-toggle="affix"]').each(function() {
		var ele = $(this),
			wrapper = $('<div class="manage"></div>');
		
		ele.before(wrapper);
		$(window).on('scroll resize', function() {
			toggleAffix(ele, $(this), wrapper);
		})
	})

	$('.mean-bar').each(function() {
		var ele = $(this),
			wrapper = $('<div class="manage"></div>');
		
		ele.before(wrapper);
		$(window).on('scroll resize', function() {
			toggleAffix(ele, $(this), wrapper);
		})
	})
});
