//=========================================================================================================
//---------------------------------------------------------------------------------------------------------
//	Simple News Ticker
//---------------------------------------------------------------------------------------------------------
//=========================================================================================================
//=========================================================================================================
//	Show next ticker item
//=========================================================================================================
function TickerShowNext( id )
{
	//	Item count
	eval( "itemcount	= " + id + "count;" );

	//	Current item index
	eval( "itemcurrent	= " + id + "current;" );

	//	Get the ticker
	ticker_object	= document.getElementById( id );

	//	Increment current item index
	if( ++itemcurrent >= itemcount )
	{
		//	If greater than count, reset
		itemcurrent	= 0;
	}

	//	Set the ticker's current item index
	eval( id + "current = " + itemcurrent + ";" );

	//	Make sure the ticker is fully visible
	ticker_object.style.opacity	= 1;

	//	Begin transition to next
	eventfade	= setInterval( "TickerFadeOut('"+id+"');", 25 );
}

//=========================================================================================================
//	Fade out the current item
//=========================================================================================================
function TickerFadeOut( id )
{
	//	Item count
	itemcount	= id + "count";

	//	Current item index
	itemcurrent	= id + "current";

	//	Get the ticker
	ticker_object	= document.getElementById( id );

	//	Current opacity value
	opvalue			= ticker_object.style.opacity;

	//	Get the content for the next item
	eval( "currentitem = " + id + "list["+itemcurrent+"];" );

	if( IE )
	{
		//	Stop the transition
		clearInterval( eventfade );

		//	Swap in the new content
		ticker_object.innerHTML	= currentitem;

		//	Start fade-in
		eventfade	= setInterval( "TickerFadeIn('"+id+"');", 25 );

		return;
	}

	//	Change fade
	opvalue		-= 0.2;

	//	If less than 0, begin switch content and begin fade-in
	if( opvalue <= 0 )
	{
		//	Start from 0
		opvalue		= 0;

		//	Set the objects opacity
		ticker_object.style.opacity	= opvalue;
		ticker_object.style.filter	= "alpha(opacity=" + ( 100 * opvalue ) + ");";	//	IE hack

		//	Stop the transition
		clearInterval( eventfade );

		//	Swap in the new content
		ticker_object.innerHTML	= currentitem;
		
		//	Start fade-in
		eventfade	= setInterval( "TickerFadeIn('"+id+"');", 25 );
	}

	//	Set the fade-out opacity
	ticker_object.style.opacity	= opvalue;
	ticker_object.style.filter	= "alpha(opacity=" + ( 100 * opvalue ) + ");";	//	IE hack
}

//=========================================================================================================
//	Fade in the next item
//=========================================================================================================
function TickerFadeIn( id )
{
	//	Get the ticker
	ticker_object	= document.getElementById( id );

	//	Current opacity value
	opvalue			= ticker_object.style.opacity;

	//	Get specified delay interval for the ticker
	eval( "interval		= " + id + "interval;" );

	if( IE )
	{
		//	Stop the transition
		clearInterval( eventfade );

		//	Prevent memory leaks
		clearTimeout( eventticker );

		//	Is it stopped (mouseover pauses the ticker)
		eval( "stopped	= " + id + "stopped;" );

		//	If not stopped, set the timer to process next item
		if( !stopped )
		{
			eventticker	= setTimeout( "TickerShowNext('"+id+"');", interval );
		}

		return;
	}

	opvalue		= (( 100 * opvalue ) + 20 ) / 100;

	//	If greater than 1, stop transition and reset the timer to process next item
	if( opvalue >= 1 )
	{
		//	Set to max (1)
		opvalue	= 1;
		ticker_object.style.opacity	= opvalue;
		ticker_object.style.filter	= "alpha(opacity=" + ( 100 * opvalue ) + ");";	//	IE hack

		//	Stop the transition
		clearInterval( eventfade );

		//	Prevent memory leaks
		clearTimeout( eventticker );

		//	Is it stopped (mouseover pauses the ticker)
		eval( "stopped	= " + id + "stopped;" );

		//	If not stopped, set the timer to process next item
		if( !stopped )
		{
			eventticker	= setTimeout( "TickerShowNext('"+id+"');", interval );
		}
	}

	//	Set current transition opacity
	ticker_object.style.opacity	= opvalue;
	ticker_object.style.filter	= "alpha(opacity=" + ( 100 * opvalue ) + ");";	//	IE hack

}

//=========================================================================================================
//	Suspend the ticker (on mouseover)
//=========================================================================================================
function TickerStop( id )
{
	//	Set the sopped flag
	eval( id + "stopped	= 1;" );

	//	Suspend the ticker
	clearTimeout( eventticker );
}

//=========================================================================================================
//	Resume the ticker (on mouseout)
//=========================================================================================================
function TickerResume( id )
{
	//	Get the sopped flag
	eval( "stopped	= " + id + "stopped;" );

	//	If suspended, resume the ticker
	if( stopped )
	{
		//	Get the ticker interval
		eval( "interval		= " + id + "interval;" );

		//	Prevent memory leaks (make sure one isn't already in progress)
		clearTimeout( eventticker );

		//	Set the timer to process the next item
		eventticker	= setTimeout( "TickerShowNext('"+id+"');", interval );

		//	Clear the stopped flag
		eval( id + "stopped	= 0;" );
	}
}


