jQuery.fn.exists = function () {
    return jQuery(this).length > 0
};
var setWindowLocation = function (a) {
    window.location.hash = a
};
$(document).ready(function () {
    $("a").css("outline", "none");

});

var amountVisible = function (c) {
    var a = $(window).scrollTop();
    var b = a + $(window).height();
    var e = c.offset().top;
    var d = e + c.height();
    if (d > a && d < b) {
        return d - a
    } else {f
        return b - e
    }
};
var fetchMatchingNavItem = function (a) {
    return $("#" + $(a).attr("id") + "-link").parent()
};
var setCurrentClass = function (a) {
    a.addClass("current");
    a.siblings("#nav li").removeClass("current")
};
var determineCurrentNodeAndSetNav = function () {
    var a = null;
    var b = $(".scroll-item:in-viewport");
    if (b.get(0).id == "header") {
        a = b.get(0)
    } else {
        b.each(function (c) {
            var d = $(this);
            if (a == null || amountVisible(d) >= amountVisible(a)) {
                a = d
            }
        })
    }
    current_index = $(".scroll-item").index(a);
    if (a && a.id == "header") {
        $("#nav ol li").removeClass("current")
    } else {
        setCurrentClass(fetchMatchingNavItem(a))
    }
};
$(document).ready(function () {
    var c = $(".scroll-item");
    var b = 0;
    var a;
    $(window).scroll(function () {
        determineCurrentNodeAndSetNav();
    });
    $("#gracepoint").click(function (d) {
        $.scrollTo("#header", 800);
        a = $("#header");
        b = c.index(a);
        d.preventDefault()
    });
    $("#nav ol li").click(function (f) {
        var d = $(this).children("a").get(0).href.split("#")[1];
        $.scrollTo("#" + d, 800);
        a = $("#" + d);
        b = c.index(a);
        f.preventDefault()
    });
    $(".scroll-link").click(function (g) {
        var d = $(this);
        var f = d.attr("href").split("#")[1];
        var h = $($("#" + f + "-link").parent());
        $.scrollTo("#" + f, 800);
        a = $("#" + f);
        b = c.index(a);
        g.preventDefault()
    });
    $(document).keydown(function (d) {
        switch (d.keyCode) {
        case 39:
            a = c[++b];
            if (a) {
                $.scrollTo(a, 800)
            } else {
                b = c.length - 1
            }
            break;
        case 37:
            a = c[--b];
            if (a) {
                $.scrollTo(a, 800)
            } else {
                b = 0
            }
            break
        }
    })
});

$(function () {
 
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
 
  if (!msie6) {
    var top = $('#main_nav').offset().top - parseFloat($('#main_nav').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
     
      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        $('#main_nav').addClass('fixed');
      } else {
        // otherwise remove it
        $('#main_nav').removeClass('fixed');
      }
    });
  }  
});

