(function ($) {

    $.extend({

        smoothAnchors: function (speed, easing, redirect) {

            speed = speed || "fast";
            easing = easing || null;
            redirect = (redirect === true || redirect == null) ? true : false;
            page = window.location.toString();
            
            $("a").each(function (i) {

                var url = $(this).attr("href");

                if (url) {

                    if (url.indexOf("#?") != -1 && url.indexOf("#?") > 0) {

                        var aParts = url.split("#?", 2);
                        var anchor = $("a[name='" + aParts[1] + "']");
 
                        if (anchor && page.indexOf(aParts[0]) != -1) {

                            $(this).click(function () {

                                if ($(document).height() - anchor.offset().top >= $(window).height()
								 || anchor.offset().top > $(window).height()
								 || $(document).width() - anchor.offset().left >= $(window).width()
								 || anchor.offset().left > $(window).width()) {

                                    $('html, body').animate({
                                        scrollTop: anchor.offset().top - 125,
                                        scrollLeft: anchor.offset().left
                                    }, speed, easing);

                                }

                                return false;

                            });
                        }

                    }

                }

            });

        }

    });

})(jQuery);


(function ($) {

    $.extend({

        smoothAnchorsOnLoad: function (speed, easing) {

            speed = speed || "fast";
            easing = easing || null;

            var anchor = $("a[name*='" + window.location.hash.replace('#?', '') + "']")

            if (anchor.offset()) {
                if ($(document).height() - anchor.offset().top >= $(window).height()
					 || anchor.offset().top > $(window).height()
					 || $(document).width() - anchor.offset().left >= $(window).width()
					 || anchor.offset().left > $(window).width()) {

                    $('html, body').animate({
                        scrollTop: anchor.offset().top - 125, // -127px, fixed header
                        scrollLeft: anchor.offset().left
                    }, speed, easing);
                }
            }

        }

    });


})(jQuery);