var sb_registry = [];
var scroll_speed = 20;
var keep_scrolling;

function scrollyBuddy (id, width, height) {
	this.id				= id;
	this.object			= id+"Content";
	this.container		= id+"Container";
	this.container_w	= width;
	this.container_h	= height;
	this.object_pos_x	= 0;
	this.object_pos_y	= 0;

	sb_registry[id] = this;

	var css  = "<style type='text/css'>";
		css += "#"+id+"Container { position: relative; overflow: hidden; width: "+width+"px; height: "+height+"px; }";
		css += "#"+id+"Content { position: absolute; left: 0; top: 0; }";
		css += "</style>";
	document.write(css);
}


scrollyBuddy.u = function (id) {
	var reg = sb_registry[id];
	var obj = document.getElementById(reg.object);

	if (reg.object_pos_y < 0) { // constrain scrolling to container
		reg.object_pos_y = reg.object_pos_y + 10;
		obj.style.top = reg.object_pos_y+"px";
		keep_scrolling = setTimeout ("scrollyBuddy.u('"+id+"')", scroll_speed);
	}
}


scrollyBuddy.d = function (id) {
	var reg = sb_registry[id];
	var obj = document.getElementById(reg.object);

	if (reg.object_pos_y > -(obj.scrollHeight - reg.container_h)) { // constrain scrolling to container
		reg.object_pos_y = reg.object_pos_y - 10;
		obj.style.top = reg.object_pos_y+"px";
		keep_scrolling = setTimeout ("scrollyBuddy.d('"+id+"')", scroll_speed);
	}
}


scrollyBuddy.l = function (id) {
	var reg = sb_registry[id];
	var obj = document.getElementById(reg.object);

	if (reg.object_pos_x > -(obj.scrollWidth - reg.container_w)) { // constrain scrolling to container
		reg.object_pos_x = reg.object_pos_x - 10;
		obj.style.left = reg.object_pos_x+"px";
		keep_scrolling = setTimeout ("scrollyBuddy.l('"+id+"')", scroll_speed);
	}
}


scrollyBuddy.r = function (id) {
	var reg = sb_registry[id];
	var obj = document.getElementById(reg.object);

	if (reg.object_pos_x < 0) { // constrain scrolling to container
		reg.object_pos_x = reg.object_pos_x + 10;
		obj.style.left = reg.object_pos_x+"px";
		keep_scrolling = setTimeout ("scrollyBuddy.r('"+id+"')", scroll_speed);
	}
}


scrollyBuddy.s = function () {
	clearTimeout(keep_scrolling);
}