/**
 * Created by JetBrains PhpStorm.
 * User: j.castrop
 * Date: 13-10-11
 * Time: 9:55
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function() {
    var animating = false;

    $(window).scroll(function(){
        SlideInBottom();
    });

    function SlideInBottom() {
        var sTop = $(window).scrollTop();
        var wHeight = $(window).height();
        var bHeight = $('body').height();

        var scrolled = wHeight + sTop;
        var showAt = bHeight - 50;
        var isVisible = $( "#cfTool" ).is(":visible");


        if (!isVisible && scrolled > showAt) {
            if(!animating) {
                animating = true;
                $( "#cfTool" ).show('slide', { direction: "down" }, function(){
                     animating = false;
                });
            } else {
                $( "#cfTool" ).show();
                 animating = false;
            }
        }

        if(isVisible &&  scrolled < showAt - 300 && !animating) {
             animating = true;
            $( "#cfTool" ).hide('slide', { direction: "right" }, function(){
                 animating = false;
            });
        }
    }
});
