/******************************************************************
*	Script name: Link fader
*	Version: 0.5
*	Date: 02.05.02
*	Usage: Freeware (as long as you don't remove this comment)
*
*	Script by: Fayez Zaheer (viol8r on #webdesign [uk.zanet.org.za])
*	Email: fayez at impenetrable.org
*	Web site: http://impenetrable.org
* 	Original idea: http://anarchos.xs.mw/fade.phtml
******************************************************************/

// Make sure not to add a # to fcS and fcE - use hex values 6 characters in length ONLY
var fcS = "ffffff";
	// Original colour of your links
var fcE = "ff0000";
	// Fade to which colour?
var fBy = 5;
	// Changing this will affect how accurately the fade to colour is "reached". A value of 1 is most accurate
var speed = 10;
	// Delay in milliseconds of the change from each individual colour to the next during the fade

// Unless you want the ability to let your visitors change the
//	fade to colour, you can delete the following function
function fadeTo()
	{
		var c = prompt("What colour do you want to fade to (no #)?", "ff0000");
		convertHex(c);
		fcEr = r;
		fcEg = g;
		fcEb = b;
	}
// Stop deleting.

// IF YOU DON'T KNOW WHAT YOU ARE DOING,
// DON'T EDIT ANYTHING BEYOND THIS POINT
var r , g, b, fcEr, fcEg, fcEb, fcSr, fcSg, fcSb, fi, fo, x = 0, h = new String();

function convertHex(hex)
	{
		r = hex.substring(0, 2);
		r = parseInt(r, 16);
		g = hex.substring(2, 4);
		g = parseInt(g, 16);
		b = hex.substring(4, 6);
		b = parseInt(b, 16);
	}

convertHex(fcE);
	fcEr = r;
	fcEg = g;
	fcEb = b;

convertHex(fcS);
	fcSr = r;
	fcSg = g;
	fcSb = b;

function fadeIn(x)
	{
		if ((r > fcEr) && (r-fBy >= 0)) r -= fBy;
		if ((g > fcEg) && (g-fBy >= 0)) g -= fBy;
		if ((b > fcEb) && (b-fBy >= 0)) b -= fBy;
		if ((r < fcEr) && (r+fBy <= 255)) r += fBy;
		if ((g < fcEg) && (g+fBy <= 255)) g += fBy;
		if ((b < fcEb) && (b+fBy <= 255)) b += fBy;
		document.links[x].style.color = "rgb(" + r  + "," + g + "," + b + ")";
		if ((r == fcEr) && (b == fcEb) && (g == fcEg))
			clearInterval(fi);
	}

function fadeOut(x)
	{
		if ((r < fcSr) && (r+fBy <= 255)) r += fBy;
		if ((g < fcSg) && (g+fBy <= 255)) g += fBy;
		if ((b < fcSb) && (b+fBy <= 255)) b += fBy;
		if ((r > fcSr) && (r-fBy >= 0)) r -= fBy;
		if ((g > fcSg) && (g-fBy >= 0)) g -= fBy;
		if ((b > fcSb) && (b-fBy >= 0)) b -= fBy;
		document.links[x].style.color = "rgb(" + r  + "," + g + "," + b + ")";
		if ((r == fcSr) && (b == fcSb) && (g == fcSg))
			clearInterval(fo);
	}

function findLink()
	{
		convertHex(fcS);
		clearInterval(fo);
		clearInterval(fi);
		document.links[x].style.color = "#" + fcS;
		x = 0;
		while (!(this.id == document.links[x].id) && (x < document.links.length))
			x++;
		if (this.id == document.links[x].id)
			fi = setInterval("fadeIn(" + x  + ")", speed);
	}

if ((!document.layers) && (document.links))
	{
		for (var i = 0; i < document.links.length; i++)
			{
				document.links[i].id = "link" + i;
				document.links[i].onmouseover = findLink;
				document.links[i].onmouseout = function mouseOut() { clearInterval(fi); clearInterval(fo); fo = setInterval("fadeOut(" + x + ")", speed); };
			}
	}
