/**************************************************

Simple DIV-Scroller for modern DOM-capable Browsers

Written by Sebastian Bechtold

sebastian_bechtold@web.de

You may use this script for whatever you want,
but please don't remove this note about its origin.

Thanks :)

**************************************************/

var scrollers = new Array();

function ScrollableLayer(id) {
	
	this.contentLayer = document.getElementById(id);
	
	this.drawerline = document.getElementById('drawerline' + id);
	
	this.drawer = document.getElementById('drawer' + id);
	
	this.scrollframe = document.getElementById('scrollframe' + id);
		
	this.scrollHeight = this.contentLayer.offsetHeight - this.scrollframe.offsetHeight;
	//alert("id= "+id);
	this.scrollWidth = this.contentLayer.offsetWidth - this.scrollframe.offsetWidth;
	
	this.contentLayer.style.position = 'relative';
	this.scrollframe.style.position = 'absolute';
}


//function start_scroll(id, speed) {
function start_scroll(id, speed, direction) {
	
	scrollers[id] = new ScrollableLayer(id);
	
	new_id = id;
	new_speed = speed;

	if (direction == 'horizontal') {
		//alert('horizontal');
		scrollers[id].timer = window.setInterval("scroll(new_id, new_speed);",20);
	} else {
		//alert('vertical');
		scrollers[id].timer = window.setInterval("scroll_vertical(new_id, new_speed);",20);
	}
	//alert(id);
}


function stop_scroll(id) {
	window.clearInterval(scrollers[id].timer);
}


function scroll(id, speed) {
	
	y_new = scrollers[id].contentLayer.offsetTop + speed;
	//alert(id);

	if (y_new <= 0 && y_new >= -scrollers[id].scrollHeight) {
		scrollers[id].contentLayer.style.top = y_new +'px';

		if(scrollers[id].drawer && scrollers[id].drawerline) {
			scrollers[id].drawer.style.top = scrollers[id].drawerline.offsetTop - (scrollers[id].drawerline.offsetHeight - scrollers[id].drawer.offsetHeight) * (y_new / scrollers[id].scrollHeight) +'px';
		}
	} else {
		height = 0;
		
		if (y_new < -scrollers[id].scrollHeight) {
			height = scrollers[id].scrollHeight;
		}

		stop_scroll(id);
		//start_scroll(id, height + y_new);
		start_scroll(id, height + y_new, 'horizontal');
	}
}

function scroll_vertical(id, speed) {
	x_new = scrollers[id].contentLayer.offsetLeft + speed;

	if (x_new <= 0 && x_new >= -scrollers[id].scrollWidth) {
		scrollers[id].contentLayer.style.left = x_new +'px';

		if(scrollers[id].drawer && scrollers[id].drawerline) {
			scrollers[id].drawer.style.left = scrollers[id].drawerline.offsetLeft - (scrollers[id].drawerline.offsetWidth - scrollers[id].drawer.offsetWidth) * (x_new / scrollers[id].scrollWidth) +'px';
		}
	} else {
		width = 0;
		
		if (x_new < -scrollers[id].scrollWidth) {
			width = scrollers[id].scrollWidth;
		}

		stop_scroll(id);
		start_scroll(id, width + x_new, 'vertical');
	}
}