$( document ).ready(function() {
    var isMobile = window.matchMedia("only screen and (max-width: 760px)");
      $(window).scroll(
          {
              previousTop: 0
          },
          // Hide Header on on scroll down but only on mobile devices
          function () {
          var currentTop = $(window).scrollTop();
          if (currentTop < this.previousTop) {
              if (isMobile.matches){
                $(".header").css("opacity", "1");
                $(".leftsidebar").css("opacity", "1");
              }
              $(".footer").css("opacity", "1");
          } else {
              if (isMobile.matches){
                $(".header").css("opacity", "0");
                $(".leftsidebar").css("opacity", "0");
                var h = document.getElementById("list-nav-left");
                h.className = h.className.replace(" w3-show", " ");
                var h = document.getElementById("list-nav");
                h.className = h.className.replace(" w3-show", " ");
              }
              $(".footer").css("opacity", "0");
          }
          this.previousTop = currentTop;
      });
      // END Hide Header on on scroll down

 });

function change_color(e){
  document.getElementById("home-left-1").className = "w3-light-grey";
  document.getElementById("home-left-2").className = "w3-light-grey";
  document.getElementById("home-left-3").className = "w3-light-grey";
  document.getElementById("home-left-4").className = "w3-light-grey";
  document.getElementById("home-left-5").className = "w3-light-grey";
  document.getElementById("home-left-6").className = "w3-light-grey";
  document.getElementById("home-left-7").className = "w3-light-grey";
  document.getElementById(e).className = "w3-blue";
}

// Show and hide dropdown
function showDropDown(e){
  document.getElementById("leftsidebar").style.display = "block";
  document.getElementById("home-main").className = "w3-dark-grey";
  document.getElementById("proj-def").className  = "w3-dark-grey";
  document.getElementById("serv-def").className  = "w3-dark-grey";
  // document.getElementById("serv-mgmt").className = "w3-dark-grey";
  document.getElementById(e).className = "w3-blue";
  // document.getElementById("home-left-1").className = "w3-blue";
  // document.getElementById("home-left-2").className = "w3-light-grey";
  // document.getElementById("home-left-3").className = "w3-light-grey";
  // document.getElementById("home-left-4").className = "w3-light-grey";
  // document.getElementById("home-left-5").className = "w3-light-grey";
  // document.getElementById("home-left-6").className = "w3-light-grey";
  // document.getElementById("home-left-7").className = "w3-light-grey";
  document.getElementById("content-div").style.marginLeft = "200px";
  document.getElementById("footer-div").style.marginLeft  = "200px";
}
function hideDropDown(e){
  document.getElementById("leftsidebar").style.display = "none";
  document.getElementById("home-main").className = "w3-dark-grey";
  document.getElementById("proj-def").className  = "w3-dark-grey";
  document.getElementById("serv-def").className  = "w3-dark-grey";
  // document.getElementById("serv-mgmt").className = "w3-dark-grey";
  document.getElementById(e).className = "w3-blue";
  document.getElementById("content-div").style.marginLeft = "0px";
  document.getElementById("footer-div").style.marginLeft  = "0px";
}

// Show and hide list navigation when in small window
function showListNav() {
    var d = document.getElementById("list-nav");
    var h = document.getElementById("list-nav-left");
    if (h.className.indexOf("w3-show") != -1)h.className = h.className.replace(" w3-show", " ");
    if (d.className.indexOf("w3-show") == -1) {
        d.className += " w3-show";
    } else {
        d.className = d.className.replace(" w3-show", "");
    }
}
function hideListNav(e) {
  var d = document.getElementById("list-nav");
  d.className = d.className.replace(" w3-show", "");
  document.getElementById("list-nav-1").className = "w3-dark-grey";
  document.getElementById("list-nav-2").className = "w3-dark-grey";
  document.getElementById("list-nav-3").className = "w3-dark-grey";
  // document.getElementById("list-nav-4").className = "w3-dark-grey";
  document.getElementById(e).className = "w3-blue";
}

// Show and hide list navigation when in small window
function showListNavLeft() {
    var d = document.getElementById("list-nav-left");
    var h = document.getElementById("list-nav");
    if (h.className.indexOf("w3-show") != -1)h.className = h.className.replace(" w3-show", " ");
    if (d.className.indexOf("w3-show") == -1) {
        d.className += " w3-show";
    } else {
        d.className = d.className.replace(" w3-show", "");
    }
}
function hideListNavLeft(e) {
  var h = document.getElementById("list-nav-left");
  h.className = h.className.replace(" w3-show", "");
  document.getElementById("list-nav-left-1").className = "w3-dark-grey";
  document.getElementById("list-nav-left-2").className = "w3-dark-grey";
  document.getElementById("list-nav-left-3").className = "w3-dark-grey";
  document.getElementById("list-nav-left-4").className = "w3-dark-grey";
  document.getElementById("list-nav-left-5").className = "w3-dark-grey";
  document.getElementById("list-nav-left-6").className = "w3-dark-grey";
  document.getElementById("list-nav-left-7").className = "w3-dark-grey";
  document.getElementById(e).className = "w3-blue";

  // change right side to home
  document.getElementById("list-nav-1").className = "w3-blue";
  document.getElementById("list-nav-2").className = "w3-dark-grey";
  document.getElementById("list-nav-3").className = "w3-dark-grey";
  document.getElementById("list-nav-4").className = "w3-dark-grey";
}

// resixe iframe when object is loaded
function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
