/**
 * alphaTrans library for WebDDM, creates fading hide/show transitions
 * for menus. 
 * 
 * @version: 0.2
 * @starteC: 12/11/2004
 * @copyright: Copyright (c) 2004-2006, Cortex Creations, All Rights Reserved
 * @website: www.cortex-creations.com/webddm
 * @license: GPL vs2.0
 * @subversion: $IC: alphaTrans.WebDDM.js 135 2006-05-02 21:10:21Z josh $
 */
 
// Register alphaTrans transition plugin
WebDDM_registerPlugin_transition('alphaTrans');

// Hash of alphaAPI objects for the alphaTrans. Each item container
// (that feeds) has its own alphaAPI object.
WebDDM.prototype.alphaAPIObjects = new Hash();


/**
 * The alpha transition system.
 *
 * @package
 *
 * @param Hash itemsHash 'items' object Hash
 * @param STRING itemsId ID of the item container in question.
 * @param BOOLEAN visibility True to make the item container visible, else false
 *
 * @return VOID
 *
 * @access PRIVATE
 */
WebDDM.prototype.alphaTrans = function (itemsHash, itemsId, visibility)
{	
	var fader;
	
	// Make sure alphaAPI library has been loaded
	if (typeof(alphaAPI) == 'undefined')
	{
		alert('WebDDM: WARNING: You must include alphaAPI.WebDDM.compressed.js or alphaAPI.WebDDM.js to use alphaTrans (alpha fading transitions)! See example page for fading menus for more information.');
		return;
	}
	
	// Get transition data - WebDDM automatically checks if it's available before
	// calling transition functions, so no need to check here
	var transitionData = itemsHash.get('alphaTrans');
	
	// Set max opacity if it isn't set
	if (!transitionData.has('maxOpacity'))
	{
		transitionData.set('maxOpacity', 100);
	}

	// Initialize the fader if needed
	if (this.alphaAPIObjects.has(itemsId))
	{
		// Get alphaAPI object
		fader = this.alphaAPIObjects.get(itemsId);
		// Pause any potential fading
		fader.pause();
	}
	else
	{
		// Create new fader
		fader = new alphaAPI(WebDDM_getElement(itemsId), this);
		// Save fader
		this.alphaAPIObjects.set(itemsId, fader);
		// Set initial alpha
		fader.setAlpha(0);
		// Set start/stop alpha
		fader.startAlpha = transitionData.get('maxOpacity');
		fader.stopAlpha = 0;
		// Set WebDDM object
		fader.WebDDM_object = this;
	}

	// If we can't fade, just stop now
	if (!domLib_canFade ||
		(transitionData.get('direction') == 'in' && !visibility) ||
		(transitionData.get('direction') == 'out' && visibility))
	{
		fader.setAlpha(visibility ? transitionData.get('maxOpacity') : 0);
		this.transitionCompleted(fader.element, visibility, fader.element.id);
	}

	// Set inDelay and outDelay if delay is set
	if (transitionData.has('delay'))
	{
		transitionData.set('inDelay', transitionData.get('delay'));
		transitionData.set('outDelay', transitionData.get('delay'));
	}

	// Set fader configuration
	fader.fadeInDelay = transitionData.get('inDelay');
	fader.fadeOutDelay = transitionData.get('outDelay');
	fader.offsetTime = 0;
	fader.deltaAlpha = transitionData.get('delta');
	
	// Get current alpha
	// Set start alpha and stop alpha
	if (visibility)
	{
		// Start fading
		fader.fadeIn();
	}
	else
	{
		// Start fading
		fader.fadeOut();
	}
};
