if (document.getElementById && document.getElementsByTagName) {
	if (window.attachEvent) {
		// IE
		window.attachEvent('onload', 
							function() {
								initAnims("headmenu3", "horizontal")
								initAnims("bottommenu", "horizontal")
								initAnims("leftmenu", "vertical")
							})
	}
	else if (window.addEventListener) {
		// W3C standard
		window.addEventListener('load',
								function() {
									initAnims("headmenu3", "horizontal") 
									initAnims("bottommenu", "horizontal")
									initAnims("leftmenu", "vertical")
								}, 
								false)
	}
}

function initAnims(id, elem_class) {

	//	Init fade animation with memory, both directions
	var block_obj = document.getElementById(id)
	if (block_obj == null)
		return
	
	var animElements = block_obj.getElementsByTagName("a");
	for(var i=0; i < animElements.length; i++) {
		if (animElements[i].className == elem_class) continue
		try {
			// use W3C standard
			animElements[i].addEventListener("mouseover", fadeBGColMem, false);
			animElements[i].addEventListener("mouseout", fadeBGColRestore, false);
		} catch (err) {
			// for IE
			animElements[i].attachEvent("onmouseover", fadeBGColMem);
			animElements[i].attachEvent("onmouseout", fadeBGColRestore);
		}
	}
}

function fadeBGColMem() {
	var obj = this							// Mozilla
	if (window.event) {
		obj = window.event.srcElement		// IE
	}
	
	if (!obj.currentbgRGB)
		obj.currentbgRGB = [224,227,224]; //if no mem is set, set it first;

	try {
		doBGFadeMem(obj, obj.currentbgRGB, [255,255,255], 12, 20, 1);
	} catch (err) {}
}

function fadeBGColRestore() {
	var obj = this							// Mozilla
	if (window.event) {
		obj = window.event.srcElement		// IE
	}
	
	if (!obj.currentbgRGB) return;	//avoid error if mouseout an element occurs before the mouseover
										//(e.g. the pointer already in the object when onload)
	try {
		doBGFadeMem(obj, obj.currentbgRGB,[224,227,224],12,20,1);
	} catch (err) {}
}


function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) 
{
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}

function doBGFadeMem(elem,startRGB,endRGB,steps,intervals,powr) 
{
	if (elem.bgFadeMemInt) window.clearInterval(elem.bgFadeMemInt);
	var actStep = 0;

	elem.bgFadeMemInt = window.setInterval(
		function() {
			try{
				elem.currentbgRGB = [
					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.currentbgRGB[0]+","+
					elem.currentbgRGB[1]+","+
					elem.currentbgRGB[2]+")";
				actStep++;
				if (actStep > steps) 
					window.clearInterval(elem.bgFadeMemInt);
			} catch (err) {}
		}
		,intervals
	)
}
