//
// This file is copyright 2008, Black Sun.
// Theft of this code will be prosecuted to the fullest extent allowed
// by law. 
// If you would like to use this code, please contact start@blacksun.co.nz
//
var showCount = 4;
var list;
var pos = 0;
var divList;
var divBox;

var color = 0;
var lineHeight;
var scrollTimer;


function d2h(d) {return d.toString(16);}
function h2d(h) {return parseInt(h,16);} 

function start()
{
	var ul = document.getElementById('skill-list');
	divList = document.getElementById('skill-scroll');
	divBox = document.getElementById('skill-box');

	ul.style.display = "none";
	list = ul.getElementsByTagName("li");
	while(divList.childNodes[0]) {
		divList.removeChild(divList.childNodes[0]);
	}
	for(var i = 0; i < showCount; i++) {
		divList.insertBefore(list[i].cloneNode(true),divList.firstChild);
	}
	lineHeight = divList.offsetHeight / showCount;
	divList.style.top = "0";
	divList.style.left = "0";
	divBox.style.verticalAlign = "top";
	divBox.style.margin = "0";
	divList.style.marginTop = "0";
	divList.style.top = "0px";
	divList.style.position = "relative";

	//divList.style.border = "1px solid green";
	//divBox.style.border = "1px solid yellow";	

	//divBox.style.height = (lineHeight * (showCount + 1)) + "px";
	
	pos = showCount;

	fadeIn();
}
function fadeIn()
{
	if (divList.firstChild.style) {
	  var c = d2h(color);
	  divList.firstChild.style.color = "#" + c + c + c;
	}
	if (divList.lastChild.style) {
	  var c = d2h(15 - color);
	  divList.lastChild.style.color = "#" + c + c + c;
	}
	divList.style.top = ((lineHeight / 16) * color) + "px";
	color++;
	if (color > 15) {
		updateList();
	}
	scrollTimer = window.setTimeout(fadeIn,200);
}
function updateList()
{
	var newNode;
	var delNode = divList.lastChild;
	newNode = list[pos].cloneNode(true);
	newNode.style.color = "#000";
	if (divList.firstChild.style) {
		divList.firstChild.style.color = "#fff";
	}
	divList.insertBefore(newNode,divList.firstChild );
	divList.style.top = "0px";
	divList.removeChild(delNode);
	pos++;
	if (pos >= list.length) pos = 0;
	//window.setTimeout(updateList,2000);
	color = 0;
}



