
slide_step = 5;
slide_int = 20;

slide_origin = 115;

timeout = new Array();

function slide_up(child) {
	clearInterval(timeout[child.id]);
	timeout[child.id] = setInterval(function() { slide_move(child, slide_step * -1); }, slide_int);
	slide_move(child, slide_step * -1);
}

function slide_down(child) {
	clearInterval(timeout[child.id]);
	timeout[child.id] = setInterval(function() { slide_move(child, slide_step); }, slide_int);
}

function slide_move(child, step) {

	var current = child.offsetTop;

	if (step > 0) {

		// moving down the page

		if (current <= slide_origin - step) {
			child.style.top = current + step + "px";
		} else if (current < slide_origin) {
			child.style.top = slide_origin + "px";
		} else {
			clearInterval(timeout[child.id]);
		}

	} else if (step < 0) {

		var max_top = child.parentNode.offsetHeight - child.offsetHeight;

		// moving up the page
		if (current >= max_top - step) {
			child.style.top = current + step + "px";
		} else if (current > max_top) {
			child.style.top = max_top + "px";
		} else {
			clearInterval(timeout[child.id]);
		}

	}

}

function slide_init() {

	var boxes = getElementsByClass("section-box", document, "div");

	for (var i = 0, m = boxes.length; i < m; i++) {

		boxes[i].id = i;
		getElementsByClass("section-box-inner", boxes[i], "div")[0].id = "child_box_"+i;

		boxes[i].onmouseover = function() {

			if (!this.already_over) {

				var child = getElementsByClass("section-box-inner", this, "div")[0];
				slide_up(child);

			}

		}

		boxes[i].onmouseout = function() {

			var child = getElementsByClass("section-box-inner", this, "div")[0];
			slide_down(child);

		}

		boxes[i].onclick = function() {

			var href = this.getElementsByTagName("a")[0].href;
			this.onclick = window.document.location.href = href;

		}

	}

}

addEvent(window, "load", slide_init);
