﻿window.onload=init;

var d=document;
var expander; 
var lContainer;

var currentTop=0;
var zInterval = null;
var direction;
var startTop=0;

var scrollRate=6;
var scrollTick=0;

var listExpand=true;
var listHeight=300;
var isExpanded=false;

var MAX_SCROLL_TICK=6;
var LI_PADDING=0;
var LI_HEIGHT=15;
var MIN_LIST_HEIGHT=255;
var REBOUND = -2;
var FAST_EXPAND=25;
var SLOW_EXPAND=2;
var SPEED_TRANSITION=20;

function init() {
	if(!d.getElementById)return;

	up=d.getElementById("upArrow");
	down=d.getElementById("downArrow");

	down.onclick=function(){scrollObjects(0);}
	up.onclick=function(){scrollObjects(1);}

	lContainer = d.getElementById("listContainer");

	d.getElementById("nContainer").style.height=MIN_LIST_HEIGHT+"px";
}

function scrollObjects(dir) {
	if(zInterval)return;
	if(isExpanded)return;
	if((!dir && currentTop<=-510) || (dir && currentTop==0))return; // dont scroll up if we're at the top or down if at the bottom of the list
	direction=dir;
	zInterval=setInterval("animate()",10);
}

function animate() {
	// increment or decrement currentTop based on direction
	if(!direction) {
		currentTop-=scrollRate;
	} else {
		currentTop+=scrollRate;
	}
	scrollTick++;	
	if(scrollTick>=MAX_SCROLL_TICK) {
		scrollRate--; // slow the scroll rate down for a little style
		scrollTick=0;
	}

	lContainer.style.top=currentTop+"px";
	if(scrollRate<=REBOUND) {
		// scroll is finished. clear the interval and reset vars for the next scroll
		clearInterval(zInterval);
		zInterval=null;
		startTop=currentTop;
		scrollTick=0;
		scrollRate=6;
	}
}
