//
//	a cross browser version of my glow.htc
//	mo /mircho@hotmail.com/
//
cFader = {
	speed	: 20,
	steps	: 8,
	active	: 0,

	startc	: 0,
	endc	: 0,
	
	startr	: 0,
	startg	: 0,
	startb	: 0,
	endr	: 0,
	endg	: 0,
	endb	: 0,
	
	startColor	: '#465C75',
	endColor	: '#A6AEBD'
}


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( eval( 'typeof '+element.className+'Start != "undefined"') ) SC = eval( element.className+'Start' )
	else SC = this.startColor
	if( eval( 'typeof '+element.className+'End != "undefined"') ) EC = eval( element.className+'End' )
	else EC = this.endColor

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

cFader.doFade = function( elName, sColor )
{
	element = eval( 'this.'+elName )
	element.style.color = sColor
}

// ----------------------------------------------------------------

/**
 * The global array below will be used inside the "setPointer()" function
 */
var markedRow = new Array();

/**
 * Sets/unsets the pointer in browse mode
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 * @param   object   the background color
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, thePointerColor, theNormalBgColor)
{
    var theCells = null;

    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    var currentColor = null;
    var newColor     = null;
    // Opera does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
        }
    }

    return true;
}

//get real element that originated the event
function spov ( e ) {
	if( !e ) e = window.event
	element = isELM( e )
	if( element != null ) setPointer(this, '#fbfcfd', '#FFFFFF')
}
function spot ( e ) {
	if( !e ) e = window.event
	element = isELM( e )
	if( element != null ) setPointer(this, '#fbfcfd', '#FFFFFF')
}
// ----------------------------------------------------------------

function isELM( e )
{
	elm =  ( e.srcElement ) ? e.srcElement : e.originalTarget.parentNode
	if( elm ) return elm
	else return null
}

//activation
function fadeMouseOver( e )
{
	if( !e ) e = window.event
	element = isELM( e )
	if( element != null ) cFader.fadeIn( element )
}

//deactivation
function fadeMouseOut( e )
{
	if( !e ) e = window.event
	element = isELM( 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
}
*/

function doFadeLinks() {
	if (document.getElementsByTagName && document.all) {
		aA = document.getElementsByTagName('A');
		for (i = 0; i < aA.length; i++) {
			a = aA[i];
			if (!a.className) {
				a.onmouseover = fadeMouseOver;
				a.onmouseout = fadeMouseOut;
			}
		}
	}
}

function doFadeRows() {
	if (document.getElementsByTagName && document.all) {
		aTR = document.getElementsByTagName('TR');
		for (i = 0; i < aTR.length; i++) {
			TR = aTR[i];
			if (TR.className == 'fade') {
				TR.onmouseover = spov;
				TR.onmouseout = spot;
			}
		}
	}
}

function myInit( e ) {
	doFadeLinks();
	doFadeRows();
}

window.onload = myInit

function loadPic(s) {
	p=new Image();
	p.src=s;
	return true;
}
