﻿var useFloat = "";
var slideTimer = "";
var initTop = 0;
var nScrollTop = 0;
var prevVal = 0;
var currVal = 0;
var throttlePx = 0;
var resizeTick = 0;
var IE = true;
if (navigator.appName != "Microsoft Internet Explorer") { IE = false }

function realign() {

    if (!IE) {
        init();
    }
    if (IE && resizeTick == 2) {
        self.location.reload();
    }
    resizeTick++;
}

function throttle() {

    clearTimeout(slideTimer);
    throttlePx += Math.floor((nScrollTop - throttlePx) * .5);
    useFloat.style.top = initTop + throttlePx + "px";
    if (Math.abs(throttlePx - nScrollTop) > 1) {
        setTimeout("throttle()", 40);
    }
    else {
        useFloat.style.top = initTop + nScrollTop + "px";
        slideTimer = setTimeout("stayHome()", 500);
    }
}

function stayHome() {

    if (document.documentElement && document.documentElement.scrollTop) {
        nScrollTop = document.documentElement.scrollTop;
        document.getElementById('nScroll').value = nScrollTop;
    }
    else {
        nScrollTop = document.body.scrollTop;
        document.getElementById('nScroll').value = nScrollTop;
    }
    prevVal = document.getElementById('nScroll').value;
    if (prevVal == currVal) {
        clearTimeout(slideTimer);
        if (Number(nScrollTop) + Number(initTop) != useFloat.offsetTop) {
            throttle();
        }
    }
    currVal = document.getElementById('nScroll').value;
    prevVal = currVal;
    slideTimer = setTimeout("stayHome()", 500);
}

function init() {

    useFloat = document.getElementById('isFloat');
    if (!document.body.scrollTop) {
        useFloat.style.top = "95%";
        useFloat.style.left = "20px";
    }
    else {
        useFloat.style.top = "95%";
        useFloat.style.left = "20px";
    }
    initTop = useFloat.offsetTop;
    stayHome();
}

onload = init;
onresize = realign;