var scrolling;
scrolling=false;

var lastscrollbox;
lastscrollbox="";

var dragging;
dragging=false;

var dragscreeninitial;
var dragtopinitial;

var scrollmarkermargin=20;
var scrollmarkerheight=15;

function onscrollmousemove(e) {
	if (!e) e=window.event;
	
	if (dragging) {
		var pos=cmsgetpos(e);

		var loop=getmarker().offsetParent;
		while (loop) {
			if (loop.offsetTop) pos[1]-=loop.offsetTop;
			loop=loop.offsetParent;
		}
		

		
		var newtop;
		newtop=pos[1]-scrollmarkerheight;
		
		if (newtop<0) newtop=0;
		if (newtop>scrollbarplay()) newtop=scrollbarplay();
		
		
		
		getmarker().style.top=(newtop-scrollmarkermargin)+"px";
		
		if (viewheight()>=contentheight()) newtop=0;
		
		getscrollcontent().style.top=-newtop*(contentheight()-viewheight())/scrollbarplay()+"px";
	}
}


function cancelclick(event) {
	if (!event) return;
	if (event.stopPropagation)	event.stopPropagation(); else event.cancelBubble=true;
}

// objects

function getmarker() {
	return document.getElementById("markerscroll"+lastscrollbox);
}

function getscrollcontent() {
	return document.getElementById("scroll"+lastscrollbox);
}

function getscrollviewport() {
	return document.getElementById("scrollviewport"+lastscrollbox);
}

function getscrollbar() {
	return document.getElementById("scrollbar"+lastscrollbox);
}

// metrtics

function objectheight(obj) {
	var h;
	h=obj.clientHeight;
	if (h==0) h=obj.offsetHeight;
	
	return h;
}

function viewheight() {
	var viewport=getscrollviewport();
	return objectheight(viewport);
}

function contentheight() {
	var content=getscrollcontent();
	return objectheight(content);
}

function scrollbarheight() {
	var scrollbar=getscrollbar();
	return objectheight(scrollbar);
}

function scrollbarplay() {
	return scrollbarheight()-scrollmarkerheight;
}

// movement

function scrolldrag(e,boxid) {			
	if (!e) e=window.event;
	lastscrollbox=boxid;
	dragging=true;
}
