var sa_step = 2;
var sa_speed = 80;
var sa_space = 30;
var sa_height = 615;

var sa_over = false;
function sa_init2(id, classname){
	var sa = $(id);
	if (!sa) return;

	var w = new Element('div');
	//w.clonePosition(sa);
	w.setStyle({
		position: 'relative',
		width: sa.getWidth() + 'px',
		height: sa_height + 'px',
		overflow: 'hidden'
	});
	sa.wrap(w);
	sa_makePositioned(sa, 0, w);

	if (classname) {
		w.addClassName(classname);
	}

	w.observe('mouseover', function() { sa_over = true; });
	w.observe('mouseout', function() { sa_over = false; });

	function sa_scroll(area){
		if (!sa_over) {
			area.childElements().each(function(box) {
				var top = (box.positionedOffset()[1] - sa_step);
				var height = box.getHeight();
				var max = area.getHeight();
				if (top + height < max && !box.next()) {
					var nb = new Element('div');
					sa_makePositioned(nb, top + height + sa_space, area);
					nb.update(box.innerHTML);
					area.insert(nb);
				}
				if (top <= -height) {
					box.remove();
				} else {
					box.setStyle({
						top: top + 'px'
					});
				}
			});
		}
		sa_scroll.delay(sa_speed / 1000, area);
	}

	sa_scroll(w);
}

function sa_init(id, classname){
	// Work around position problems
	document.observe('dom:loaded', function(){
			sa_init2(id, classname);
		});
}


function sa_makePositioned(box, top, area){
	box.setStyle({
			position: 'absolute',
			top: top + 'px',
			width: area.getWidth() + 'px',
			left: '0px',
			textAlign: 'center'
		});
}