var Scroll = function(up,dn,sb,sc,cc){
	var objU = null;
	var objD = null;
	var objSB = null;
	var objSC = null;
	var objC = null;
	
	var id_timeout = null;
	var direct=0;
	var id_s = null;
	
	var findObj = function(theObj){
		var ret = theObj;
		if(typeof(theObj)!='object'&&typeof(theObj)=='string'){
			if(document.getElementById) ret = document.getElementById(theObj);
			if(typeof(ret)=='undefined'||!ret) if(document.all) ret = document.all[theObj];
			if(typeof(ret)=='undefined'||!ret) ret = null;
		}
		return ret;
	}
	
	objU = findObj(up);
	objD = findObj(dn);
	objSB = findObj(sb);
	objSC = findObj(sc);
	objC = findObj(cc);
	
	this.init = function(){
		if(objSC){
			objSC.svT = parseInt(objSC.style.top);//objSC.offsetTop;
			objSC.svB = objSC.svT+parseInt(objSB.style.height,10)-parseInt(objSC.style.height,10);
			objSC.startY = objSC.svT;
			objSC.style.top = objSC.svT+'px';
			//objSC.style.left='0px';
			//objSC.style.left=(objSC.offsetLeft-(parseInt(objSC.style.width,10)/2))+'px';
			objSC.onmousedown=function(){div_event_mousedown(arguments[0]);};
			//objSC.style.top = get_pos_sc();
		}
	}
	
	var div_event_mousedown = function(e){
		e = window.event?window.event:e;
		objSC.startY=e.clientY-objSC.offsetTop;
		document.onmousemove=doc_event_mousemove;
		document.onmouseup=doc_event_mouseup;
	}
	var doc_event_mousemove = function(e){
		e = window.event?window.event:e;
		var top;
		top=e.clientY-objSC.startY;
		if(top<=objSC.svT){
			top = objSC.svT;
		}else if(top>=objSC.svB){
			top = objSC.svB;
		}
		objSC.style.top=top+'px';
		//window.status=(top-objSC.svT)+'/'+(objSC.svB-objSC.svT)+'::'+objC.scrollTop+'/'+(objC.scrollHeight-objC.offsetHeight);
		objC.scrollTop = (top-objSC.svT)/(objSC.svB-objSC.svT)*(objC.scrollHeight-objC.offsetHeight);
	}
	var doc_event_mouseup = function(e){
		document.onmousemove=null;
		document.onmouseup=null;
	}
	
	var get_pos_sc=function(){
		return (objSC.svB-objSC.svT)*objC.scrollTop/(objC.scrollHeight-objC.offsetHeight)+objSC.svT;
	}
	this.scrollC=function(){
		if(arguments.length>0){
			direct = isNaN(parseInt(arguments[0]))?0:parseInt(arguments[0]);
			id_s = arguments.length>=2?arguments[1]:null;
		}
		if(direct==0){
			if(id_timeout!=null&&id_timeout){
				clearTimeout(id_timeout);
			}
		}else{
			objC.scrollTop+=10*direct;
			objC.scrollTop=objC.scrollTop<=0?0:objC.scrollTop;
			var top = get_pos_sc();
			objSC.style.top=top+'px';
			setTimeout(id_s,100);
		}
	}
}

