// jQuery SmoothScroll | Version 11-03-14
//plugin
jQuery.fn.topLink = function(settings) {
    settings = jQuery.extend({
      min: 1,
      fadeSpeed: 200,
      ieOffset: 50
    }, settings);
    return this.each(function() {
      //listen for scroll
      var el = $(this);
      el.css('display','none'); //in case the user forgot
      $(window).scroll(function() {
        //stupid IE hack
        if(!jQuery.support.hrefNormalized) {
          el.css({
            'position': 'absolute',
            'top': $(window).scrollTop() + $(window).height() - settings.ieOffset
          });
        }
        if($(window).scrollTop() >= settings.min)
        {
          el.fadeIn(settings.fadeSpeed);
        }
        else
        {
          el.fadeOut(settings.fadeSpeed);
        }
      });
    });
  };

/*jQuery.fn.topLink = function(settings) {
  settings = jQuery.extend({
    min: 1,
    fadeSpeed: 200
  }, 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);
      }
    });
  });
};
*/
$(document).ready(function() {
  //set the link
  $('#top-link').topLink({
    min: 400,
    fadeSpeed: 500
  });
  //smoothscroll
  $('#top-link').click(function(e) {
    e.preventDefault();
    $.scrollTo(0,300);
  });
});


$(document).ready(function() {

   $('a[href*=#]').click(function() {

      // duration in ms
      var duration=500;

      // easing values: swing | linear
      var easing='swing';

      // get / set parameters
      var newHash=this.hash;
      var target=$(this.hash+', a[name='+this.hash.slice(1)+']').offset().top - 20;
      var oldLocation=window.location.href.replace(window.location.hash, '');
      var newLocation=this;

      // make sure it's the same location      
      if(oldLocation+newHash==newLocation)
      {
         // set selector
         if($.browser.safari) var animationSelector='body:not(:animated)';
         else var animationSelector='html:not(:animated)';

         // animate to target and set the hash to the window.location after the animation
         $(animationSelector).animate({ scrollTop: target }, duration, easing, function() {

            // add new hash to the browser location
            //window.location.href=newLocation;
         });

         // cancel default click action
         return false;
      }
   });

});
