var marqueePos = -1;
var timeout = null;
var is_visible = true;
var marqueeText = [
	"Never stop laughing.",
	"Small changes today---big results tomorrow.",
	"Endeavor to simplify things, not complicate them.",
	"Life is pleasurable; anyone who tells you otherwise is a masochist.",
	"Grace is but glory begun, and glory is but grace perfected.",
	"Master Yoda: You must train yourself to let go of all that you fear to lose.",
	"Happiness is a direction, not a destination.",
	"When the gods wish to punish us, they give us what we want.",
	"Heaven and hell are states of mind.",
	"Ghandi: You must be the change that you wish to see in the world.",
	"Those who know, don't speak; and those who speak, don't know.",
	"Johnnie's secret to maximize productivity: put the task off as long as possible.",
	"There is only one way to gain information: it must be given to you.",
	"Nietzsche: What doesn't kill you makes you stronger.",
	"Einstein: Reality is merely an illusion, albeit a very persistent one.",
	"Nietzsche: In heaven, all the interesting people are missing.",
	"Churchill: If you're going through hell, keep going.",
	"Descartes: To be is to do.",
	"Voltaire: To do is to be.",
	"Burke: All that is required for evil to prevail is for good men to do nothing.",
	"Winners are losers who didn't give up." ];

function changeMarqueeText ()
{
	document.getElementById ( "marquee" ).innerHTML = marqueeText [ marqueePos ];
}

function setMarqueeOpacityForAllBrowsers ( alpha ) {
	document.getElementById ( "marquee" ).style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity:" + alpha + ")";	// MSIE
	document.getElementById ( "marquee" ).style.KHTMLOpacity = alpha / 100;	// Safari < 1.2, Konqueror
	document.getElementById ( "marquee" ).style.MozOpacity = alpha / 100;	// Older Mozilla & Firefox
	document.getElementById ( "marquee" ).style.opacity = alpha / 100;	// Safari 1.2+, newer Mozilla & Firefox, CSS3
}

function affectMarquee ( currentAlpha, increment, cbFuncName ) {

	var alpha = currentAlpha + increment;

	// have we gone beyond either threshold?
	if ( alpha < 0 || alpha > 95 )	// use 95 so code jumps from 95 -> 99; Mozilla flickers the div if 95 -> 100
	{
		// if so, cancel the operation by invoking callback
		if ( cbFuncName != null )
			cbFuncName ();
	} else {
		// else, adjust transparency and setup the next adjustment
		setMarqueeOpacityForAllBrowsers ( alpha );
		setTimeout ( "affectMarquee ( " + alpha + ", " + increment + ", " + cbFuncName + " )", 25 );
	}
}


function marqueeDisappear ()
{
	affectMarquee ( 100, -5, "marqueeDisappearCallback" );
}

function marqueeAppear ()
{
	affectMarquee ( 0, 5, "marqueeAppearCallback" );
}

function marqueeDisappearCallback ()
{
	is_visible = false;
	marqueeForward ();
	marqueeAppear ();
}

function marqueeAppearCallback ()
{
	is_visible = true;
	setMarqueeOpacityForAllBrowsers ( 99 );
	timeout = setTimeout ( "marqueeDisappear ()", 10000 );
}

function marqueeForward ()
{
	if ( timeout != null ) clearTimeout ( timeout ); // cancel the pending fade out
	marqueePos++;
	if ( marqueePos >= marqueeText.length ) marqueePos = 0;
	changeMarqueeText ();

	if ( is_visible )
		timeout = setTimeout ( "marqueeDisappear ()", 10000 ); // reschedule the fade out in another 10 s
}

function marqueeBackward ()
{
	if ( timeout != null ) clearTimeout ( timeout ); // cancel the pending fade out
	marqueePos--;
	if ( marqueePos < 0 ) marqueePos = marqueeText.length - 1;
	changeMarqueeText ();

	if ( is_visible )
		timeout = setTimeout ( "marqueeDisappear ()", 10000 ); // reschedule the fade out in another 10 s
}

function startMarquee ()
{
	marqueeDisappear ();
}