/**
* General JS Functions
* @requires jQuery library
*/

jQuery(function(){
    
    // Hide all back to top elements
    jQuery('A[href="#top"]').hide();
    
    // When the window is scrolled down, fadeIn all back to top elements
    // When returning back to top, fade out again
    jQuery(window).scroll(function(){
        // What to do when the page is scrolling
        if(jQuery(window).scrollTop() == 0) {
            jQuery('A[href="#top"]').fadeOut();        
        } else {
            jQuery('[href="#top"]').fadeIn();        
        }
    });
    
    // When a back to top element is clicked, animate the scrollTop
    jQuery('A[href="#top"]').click(function(e){
        // Prevent default action
        e.preventDefault();
        // Animate scroll to top
        jQuery('HTML,BODY').animate({ scrollTop : 0 }, 500);
    });
    
});
