$(document).ready(function() {
    // fade animation for block links
    $('.section-block, .story-block').hover(
        function () {
          $(this).animate({ opacity: 0.6 }, 300);
        }, 
        function () {
          $(this).animate({ opacity: 1 }, 300);
        }
    ).click( function() {
        window.location = $(this).find('.read-more').attr('href');
    });
    
    // animation for anchor links
    $(".anchor-link").click( function(){
        var currentLocation = window.location.href;
        if ( currentLocation.indexOf("#", 0) > 0 ) {
            var currentPath = currentLocation.substr(0,currentLocation.indexOf("#", 0));
        } else {
            var currentPath = currentLocation;
        }
        
        var gotoLocation = this.href;
        if ( gotoLocation.indexOf("#", 0) > 0 ) {
            var gotoPath = gotoLocation.substr(0,gotoLocation.indexOf("#", 0));
        } else {
            var gotoPath = gotoLocation;
        }
        
        if( currentPath == gotoPath) {
            anchorScroll( this.hash, '106' );
        }
    });
});

// animate anchor link scroll
$(window).load(function () {
    if( window.location.hash != '') {
        anchorScroll( window.location.hash, '106' );
    }
});

// Scroll to an anchor on the page
function anchorScroll( anchorName, anchorOffset ) {
    var destination = $(anchorName).offset().top - anchorOffset;
    $("html:not(:animated),body:not(:animated)").animate( {scrollTop: destination }, 600 );
}

// Animates the slides on the home page
function startMarqueeSlideshow() {
    $('#marquee-slides').bxSlider({
        auto: true,
        controls: true,
        pause: 7000,
        nextText: '',
        prevText: ''
    });
}

// Sets up the floating scrollbar
function activateFloatingScroll() {
    $.waypoints.settings.scrollThrottle = 30;
    $('#scrollpoint').waypoint(function(event, direction) {
        $('#subnav-container').toggleClass('sticky', direction === "down");
        event.stopPropagation();
    });
}
