var col1;
var col2;
var fadeStep;
var fadeDir=1;
var fadeCount = 0;
var fadeSteps = 50;
var fadeRate = 20;

function color(r,g,b) {
	this.red = r;
	this.green = g;
	this.blue = b;
	this.toString = color_tostring;
	this.colorStep = color_step
	this.colorAdd = color_add
}

function color_add(c2,count) {
	r = Math.round(this.red + (count * c2.red)) | 256;
	g = Math.round(this.green + (count * c2.green)) | 256;
	b = Math.round(this.blue + (count * c2.blue)) | 256;
	return new color(r,g,b);
}

function color_step(c2,count) {
	return(new color((c2.red - this.red)/count,(c2.green-this.green)/count,(c2.blue-this.blue)/count));
}

function colorFromString(sCol) {
	sCol = sCol + "000000";
	if(sCol.substring(0,1) == '#') { sCol = sCol.substring(1,7); }
	r = eval("0x" + sCol.substring(0,2));
	g = eval("0x" + sCol.substring(2,4));
	b = eval("0x" + sCol.substring(4,6));
	return new color(r,g,b);
}

function color_tostring() {
	return("#"+int2hex(this.red) + int2hex(this.green) + int2hex(this.blue));
}

function int2hex(i) {
	var k = i % 16;
	var j= ((i-k) % 256) / 16;
	h = "0123456789ABCDEF";
	s = h.substring(j,j+1) + h.substring(k,k+1);
	return(s);
}

function linkPulse(c1,c2,pRate,pSteps) {
	fadeSteps = pSteps;
	dir=1;
	fadeRate=pRate;
	col1 = colorFromString(c1);
	col2 = colorFromString(c2);
	fadeStep = col1.colorStep(col2,fadeSteps);
	setLinkColors(col1.toString());
}

function nextCol() {
	fadeCount = fadeCount + fadeDir;
	nc = col1.colorAdd(fadeStep,fadeCount);
	col0=nc;
	if(fadeCount<=0) { 
		fadeDir=1;
		fadeCount=0;
	} else {
		if(fadeCount >= fadeSteps) {
			fadeDir=-1;
			fadeCount = fadeSteps;
		}
	}
	return(nc)
}

function setLinkColors(colval)
{
	lnks = document.links;
	if(lnks) {
		var e;
		var ll = lnks.length;
		for(i = 0; i < ll; i++){
		   e = lnks[i];
	   	   e.style.color = colval;
		}

	}
	nc = nextCol();
	window.setTimeout("setLinkColors('" + nc.toString() + "');",fadeRate);
}