function highlight(x, y) {
	if (y) {
		x.style.background="#ff6060";
	} else {
		x.style.background="#ff4040";
	}
}

function highlight2(x) {
	var d = new Date();
	var prevt = d.getMilliseconds();
	var startt = prevt;
	var currt;
	var passed = false;
	var passed0 = false;
	for (currt = startt; currt <= startt && passed; prevt = currt) {
		var ccolor;
		currt = (new Date()).getMilliseconds();
		if (startt < currt) {
			ccolor = 32 * ((currt-startt)/1000);		
		} else {
			ccolor = 32 * (((currt+(1000-startt))-startt)/1000);
			if (currt < prevt)  {	passed0 = true; 	}
			if (currt > startt) {	passed = true; }
		}
		var ccolor2 = 64 + parseInt(ccolor);
		var colorstring = "#ff" + ccolor2.toString(16) + ccolor2.toString(16);
		x.style.background=colorstring;
	}
}

//window.onload=loader;
function loader(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none';
		}
	}
	if (d) {
		d.style.display='inline';
	}
}

//creates a sub menu
//the loaded menu has to call the submenu
function loader2(id, x) {
var d;
if (id!='none') {d = document.getElementById(id); }
	//naming convention: all id's 5 or greater are submenu, alter constant 'i' below if 
	//you want more primary drop-down menus
	for (var i = 5; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none';
		}
	}
	if (d) {
		if (x) {
			d.style.display='inline';
		} else {
			d.style.display='none';
		}
	}
}

var t2, t3;

//This function takes three argument, the object(x)
//and an integer value that determines the level(y)
//and a boolean as to whether the field lightens(z)
function adjust(x, y, z) {
	if (y===0) {
		//todo: cycle through submenus and set their default color
		if (x < 5) {
			loader("smenu"+x);
		} else if (x < 15) {
			loader2("smenu"+x, true);
		}
	}
	if (y < 10) {
//		if (x.style.display != 'none') {
			var r, g, b;
			if (5 > x) { //anything greater than 4 is a submenu (rr convention)
				if (z) {
					r = "FF"; //208 is hex for d0
					g = ((4*y) + 64).toString(16); //224 is hex for e0
					b = ((4*y) + 64).toString(16); //208 is hex for d0
					var colr = "#"+r+g+b;
					document.getElementById("static"+x).style.background=colr;
					y ++;
					var meth = "adjust("+x+","+y+","+z+")";
					var t2 = setTimeout(meth, 30);
				} else {
					r = "FF"; //208 is hex for d0
					g = (104 - (4*y)).toString(16); //224 is hex for e0
					b = (104 - (4*y)).toString(16); //208 is hex for d0
					var colr = "#"+r+g+b;
					document.getElementById("static"+x).style.background="#"+r+g+b;
					y ++;
					var meth = "adjust("+x+","+y+","+z+")";
					t2 = setTimeout(meth, 30);
				}
			} else {
				if (z) {
					//gradually decreases brightness
					r = (228-(2*y)).toString(16); //208 is hex for d0
					g = (254-(3*y)).toString(16); //224 is hex for e0
					b = (228-(2*y)).toString(16); //208 is hex for d0
					var colr = "#"+r+g+b;
					document.getElementById("static"+x).style.background=colr;
					y ++;
					var meth = "adjust("+x+","+y+","+z+")";
					t2 = setTimeout(meth, 30);
				} else {
					//default to original color
					r = (208+(2*y)).toString(16); //208 is hex for d0
					g = (224+(3*y)).toString(16); //224 is hex for e0
					b = (208+(2*y)).toString(16); //208 is hex for d0
					var colr = "#"+r+g+b;
					document.getElementById("static"+x).style.background=colr;
					y ++;
					var meth = "adjust("+x+","+y+","+z+")";
					t2 = setTimeout(meth, 30);
					
					
//					document.getElementById("static"+x).style.background="#e4ffe4";
//					y=10; //in case of any further modification
				}
			}
//		}
	}
}