/*
***********************************************************************************
Program Name			:	fader.js
Purpose					:	Fade Divs in and out
Modification History	:	
-----------------------------------------------------------------------------------
Who			Date		Description										Reference

Carlos Saba	31/07/2007	Created

-----------------------------------------------------------------------------------
***********************************************************************************
*/

/*
***********************************************************************************
// Function:	supportsOpacity
// Description:	
***********************************************************************************
*/
function supportsOpacity( el ) {
	if ( el.style.opacity != undefined ) return true;
	if( el.style.MozOpacity != undefined ) return true;
	if ( el.style.filter != undefined ) return true;
	return false;
}

/*
***********************************************************************************
// Function:	setOpacity
// Description:	
***********************************************************************************
*/
function setOpacity( el, opaciLevel ) {
	if ( el.style.opacity != undefined ) {
		el.style.opacity = opaciLevel;
	} else if( el.style.MozOpacity != undefined ) {
		el.style.MozOpacity = opaciLevel;
	} else if ( el.style.filter != undefined ) {
		var oplvl = Math.round(opaciLevel*100);
		el.style.filter="alpha(opacity=" + oplvl + ")";
	}
}

/*
***********************************************************************************
// Function:	fadeIn
// Description:	
***********************************************************************************
*/
function fadeIn( id, currentOpacity ) {
	var counterLimit = 20;
	var el = document.getElementById( id );
	if( !currentOpacity ) currentOpacity = 1;
	if( currentOpacity > counterLimit ) {
		return;
	}
	setOpacity( el, ( currentOpacity/counterLimit ) );
	currentOpacity++;
	var func = "fadeIn( '" + id + "', " + currentOpacity + ")";
	window.setTimeout( func, 50);
}

/*
***********************************************************************************
// Function:	fadeOut
// Description:	
***********************************************************************************
*/
function fadeOut( id, currentOpacity ) {
	var counterLimit = 20;
	var el = document.getElementById( id );
	if( !currentOpacity && currentOpacity !== 0 ) currentOpacity = 20;
	if( currentOpacity < 0 ) {
		hide(id);
		return;
	}
	setOpacity( el, ( currentOpacity/counterLimit ) );
	currentOpacity--;
	var func = "fadeOut( '" + id + "', " + currentOpacity + ")";
	window.setTimeout( func, 50);
}

/*
***********************************************************************************
// Function:	show
// Description:	
***********************************************************************************
*/
function show( id ) {
	var elem = document.getElementById( id );
	if( supportsOpacity( elem )) {
		// first set 0% opacity to make it completely transparent
		setOpacity( elem, 0 );
		// when we set display = "block" it's still invisible
		elem.style.display = "block";
		// call the function to gradually increase opacity
		fadeIn( id );
	} else {
		// can't modify opacity, so just make it visible...
		elem.style.display = "block";
	}
}

/*
***********************************************************************************
// Function:	hide
// Description:	
***********************************************************************************
*/
function hide( id ) {
	var elem = document.getElementById( id );
//	elem.style.display="none";
}