function updateBackToTopButton()
{
	var wdw = $(window);
	var button = $('#back-to-top-button');
	var content2 = $('#content2');
	var leftSide = content2.find('> div.leftSide');
	var rightSide = content2.find('> div.rightSide');

	min = content2.offset().top;
	max = min + content2.outerHeight() - button.outerHeight();

	var top = (wdw.height() / 2) - (button.outerHeight() / 2) + wdw.scrollTop();
	if( top < min ) top = min;
	if( max < top ) top = max;

	left = ((rightSide.offset().left + leftSide.offset().left + leftSide.outerWidth()) / 2) - (button.outerWidth() / 2);

	button.css('top', top);
	button.css('left', left);
}

$(document).ready(function(){
	var backToTop = $('<img src="' + BlueMoonIt_App.basePath + 'styles/topfysio/default/images/back-to-top.png" id="back-to-top-button" />');

	backToTop.css('position', 'absolute');
	backToTop.css('top', '0');
	backToTop.css('cursor', 'pointer');
	backToTop.css('z-index', '999');

	var content2  = $('#content2');
	content2.append(backToTop);

	backToTop.bind('click', function() {
		$(window).scrollTop(0);
	});

	updateBackToTopButton();
});

$(window).scroll(updateBackToTopButton);
$(window).resize(updateBackToTopButton);
