require(['jquery'], function($){

$(document).ready(function(){
	// text button
        var text="Go to top"; // This text appear when you hover the button back to top
        var displaymode=""; // If empty the button displays in all modes, if you want to display it for the view mode put "view" or                if you want to display it for the edit mode put "edit"  

	// create #back-top button
        $( 'body' ).append( '<span id="back-top"><a href="#top"></a><span>'+text+'</span></span>' );
        
	// hide text span if is empty 
        if(text==""){
		$('#back-top span').remove();
	}

        // display mode 
        if(displaymode=="view"){
           $('.editbody #back-top').remove();
        };
        if(displaymode=="edit"){
           $('.viewbody #back-top').remove();
        };

	// hide #back-top first
	$('#back-top').hide();
	
	// fade in #back-top
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#back-top').fadeIn();
			} else {
				$('#back-top').fadeOut();
			}
		});

		// scroll body to 0px on click
		$('#back-top a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});

});

});
