
// ColorFade script
// copyright 2007 by Michal Gajek
// http://migajek.com/

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)
}

/* debug function 
function  printProps(obj, objName) {
  var output = "" ;
  for (var prop in obj) {
    output += objName + "." + prop + " = " + obj[prop] + "\n" ;
  }
  return output ;
}
*/

function disableAHover(){
 // function by nav :) thx ;)
  i = document.styleSheets;
for (l=0; l<i.length; l++)
{  
    for (x in i[l].cssRules)
    {
    var st = new String(i[l].cssRules[x].selectorText); 
    //alert(printProps(i[l].cssRules[x]));
        if ( (st.toLowerCase() == "div.menucontainer2 a:hover") || (st.toLowerCase() == "div.menucontainer a:hover"))
        {          
            i[l].cssRules[x].style.backgroundColor='rgb(236, 232, 232)';
        }
    }
}

}

function doBGFadeMem(elem,startRGB,endRGB,steps,intervals,powr) {
	if (elem.bgFadeMemInt) window.clearInterval(elem.bgFadeMemInt);
	var actStep = 0;
	elem.bgFadeMemInt = window.setInterval(
		function() {
			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);
		}
		,intervals)
}


var ColorFade = Class.create();

ColorFade.prototype = {
  initialize: function(){
    
    if (!document.getElementsByTagName){ return; }
    var elems = document.getElementsByTagName('a');
    
    for (var i = 0; i < elems.length; i++){
	 var anchor = elems[i];
	 var relAttribute = String(anchor.getAttribute('rel'));
	 if ( (relAttribute.toLowerCase().match('colorfade')) || (relAttribute.toLowerCase().match('colorfade2')) ){
    		anchor.onmouseover = this.fadeBGColMem;
		anchor.onmouseout = this.fadeBGColRestore;	
  	 }
  	 
    }
  },
  
   fadeBGColMem: function() {     			
			if (!this.currentbgRGB) this.currentbgRGB = [0xEC,0xE8,0xE8]; //if no mem is set, set it first;
			
			doBGFadeMem(this,this.currentbgRGB,[0x9E,0x96,0x96],20,20,1);
			},

   fadeBGColRestore: function() {
			if (!this.currentbgRGB) return;	//avoid error if mouseout an element occurs before the mosueover						
			
			if ( String(this.getAttribute('rel')).toLowerCase() == 'colorfade2' ){
			 Cl = [0xFF, 0xFF, 0xFF];
			} else {
			 Cl = [0xEC,0xE8,0xE8];
  			} 
			 
			doBGFadeMem(this,this.currentbgRGB,Cl,25,20,1);
			}
			  
    
  }



function initColorFade() { disableAHover(); myColorFade = new ColorFade(); }
Event.observe(window, 'load', initColorFade, false);

