var globalvar = null;

function ScrollClass(elem,dir,startpoint,size, show_when_inactive) {
	this.name = elem;
	this.element = ElementGetById(elem);
	this.direction = dir;
	this.pagesize = size;
	this.point = 0;
	this.offset = startpoint;
	this.startinterval = 10;
	this.delay = 50;
	this.active = true;
	if (this.direction == 'vertical') {
		this.divsize = this.element.clientHeight;
		if (this.pagesize >= this.element.clientHeight) {
			this.active = false;
		}
	} else if (this.direction == 'horizontal') {
		this.divsize = this.element.clientWidth;
		if (this.pagesize >= this.element.clientWidth) {
			this.active = false;
		}
	}
	hideitems(this.name, this.active, show_when_inactive);
	this.go = start;
	this.stop = stop;
	this.scroll = scroll;
}

function hideitems(name, active, show){
	item1 = ElementGetById(name+'scroll1');
	item2 = ElementGetById(name+'scroll2');
	item3 = ElementGetById(name+'scroll3');
	if (active == true || show == 1){
		if (show == 1 && active == false){
			item1.style.backgroundImage = backgroundImage = "url('images/blank9by9.png')";
			item1.style.cursor = "default";
			item3.style.backgroundImage = "url('images/blank9by9.png')";
			item3.style.cursor = "default";
		}
		item1.style.display = 'inline';	
		item2.style.display = 'inline';	
		item3.style.display = 'inline';	


	} 
}



function start(way) {
	if (this.active != true) {
		return;
	}
	this.scrolldir = way;
	this.interval = this.startinterval;
	this.iterations = 0;
	this.run = true;
	this.scroll();

}

function stop(){
	this.run = false;
}

function scroll() {

	if (this.run != true){
		return;
		
	}
	
	this.interval = this.startinterval + this.iterations * 2;
	switch(this.scrolldir){
	
		case 'up': 
		case 'left':
			if (this.point < 0 - this.interval) {
				this.point += this.interval;
			} else {
				this.run = false;
				this.point = 0;
			}
		break;

		case 'down':
		case 'right': 
			if (this.point > this.pagesize - this.divsize + this.interval) {
				this.point -= this.interval;
			} else {
				this.run = false;
				this.point = this.pagesize - this.divsize;
			}
		break;

		default:
			this.run = false;
		break;
	}

	if (this.direction == 'vertical'){
		this.element.style.top = (this.offset+this.point)+'px';
		this.divsize = this.element.clientHeight;
	} else {
		this.element.style.left = (this.offset+this.point)+'px';
		this.divsize = this.element.clientWidth;
	}
	this.iterations++;
 	globalvar = this
	setTimeout("globalvar.scroll()",this.delay);
}

