cFader = {
	speed	: 5,
	steps	: 20,
	active	: 0,

	startc	: 0,
	endc	: 0,
	
	startr	: 0,
	startg	: 0,
	startb	: 0,
	endr	: 0,
	endg	: 0,
	endb	: 0,

	startColor1	: '#FF00FF',
	endColor1	: '#FFFFFF',
	startColor2	: '#FFFFFF',
	endColor2	: '#FFFFFF',
	startColor3	: '#0099FF',
	endColor3	: '#33CC00'
}

cFader.colorToNumber = function( sColor )
{
	sRCol = /^#/
	return parseInt( '0x'+sColor.replace( sRCol, '' ) )
}

cFader.numberToColor = function( nColor )
{
	nColor |= 1<<24
	return '#'+nColor.toString(16).substr(1)
}

cFader.init = function( element )
{
	if (element.className == "title")
	{
	    SC = this.startColor1;
	    EC = this.endColor1;
	}
	if (element.className == "hresult")
	{
	    SC = this.startColor2;
	    EC = this.endColor2;
	}
	if (element.className == "lresult")
	{
	    SC = this.startColor3;
	    EC = this.endColor3;
	}
	if (element.className == "link")
	{
	    SC = this.startColor3;
	    EC = this.endColor3;
	}

	with (this)
	{
		startc = colorToNumber( SC )
		endc = colorToNumber( EC )

		startr = (startc & 0xff0000) >>> 16
		startg = (startc & 0x00ff00) >>> 8
		startb = (startc & 0x0000ff)
		
		endr = (endc & 0xff0000) >>> 16
		endg = (endc & 0x00ff00) >>> 8
		endb = (endc & 0x0000ff)
	}
}

cFader.fadeIn = function( element )
{
	this.init( element )
	elName = 'cFaderActive'+(this.active++)
	eval( 'this.'+elName+'=element' )
	for( step = 0; step <= this.steps; step++ )
	{
		with( this )
		{
			nColor = startr*((steps-step)/steps)+endr*(step/steps) << 16 | startg*((steps-step)/steps)+endg*(step/steps) << 8 | startb*((steps-step)/steps)+endb*(step/steps)
		}
		sColor = this.numberToColor( nColor )
		setTimeout('cFader.doFade("'+elName+'", "'+sColor+'")', this.speed*(step+1))
	}
}

cFader.fadeOut = function( element )
{
	this.init( element )
	elName = 'cFaderActive'+(this.active++)
	eval( 'this.'+elName+'=element' )
	for( step = 0; step <= this.steps; step++ )
	{
		with( this )
		{
			nColor = endr*((steps-step)/steps)+startr*(step/steps) << 16 | endg*((steps-step)/steps)+startg*(step/steps) << 8 | endb*((steps-step)/steps)+startb*(step/steps)
		}
		sColor = this.numberToColor( nColor )
		setTimeout('cFader.doFade("'+elName+'", "'+sColor+'")', this.speed*(step+50))
	}
}

cFader.doFade = function( elName, sColor )
{
	element = eval( 'this.'+elName )
	element.style.color = sColor
}

//get real element that originated the event
function getReal( e )
{
	elm =  ( e.srcElement ) ? e.srcElement : e.originalTarget.parentNode
	
	if ((elm.tagName.toUpperCase() == "FONT") && elm.className == "link")
	    return null
	else
	    return elm
}

//activation
function fadeMouseOver( e )
{
  eSrc = window.event.srcElement;
  if (eSrc) {
     if ((eSrc.className == "title") || (eSrc.className == "hresult") || (eSrc.className == "lresult") || (eSrc.className == "link")) {
	if (!e) e = window.event
	element = getReal(e)
	if (element != null) cFader.fadeIn(element)
     }
  }
}

//deactivation
function fadeMouseOut( e )
{
  eSrc = window.event.srcElement;
  if (eSrc) {
     if ((eSrc.className == "title") || (eSrc.className == "hresult") || (eSrc.className == "lresult") || (eSrc.className == "link")) {
	if (!e) e = window.event
	element = getReal( e )
	if( element != null ) cFader.fadeOut( element )
     }
  }
}

if( document.attachEvent ) 
{
	document.attachEvent( 'onmouseover', fadeMouseOver )
	document.attachEvent( 'onmouseout', fadeMouseOut )
}
else if( document.addEventListener )
{
	document.addEventListener( 'mouseover', fadeMouseOver, true )
	document.addEventListener( 'mouseout', fadeMouseOut, true )
}
else if( document.all )
{
	document.onmouseover = fadeMouseOver
	document.onmouseout = fadeMouseOut
}

