$("document").ready(function() {
	$('.top-link').click(function() {
  	$('html, body').animate({
    	scrollTop: 0
    }, 300);
  });
  $('.top-link').topLink({
    min: 50,
    fadeSpeed: 300
  });
});

jQuery.fn.topLink = function(settings) {
  settings = jQuery.extend({
    min: 1,
    fadeSpeed: 300
  }, settings);
  return this.each(function() {
    //listen for scroll
    var el = $(this);
    el.hide(); //in case the user forgot
    $(window).scroll(function() {
      if($(window).scrollTop() >= settings.min) {
        el.fadeIn(settings.fadeSpeed);
      } else {
        el.fadeOut(settings.fadeSpeed);
      }
    });
  });
};
