$(window).scroll(function () {
  var sc = $(window).scrollTop();
  if (sc > 150) {
    $(".navbar").addClass("navbar-scroll");
  } else {
    $(".navbar").removeClass("navbar-scroll");
  }
});

//Program created by Ryan Tarson Updated 6.15.16, under this code is my pure JS Version
jQuery(document).ready(function ($) {
  var wHeight = window.innerHeight;
  //search bar middle alignment
  $("#mk-fullscreen-searchform").css("top", wHeight / 2);
  //reform search bar
  jQuery(window).resize(function () {
    wHeight = window.innerHeight;
    $("#mk-fullscreen-searchform").css("top", wHeight / 2);
  });
  // Search
  $("#search-button").click(function () {
    console.log("Open Search, Search Centered");
    $("div.mk-fullscreen-search-overlay").addClass(
      "mk-fullscreen-search-overlay-show"
    );
  });
  $("a.mk-fullscreen-close").click(function () {
    console.log("Closed Search");
    $("div.mk-fullscreen-search-overlay").removeClass(
      "mk-fullscreen-search-overlay-show"
    );
  });
});

/* Don't Like jQuery or have a custom jQuery that's conflicting? Then you can use my Pure JS program Below. Runs exactly the same and so is the preformance just Pure JS*/
//Program made by Ryan Tarson
/*
   var wHeight = window.innerHeight;
   var sb = document.getElementById("search-button");
   var closeSB = document.getElementById("mk-fullscreen-close-button");
   var SearchOverlay = document.getElementById("mk-search-overlay");
   var searchBar = document.getElementById("mk-fullscreen-searchform");
   searchBar.style.top=wHeight/2 +'px';
	console.log(wHeight);
	window.addEventListener("resize", function(){
		console.log(wHeight);
		 wHeight = window.innerHeight;
		 searchBar.style.top=wHeight/2 + 'px';
	}, true);
	document.addEventListener("click", function(){
	sb.onclick = function(){
	  console.log("Opened Search for Element: ");
	  SearchOverlay.classList.add("mk-fullscreen-search-overlay-show");
	};
	closeSB.onclick = function(){
		console.log("Closed Search for Element: " + closeSB);
		SearchOverlay.classList.remove("mk-fullscreen-search-overlay-show");
	};
	}, true);
	*/
var rafId = null;
var delay = 200;
var lTime = 0;

function scroll() {
  var scrollTop = $(window).scrollTop();
  var height = $(window).height();
  var visibleTop = scrollTop + height;
  $(".reveal").each(function () {
    var $t = $(this);
    if ($t.hasClass("reveal_visible")) {
      return;
    }
    var top = $t.offset().top;
    if (top <= visibleTop) {
      if (top + $t.height() < scrollTop) {
        $t.removeClass("reveal_pending").addClass("reveal_visible");
      } else {
        $t.addClass("reveal_pending");
        if (!rafId) requestAnimationFrame(reveal);
      }
    }
  });
}
function reveal() {
  rafId = null;
  var now = performance.now();

  if (now - lTime > delay) {
    lTime = now;
    var $ts = $(".reveal_pending");
    $($ts.get(0)).removeClass("reveal_pending").addClass("reveal_visible");
  }

  if ($(".reveal_pending").length >= 1) rafId = requestAnimationFrame(reveal);
}

$(scroll);
$(window).scroll(scroll);

$(document).ready(function () {
  $(".owl-carousel").owlCarousel();
});
