//http://www.webresourcesdepot.com/smart-floating-banners/

$(document).ready(function(){
    $(window).scroll(function(){
        //Only change to the scrolling behavior when there is enough window
        // height to do so.
        if ($(window).height() >= $("#toc").height() ){
            // first we hide the returnTOC links
            if (jQuery.support.boxModel != '6.0'){
                $(".returnTOC").css("display", "none");
            }
            //Then we determine what position to put the TOC
            if  ($(window).scrollTop() > $(".tocIdentifier").offset({
                scroll: false
            }).top){
                $("#toc").css("position", "fixed");
                $("#toc").css("top", "0");
            }
            if  ($(window).scrollTop() <= $(".tocIdentifier").offset({
                scroll: false
            }).top){
                $("#toc").css("position", "relative");
                $("#toc").css("top", $(".tocIdentifier").offset);
            }
        }
        
        //If there isn't enough window height for scrolling then we need to 
        // display the return to TOC links
        if ($(window).height() < $("#toc").height()) {
            $(".returnTOC").css("display", "block");            
        }







    });
});


