function scrollPanelUp(panelDivId, controlId, scrollAmount, offset) {
    var panelDiv = document.getElementById(panelDivId);
    var control = document.getElementById(controlId);
    if (offset == null) {
        offset = 0;
    }
    if (navigator.appName == "Microsoft Internet Explorer") {
        offset += 200;
    }

    panelDiv.style.top = parseInt(panelDiv.style.top) + scrollAmount + 'px';
    if (parseInt(panelDiv.style.top) > 0) {
        panelDiv.style.top = '0px';
    }
    if (parseInt(panelDiv.style.top) < -parseInt(panelDiv.scrollHeight) + offset) {
        panelDiv.style.top = -parseInt(panelDiv.scrollHeight) + offset + 'px';
    }
    control.style.top = -parseInt(panelDiv.style.top) * (parseInt(control.parentNode.style.height) - parseInt(control.style.height)) / (parseInt(panelDiv.scrollHeight) - offset) + "px";
}
function scrollPanelDown(panelDivId, controlId, scrollAmount, offset) {
    var panelDiv = document.getElementById(panelDivId);
    var control = document.getElementById(controlId);
    
    if (offset == null) {
        offset = 0;
    }
    if (navigator.appName == "Microsoft Internet Explorer") {
        offset += 200;
    }

    panelDiv.style.top = parseInt(panelDiv.style.top) - scrollAmount + 'px';
    if (parseInt(panelDiv.style.top) > 0) {
        panelDiv.style.top = '0px';
    }
    if (parseInt(panelDiv.style.top) < -parseInt(panelDiv.scrollHeight) + offset) {
        panelDiv.style.top = -parseInt(panelDiv.scrollHeight) + offset + 'px';
    }
    control.style.top = -parseInt(panelDiv.style.top) * (parseInt(control.parentNode.style.height) - parseInt(control.style.height)) / (parseInt(panelDiv.scrollHeight) - offset) + "px";
}
function control_mouse_over(control, divId, offset) {
	control.style.cursor = "pointer";
	if(control.onmousedown == null) {
		control.onmousedown = function(e) {
			control_mouse_down(control, e, divId, offset);
		};
	}
}
function control_mouse_down(control, e, divId, offset) {
    document.ondragstart = function() {
        try {
            e.preventDefault();
        }
        catch (er) { 
        }
        return false;
    };
	document.onselectstart = function()	{
	    try {
	        e.preventDefault();
	    }
	    catch (er) {
	    }
	    return false;
	};
	if (offset == null) {
	    offset = 0;
	}
	if (navigator.appName == "Microsoft Internet Explorer") {
	    offset += 200;
	}
	document.body.style.cursor = "pointer";
	var mouseStartY;
	var controlStartY;
	var divy = document.getElementById(divId);
	if(!e) e = window.event;
	mouseStartY = e.clientY;
	controlStartY = control.style.top;
	document.onmousemove = function(e) {
	    if (!e) {
	        e = window.event;
	    }
	    control.style.top = parseInt(e.clientY) - parseInt(mouseStartY) + parseInt(controlStartY) + "px";
	    if (parseInt(control.style.top) < 0) {
	        control.style.top = "0px";
	    }
	    if (parseInt(control.style.top) > parseInt(control.parentNode.style.height) - parseInt(control.style.height)) {
	        control.style.top = parseInt(control.parentNode.style.height) - parseInt(control.style.height) + "px";
	    }
	    divy.style.top = -parseInt(control.style.top) * (parseInt(divy.scrollHeight) - offset) / (parseInt(control.parentNode.style.height) - parseInt(control.style.height)) + "px";
	};
	document.onmouseup = function(e) {
	    document.body.style.cursor = "default";
	    document.ondragstart = null;
	    document.onselectstart = null;
	    document.onmousemove = null;
	    document.onmouseup = null;
	};
}

function initPanelMouseScroll(panelDivId, controlId, offset, scrollSpeed) {
    var panelDiv = document.getElementById(panelDivId);
    var control = document.getElementById(controlId);
    try {
        panelDiv.addEventListener("DOMMouseScroll", function(e) { 
            panel_on_mousewheel(panelDiv, control, offset, scrollSpeed, e);
        }, false);
    }
    catch(e) {
        panelDiv.onmousewheel = function() {
            panel_on_mousewheel(panelDiv, control, offset, scrollSpeed);
            return false;
        };
    }
}

function panel_on_mousewheel(panelDiv, control, offset, scrollSpeed, e) {
    var wheelDelta;
    var scrollAmount;
    if (offset == null) {
        offset = 0;
    }
    if (navigator.appName == "Microsoft Internet Explorer") {
        offset += 200;
    }
    try {
        wheelDelta = -e.detail; //make the wheel delta oposite sign to keep IE and FF the same
    }
    catch (er) {
        wheelDelta = window.event.wheelDelta;
    }
    if (wheelDelta < -3 || wheelDelta > 3) {
        wheelDelta /= 120; //IE says wheel delta should be plus or minus 120.  I say plus or minus 1.
    }
    else if (wheelDelta < -1 || wheelDelta > 1) {
        wheelDelta /= 3; //older versions of firefox say delta should be plus or minus 3.  I say plus or minus 1.
    }
    //Newer versions of firefox and I are in agreement.
    
    scrollAmount = wheelDelta * scrollSpeed;
    
    
    
    panelDiv.style.top = parseInt(panelDiv.style.top) + scrollAmount + 'px';
    if (parseInt(panelDiv.style.top) > 0) {
        panelDiv.style.top = '0px';
    }
    if (parseInt(panelDiv.style.top) < -parseInt(panelDiv.scrollHeight) + offset) {
        panelDiv.style.top = -parseInt(panelDiv.scrollHeight) + offset + 'px';
    }
    control.style.top = -parseInt(panelDiv.style.top) * (parseInt(control.parentNode.style.height) - parseInt(control.style.height)) / (parseInt(panelDiv.scrollHeight) - offset) + "px";
    try {
        e.preventDefault();
    }
    catch (er) {
    
    }
    return false;

}

