var current = 1;
var top = 0;
var timeout = null;

function subnavclick(item, coords) {
	clearInterval(timeout);
	var amount = (coords - top) / 20;
	timeout = setTimeout("subnavclick_scroll(" + top + ", " + coords + ", " + amount + ")", 10);
}

function subnavclick_highlight(item) {
	document.getElementById("subnav_" + current).className = "work_link";
	document.getElementById("subnav_" + item).className = "work_link_highlight";
	current = item;
}

function subnavclick_scroll(start, stop, amount) {
	if ((amount > 0 && top < stop) || (amount < 0 && top > stop)) {
		top += amount;
		amount *= 0.953;
		if (amount < 0 && amount > -1) {
			amount = -1;
		} else if (amount > 0 && amount < 1) {
			amount = 1;
		}
		timeout = setTimeout("subnavclick_scroll(" + start + ", " + stop + ", " + amount + ")", 5)
	} else {
		top = stop;
		clearInterval(timeout);
	}
	document.getElementById("content").scrollTop = top;
}

function subnav_updatehighlight() {
	top = document.getElementById("content").scrollTop;
	for (i = 0; i < projects.length; i++) {
		if (projects[i] <= top && ((i + 1) == projects.length || projects[i + 1] >= top)) {
			subnavclick_highlight(i + 1);
		}
	}
}
