/* Timing settings */
var textscrollerStopMs = 5000;
var textscrollerSlideInMs = 1500;
var textscrollerFadeOutMs = 1000;

/* Dynamic variables */
var textscrollerText = null;
var textscrollerTextTopY = 0;
var textscrollerTextBottomY = 0;
var textscrollerLinks = null;
var textscrollerMax = 0;
var textscrollerLoop = 0;
var textscrollerTimeout = null;

$(document).ready(textscrollerInit);

function textscrollerInit()
{
	/* Required when using 24 bit png on IE6
	if (typeof(DD_belatedPNG) == 'object')
	{
		DD_belatedPNG.fix('.textscroller-textcontainer a');
	}
	* Also include following in the markup from: http://www.dillerdesign.com/experiment/DD_belatedPNG/
	<!--[if IE 6]>
	<script type="text/javascript" src="DD_belatedPNG_0.0.8a-min.js"></script>
	<![endif]-->
	* And activate non animated hiding for IE below.
	*/
	var main = $(".textscroller-maincontainer");
	main.css("height", main.height());
	textscrollerText = main.find(".textscroller-textcontainer");
	textscrollerTextTopY = textscrollerText.css("top");
	textscrollerTextBottomY = main.height() + 30;
	textscrollerLinks = textscrollerText.find("a");
	textscrollerMax = textscrollerLinks.size();
	textscrollerTextTweenIn();
}

function textscrollerTextTweenIn()
{
	textscrollerLinks.css("display", "none").eq(textscrollerLoop).css("display", "block");
	textscrollerText.show();
	textscrollerText.css("top", textscrollerTextBottomY);
	textscrollerText.animate({top: textscrollerTextTopY}, textscrollerSlideInMs, textscrollerWait);
}

function textscrollerWait()
{
	textscrollerTimeout = setTimeout("textscrollerTextTweenOut()", textscrollerStopMs);
}

function textscrollerTextTweenOut()
{
	clearTimeout(textscrollerTimeout);
	/* Fading out does not work on any IE with alpha png. This is an alternative non animated hiding.
	if ($.browser.msie)
	{
		//textscrollerText.animate({top: textscrollerTextBottomY}, textscrollerFadeOutMs, textscrollerLoopCarusel);
		textscrollerText.hide();
		textscrollerLoopCarusel();
	}
	*/
	textscrollerText.fadeOut(textscrollerFadeOutMs, textscrollerLoopCarusel);
}

function textscrollerLoopCarusel()
{
	textscrollerLoop++;
	if (textscrollerLoop >= textscrollerMax)
	{
		textscrollerLoop = 0;
	}
	textscrollerTextTweenIn();
}

