﻿//Animate to any anchors instead of boring jump
$(function () {
    $('a[href^="#"]').each(function () {
        var target = $(this).attr('href').substr(1);
        $(this).click(function () {
            LoadFeatureHash(target);
        });
    });
});

function LoadFeatureHash(target) {
    var jqTarget = $('a[name="' + target + '"]');
    if (jqTarget.length > 0) {
        var targetTop = jqTarget.offset().top - 70;

        if (jqTarget.parent().hasClass('feature')) {
            targetTop = $('.featureWrapper').offset().top - 70;
        }

        $('html,body').animate({ scrollTop: targetTop }, 400);

        if (jqTarget.parent().hasClass('feature')) {
            $('a[href^="#"]').removeClass('on');
            $('a[href="#' + target + '"]').addClass('on');

            $('.feature:visible').fadeOut(300, function () {
                jqTarget.parent().fadeIn(300);
            });
        }
    }
}
