


function Scrollbar(t, c){
	this.container=document.getElementById(t);
	this.content=document.getElementById(c);
	this.content.style.left=0;
	this.content.style.top=0;
	this.width=this.content.offsetWidth;
	this.height=this.content.offsetHeight;
	this.step=1;
	this.interval=40;

	this.timeticket=0;


	this.containerWidth=this.container.offsetWidth;
	this.containerHeight=this.container.offsetHeight;


	this.speed=arguments[2] ? arguments[2] : 200;
	this.dir='';
	this.stopscroll=true;

	this.scrolls=function(){
		dir=arguments[0] ? arguments[0] : this.dir;
		if(dir=='right'){
			if(parseInt(this.content.style.left)>(this.width*(-1)+ this.containerWidth)){
				this.content.style.left=parseInt(this.content.style.left)-this.step +"px"; //move scroller upwards
			}
		}
		else if(dir=='left'){
			if(parseInt(this.content.style.left)<=0){ //if scroller hasn't reached the end of its height
				this.content.style.left=parseInt(this.content.style.left)+this.step +"px"; //move scroller upwards
			}
		}
		else if(dir=='down'){
			if(parseInt(this.content.style.top)>(this.height*(-1)+ this.containerHeight)){
				this.content.style.top=parseInt(this.content.style.top)-this.step +"px"; //move scroller upwards
			}
		}
		else if(dir=='up'){
			if(parseInt(this.content.style.top)<=0){ //if scroller hasn't reached the end of its height
				this.content.style.top=parseInt(this.content.style.top)+this.step +"px"; //move scroller upwards
			}

		}
	}

	this.scroll=function(dir){
		this.dir=dir;
		this.stopscroll=false;
		this.doscrolling();
	}

	this.pause=function(){
		this.stopscroll=true;
	}

	this.doscrolling=function(){
		this.scrolls();
		if(this.timeticket)clearTimeout(this.timeticket);
		if(!this.stopscroll){
			this.timeticket=setTimeout(this.vname+".doscrolling()", this.interval);
		}

	}

}

function Scrollbar_create(vname, container,content,left,right,up,down){
	var	scontainer=document.getElementById(container);
	var scontent=document.getElementById(content);
	var sleft=document.getElementById(left);
	var sright=document.getElementById(right);
	var sup=document.getElementById(up);
	var sdown=document.getElementById(down);

	if(scontainer && scontent){
		scontainer.style.position='relative';
		scontainer.style.overflow='hidden';
		scontent.style.position='absolute';

		eval(vname+"=new Scrollbar('"+container+"','"+content+"');");
		eval(vname+".step=8;");
		eval(vname+".vname='"+vname+"';");

		var a=['left','right','up','down'];
		var r;
		for(var i=0;i<a.length;i++){
			eval("r=s"+a[i]+';');
			if(r){
				eval("s"+a[i]+".onmouseover=function(){this.style.cursor='pointer';"+vname+".scroll('"+a[i]+"');};");
				eval("s"+a[i]+".onmouseout=function(){this.style.cursor='normal';"+vname+".pause();};");
			}
		}

	}

}


var scrolls=[];
function makescroll(){
	var e;
	for(var i=0;i<scrolls.length;i++){
		e=scrolls[i];
		if(typeof(e)=='object' ){
			p=e.postfix;
		}
		else{
			p=e;
		}
		Scrollbar_create('scrollbar'+p,'scontainer'+p,'scontent'+p,'sleft'+p,'sright'+p,'sup'+p,'sdown'+p);

	}

}






