var LC = new Array("#ffe5bf","#ffeacb","#feeed6","#fff3e2","#fff8ee","#fefcfa","#ffffff");

function topnav() {
	var tar_div = document.getElementById("nav");
	var tar_ul = tar_div.getElementsByTagName("ul");
	var ul_no = tar_ul.length;
	
	for(i = 0; i < ul_no; i++) {
		var list = tar_ul[i];
		var newULlisteners = new ulListeners(list);
		
		var tar_a = tar_ul[i].getElementsByTagName("a");
		var a_no = tar_a.length;
		
		for(i = 0; i < a_no; i++) {
			var link = tar_a[i];
			var newAlistener = new aListener(link);
		}
	}

}

function ulListeners(targetList) {
	var t;
	var tt;
	var thisList = targetList;
	thisList.parentNode.onmouseover = function() {
		clearTimeout(tt);
		t = setTimeout(function() {thisList.style.visibility='visible'},100);
	}
	thisList.parentNode.onmouseout = function() {
		clearTimeout(t);
		tt = setTimeout(function() {thisList.style.visibility='hidden'},500);
	}
}

function aListener(myLink) {
	var thisLink = myLink;
	var interval;
	
	thisLink.onmouseover = function() {
		clearTimeout(interval);
		thisLink.style.background=LC[0];
	}
	
	thisLink.onmouseout = function() {
		fadeOut(0);
	}
	
	function fadeOut(colour) {
		myColour = LC[colour];
		thisLink.style.background=myColour;
		if(colour < 6) {
			var newColour = colour + 1;
			interval = setTimeout(function() {fadeOut(newColour)},50);
		 }
		
	}
}


window.onload = function() {
	topnav();
}