// JavaScript Document
if (document.getElementById && document.getElementsByTagName) {
if (window.addEventListener) window.addEventListener('load', initAnims, false);
else if (window.attachEvent) window.attachEvent('onload', initAnims);
}

function initAnims() {

		var animElements = document.getElementsByTagName("a");
		for(var i=0; i<animElements.length; i++) {
			animElements[i].onmouseover = fadeColMem;
			animElements[i].onmouseout = fadeColRestore;
			}

		var animElements = document.getElementById("fade").getElementsByTagName("a");
		for(var i=0; i<animElements.length; i++) {
			animElements[i].onmouseover = fadeOpaMem;
			animElements[i].onmouseout = fadeOpaRestore;
			}

		function fadeOpaMem() {
			if (!this.style.opacity) {
				this.style.opacity="0.4";
				this.style.filter="alpha(opacity=40)";
			}
			if (!this.ofade||!this.cfade) {
				this.ofade = this.style.opacity*100;
				this.cfade = this.style.opacity*100;
			}
			doFadeOpaMem(this,this.cfade,99,15,20,.75);
		}

		function fadeOpaRestore() {
			if (!this.cfade) return;	//avoid error if mouseout an element occurs before the mouseover
																//(e.g. the pointer already in the object when onload)
			doFadeOpaMem(this,this.cfade,this.ofade,30,20,1.5);
		}


		function fadeColMem() {
			if (!this.style.color) this.style.color="#000000";
			var color = new RGBColor(this.style.color);
			if (!this.currentRGB||!this.returncolor) {
				this.currentRGB = [color.r,color.g,color.b]; 
				this.returncolor = [color.r,color.g,color.b];
				}
			doFadeMem(this,this.currentRGB,[255,255,255],15,20,.5);
		}

		function fadeColRestore() {
			var bgelem=document.getElementById("bg");
			if (!this.currentRGB||!this.returncolor) return;	//avoid error if mouseout an element occurs before the mouseover
																//(e.g. the pointer already in the object when onload)
			doFadeMem(this,this.currentRGB,this.returncolor,30,20,1.5);

		}

			
}
	
//*******************

function doFade(elem,startRGB,endRGB,finalColor,steps,intervals,powr) {
	if (elem.FadeInt) window.clearInterval(elem.FadeInt);
	var actStep = 0;
	elem.FadeInt = window.setInterval(
		function() {
			elem.style.color = "rgb("+
				easeInOut(startRGB[0],endRGB[0],steps,actStep,powr)+","+
				easeInOut(startRGB[1],endRGB[1],steps,actStep,powr)+","+
				easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)+")";
			actStep++;
			if (actStep > steps) {
			elem.style.color = finalColor;
			window.clearInterval(elem.FadeInt);
			}
		}
		,intervals)
}

//*******************

function doFadeMem(elem,startRGB,endRGB,steps,intervals,powr) {
// Fader with Memory by www.hesido.com
	if (elem.FadeMemInt) window.clearInterval(elem.FadeMemInt);
	var actStep = 0;
	elem.FadeMemInt = window.setInterval(
		function() {
			elem.currentRGB = [
				easeInOut(startRGB[0],endRGB[0],steps,actStep,powr),
				easeInOut(startRGB[1],endRGB[1],steps,actStep,powr),
				easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)
				];
			elem.style.color = "rgb("+
				elem.currentRGB[0]+","+
				elem.currentRGB[1]+","+
				elem.currentRGB[2]+")";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.FadeMemInt);
		}
		,intervals)
}

//*******************

function doFadeMemBG(elem,startRGB,endRGB,steps,intervals,powr) {
// Fader with Memory by www.hesido.com
	if (elem.FadeMemInt) window.clearInterval(elem.FadeMemInt);
	var actStep = 0;
	elem.FadeMemInt = window.setInterval(
		function() {
			elem.currentRGB = [
				easeInOut(startRGB[0],endRGB[0],steps,actStep,powr),
				easeInOut(startRGB[1],endRGB[1],steps,actStep,powr),
				easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)
				];
			elem.style.backgroundColor = "rgb("+
				elem.currentRGB[0]+","+
				elem.currentRGB[1]+","+
				elem.currentRGB[2]+")";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.FadeMemInt);
		}
		,intervals)
}

//*******************

function doFadeOpaMem(elem,startO,endO,steps,intervals,powr) {
	if (elem.FadeOpaMemInt) window.clearInterval(elem.FadeOpaMemInt);
	var actStep = 0;
	elem.FadeOpaMemInt = window.setInterval(
		function() {
			elem.cfade = easeInOut(startO,endO,steps,actStep,powr);
			elem.style.opacity = elem.cfade/100;
		    elem.style.MozOpacity = elem.cfade/100;
		    elem.style.KhtmlOpacity = elem.cfade/100;
		    elem.style.filter = "alpha(opacity=" + elem.cfade + ")";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.FadeOpaMemInt);
		}
		,intervals)
}

//*******************

function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
//Generic Animation Step Value Generator By www.hesido.com
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}

