
// No modificar nada a partir de aquí.
	var hexa = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');

function menufader()
{
	this.startColor = "#3C434A"; // Color al sacar el mouse
	this.endColor = "#666666"; // "#F0EADD";Color al pasar el mouse
	this.stepIn = 18; // retraso de fade in
	this.stepOut = 18; // retraso de fade out

	this.fadeId = new Array();

	this.init = init;
	this.fade = fade;
	this.fover = Fover;
	this.fout = Fout;
}

function init()
{
	this.startColor = dehexize(this.startColor.toLowerCase());
	this.endColor = dehexize(this.endColor.toLowerCase());
}

function fade(s, e, elemento, step)
{
	var sr = s[0];
	var sg = s[1];
	var sb = s[2];
	var er = e[0];
	var eg = e[1];
	var eb = e[2];

	if (this.fadeId[0] != null && fade[0] != elemento.id)
	{
		setColor(sr,sg,sb,this.fadeId[0]);
		var i = 1;
		while(i < this.fadeId.length)
		{
			clearTimeout(this.fadeId[i]);
			i++;
		}
	}

	if (!elemento.id)
	{
		do
		{
			uniqId = Math.random()*1000;
		} while (document.getElementById(uniqId));
		elemento.id = uniqId;
	}

	this.fadeId[0] = elemento.id;

	for(var i = 0; i <= step; i++)
	{
		nr = Math.floor( sr * ( (step-i)/step ) + er * (i/step) );
		ng = Math.floor(sg*((step-i)/step)+eg*(i/step));
		nb = Math.floor(sb*((step-i)/step)+eb*(i/step));
		this.fadeId[i+1] = setTimeout("setColor("+nr+","+ng+","+nb+",'"+elemento.id+"');",i*step);
	}
}

function Fover(ev,me)
{
	// t contiene el elemento para el cual se dispara el evento
	if (ev.target)
	{
		t=ev.target;
	}
	else
	{
		t=ev.srcElement;
	}
	// ref contiene el elemento del que viene el ratón
	if (ev.relatedTarget)
	{
		ref=ev.relatedTarget;
	}
	else
	{
		ref=ev.fromElement;
	}
	// Si el elemento para el que se dispara el evento es el elemento al que se
	// asignó manualmente el evento original o si es alguno de sus hijos
	// ejecuto el código asociado
	if ((me==t)||contains(me,t))
	{
		// Si el elemento para el que se dispara el evento no es el elemento del
		// que viene el puntero del ratón ni es un elemento hijo ejecuto el código
		// asociado
		if (me!=ref&&!contains(me,ref))
		{
			this.fade(this.startColor, this.endColor, me, this.stepIn);
		}
	}
}

function Fout(ev,me)
{
	if (ev.target)
	{
		t=ev.target;
	}
	else
	{
		t=ev.srcElement;
	}
	if (ev.relatedTarget)
	{
		ref=ev.relatedTarget;
	}
	else
	{
		ref=ev.toElement;
	}

	if ( (me == t) || contains(me,t) )
	{
		if ( me != ref&&!contains(me,ref) )
		{
			this.fade(this.endColor, this.startColor, me, this.stepOut);
		}
	}
}

function contains(a, b)
{
  if (!b) return false;
  if (a.contains) return a.contains(b);
  while (b.parentNode)
    if ((b = b.parentNode) == a)
      return true;
  return false;
}

function makearray(n) {
	this.length = n;
	for(var i = 1; i <= n; i++)
		this[i] = 0;
	return this;
}

function dehexize(Color) {
	var colorArr = new makearray(3);
	for (i=1; i<7; i++){
		for (j=0; j<16; j++){
			if (Color.charAt(i) == hexa[j]){
				if (i%2 !=0)
					colorArr[Math.floor((i-1)/2)]=eval(j)*16;
				else
					colorArr[Math.floor((i-1)/2)]+=eval(j);
			}
		}
	}
	return colorArr;
}

function hex(i)
{
	if (i < 0)
		return "00";
	else if (i > 255)
		return "ff";
	else
		return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}

function setColor(r, g, b, elementId)
{
	var hr = hex(r);
	var hg = hex(g);
	var hb = hex(b);
	var element = document.getElementById(elementId);

	try
	{
		element != "";
	}
	catch(e)
	{
		alert("No se cargó el elemento "+ element);
	}
	
	//if (!element) alert(elementId);
	
	element.style.backgroundColor = "#"+hr+hg+hb;
}

