﻿function setUp() {

    // get window height
    if (typeof (window.innerHeight) == 'number') {
        /* Non-IE */
        winH = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        /* IE 6+ in 'standards compliant mode' */
        winH = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        /*IE 4 compatible*/
        winH = document.body.clientHeight;
    }
 
    // set trigger zone for scroll
    setD = parseInt(winH * 2 / 3);
    setU = parseInt(winH * 1 / 5);
    
    // scroll speed control, in pixels/mousemove
    pix = 16

    // scroll speed control time setTimeout, in milliseconds
    time = 10
}

function resetScroll() {
    document.getElementById("scrollState").value = 'true';
}

function scrollMe(e) {

    setUp();

    // capture the mouse position
    var posy = 0;

    if (!e) var e = window.event;

    if (e.pageY) {
        posy = e.pageY;
    }
    else if (e.clientY) {
        posy = e.clientY;
    }

    // initialize the scrollBy parameters
    y = 0;

    // set the new scrollBy parameters
    if (posy < setU) {
        y = 0 // -(pix/2);
        scroller(y);
        document.getElementById("scrollState").value = 'true';
    }
    if (posy > setD && document.getElementById("scrollState").value == 'true') {
        y = pix;
        scroller(y);
        document.getElementById("scrollState").value = 'false';
    }
}

function scroller(y) {

    window.scrollBy(0, y);
    zz = setTimeout('scroller(' + (y-1) + ')', time + 10);
    
    if (y < 0) {
        clearTimeout(zz);
    }
}
