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" || navigator.appVersion.search("Safari") != -1) {
        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" || navigator.appVersion.search("Safari") != -1) {
        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" || navigator.appVersion.search("Safari") != -1) {
	    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);
    $("#" + panelDivId).mousewheel(
        function(event, delta) {
            panel_on_mousewheel(panelDiv, control, offset, delta * scrollSpeed);
            return false;
        }
    );
}

function panel_on_mousewheel(panelDiv, control, offset, scrollAmount) {
    if (offset == null) {
        offset = 0;
    }
    if (navigator.appName == "Microsoft Internet Explorer" || navigator.appVersion.search("Safari") != -1) {
        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";
    try {
        e.preventDefault();
    }
    catch (er) {
    
    }
    return false;

}


