window.onload = UpdateControls;

var delay = 10;
var jump = 10;

var timeout = null;
var dist;

function StartScrolling(dir) {
	StopScrolling();
	dist = dir * jump;
	Scroll();
}

function Scroll() {
	var cont = document.getElementById("content");
	var cur = cont.scrollTop;
	cur += dist;
	cont.scrollTop = Math.max(0, cur);
	UpdateControls();
	timeout = setTimeout(Scroll, delay);
}

function StopScrolling() {
	if(!timeout)
		return;
		
	clearTimeout(timeout);
	timeout = null;
}

function UpdateControls() {
	var cont = document.getElementById("content");
	var cur = cont.scrollTop;

	var up = (cur == 0);
	var down = (cur + cont.offsetHeight >= cont.scrollHeight);
	
	document.getElementById("arrowup").style["visibility"] = (up ? "hidden" : "visible");
	document.getElementById("arrowdown").style["visibility"] = (down ? "hidden" : "visible");
}


function flipDetails(num) {
	var el = document.getElementById("details" + num);

	if(el.style["display"] != "block")
		new Effect.BlindDown(document.getElementById("details" + num),
			{ duration: 1.0, afterFinishInternal:
				function(effect) { effect.element.style["display"] = "block"; UpdateControls(); }
			});
	else
		new Effect.BlindUp(document.getElementById("details" + num),
			{ duration: 1.0, afterFinishInternal:
				function(effect) { effect.element.style["display"] = "none"; UpdateControls(); }
			});                        
}


function Rearrange(path) {
	var comps = path.split("/").reverse();
	document.location = "mail" + "to:" + comps.shift() + "@" + comps.join(".");
}
