
function topOfPage() {
    // Show topOfPage link if content exceeds browser height and exceeds height of footer and right column (else there's no room for the link)
    try {
        if (($(document).height() > $(window).height()) && ($(document).height() > 785)) {
            $(".topOfPage").css("display","block");
            $(".backPreviousPage").css("display","block");

                if ($(".topOfPage").css("display") == "none") {
                    $(".topOfPage").css("display", "block");
                }
                if ($(".backPreviousPage").css("display") == "none") {
                    $(".backPreviousPage").css("display", "block");
                }
                offset = ($(document).scrollTop() + $(window).height() - 40);
                // Not too high or low?
                if (offset < 650) offset = 650;
                if ($(document).height() - offset < 422) offset = $(document).height() - 422;
                // Let's go...
                $(".topOfPage").animate({ top: offset + "px" }, { duration: 0, queue: false });
                $(".backPreviousPage").animate({ top: offset + "px" }, { duration: 0, queue: false });

            $(window).scroll(function() {
                if ($(".topOfPage").css("display") == "none") {
                    $(".topOfPage").css("display", "block");
                }
                if ($(".backPreviousPage").css("display") == "none") {
                    $(".backPreviousPage").css("display", "block");
                }
                offset = ($(document).scrollTop() + $(window).height() - 40);
                // Not too high or low?
                if (offset < 650) offset = 650;
                if ($(document).height() - offset < 422) offset = $(document).height() - 422;
                // Let's go...
                $(".topOfPage").animate({ top: offset + "px" }, { duration: 0, queue: false });
                $(".backPreviousPage").animate({ top: offset + "px" }, { duration: 0, queue: false });
            });
        }
    } catch (ex) {
        //alert(ex);
    }
}

$(document).ready(function() {
    topOfPage();

    // BUTTON BACK
    $('a.but_back').click(function(e){
        e.preventDefault();
        history.go(-1);
    });

    // BUTTON UP EFFECT
    $('a[href=#globalwrapper]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
	});

});
