function xGetElementById(e)
{
  if (typeof(e)!='string') return e;
  if (document.getElementById) e = document.getElementById(e);
  else if (document.all) e = document.all[e];
  else e = null;
  return e;
}

function setLayer(thislayer) {
	elm = xGetElementById(thislayer);
	last_elm = xGetElementById(Last);
	elm.style.top = 0; // set layer to top of container

	if (Last != "" && Last != thislayer) {
		last_elm.style.visibility = "hidden";
	}
	
	elm.style.visibility = "visible";
	uparrow = xGetElementById("up");
	uparrow.style.visibility = "hidden";
	
	Last = thislayer;
	current = thislayer;

 	current_elm = xGetElementById(current);
	posnow = parseInt(current_elm.style.top);	
	downarrow = xGetElementById("down");
	if (posnow < -parseInt(current_elm.scrollHeight) + parseInt(xGetElementById("container").offsetHeight)) {
		downarrow.style.visibility = "hidden";
	}
	else {
		downarrow.style.visibility = "visible";
	}
}

function movedown() {
	step = -scroll_rate;
	dir = 0;
	uparrow = xGetElementById("up");
	uparrow.style.visibility = "visible";
	motion();
}

function moveup() {
	step = scroll_rate;
	dir = 1;
	downarrow = xGetElementById("down");
	downarrow.style.visibility = "visible";
	motion();
}

function motion() {
	if (current == "") { 
		return;
	}
	
	current_elm = xGetElementById(current);
	clearTimeout(timer);
	posnow = parseInt(current_elm.style.top);	
	if (dir == 1 && posnow > -1 || dir == 0 && posnow < -parseInt(current_elm.scrollHeight)
	+ parseInt(xGetElementById("container").offsetHeight)) {
		if (dir == 0) {
			downarrow = xGetElementById("down");
			downarrow.style.visibility = "hidden";
		}
		else {
			uparrow = xGetElementById("up");
			uparrow.style.visibility = "hidden";
		}
		cease();
	}
	else {
		posnow += step;;
		current_elm.style.top = posnow;
		timer = setTimeout("motion()",5);
	}
}

function cease() {
	clearTimeout(timer);
}

function otop() {
	current_elm.style.top = 0;
}
