/*********************************************
*               JQUERY EASING                *
*  http://gsgd.co.uk/sandbox/jquery/easing/  *
*********************************************/

jQuery.extend(jQuery.easing,
{
    easeInOut: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
        return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
    },
    easeIn: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t + b;
    },
    easeOut: function (x, t, b, c, d) {
        return -c * ((t = t / d - 1) * t * t * t - 1) + b;
    }
});




/**********************************
*  FUNCTIONS CALLED ON PAGE LOAD  *
**********************************/

function loadGlobalBackToTop() {
    var tophide = 770,
        offset = 120,
		maxOffset = 350,
		timer,
		button = $('#freequotemenu'),
		buttonHeight = button.height();
    if ($(document).scrollTop() <= tophide) {
        button.css({ opacity: 0 });
    }
    button.show();
    animate();
    $(window).bind('scroll resize', function () {
        clearTimeout(timer);
        timer = setTimeout(animate, 20);
    });
    function animate() {
	/*
        var aniTop = $(document).scrollTop() + $(window).height() - buttonHeight - offset,
			alpha = $(document).scrollTop() > tophide ? 1 : 0;
        aniTop = Math.min(parseInt($(document).height()) - maxOffset, aniTop);
	*/
		var aniTop = $(document).scrollTop() + 10,
			alpha = $(document).scrollTop() > tophide ? 1 : 0;
        button.stop().animate({ top: aniTop, opacity: alpha }, 500, 'easeOut');
    }
}


/****************************
*         PAGE LOAD         *
****************************/

$(function () {

    loadGlobalBackToTop();

});
