var marqueePos = -1;
var timeout = null;
var is_visible = true;
var marqueeText = [
	"<a href=\"http://www.orzarua.org/AdultEd_Talmud.shtml\" style=\"font-size:14px;color:#0000cd\">Talmud Class</a> with Rabbi Wechsler, Wednesdays 8:00 - 9:30 pm",
	"<a href=\"http://www.orzarua.org/calendar.shtml#sirius.shtml\" style=\"font-size:14px;color:#0000cd\">Rabbi Wechsler Teaches</a> on Sirius Radio 102/XM 155 - Sundays at 3:00 am and 11:00 am",
    "Join Rabbi Wechsler at <a href=\"http://www.aipac.org/about_AIPAC/Learn_About_AIPAC/2841.asp\" style=\"font-size:14px;color:#0000cd\">AIPAC's 2010 Policy Conference</a>, March 21-23 in Wash DC",
    "Support <a href=\"http://www.mercazusa.org\" style=\"font-size:14px;color:#0000cd\">Conservative Judaism in Israel</a> - Join Mercaz USA in time to be counted!",
    "Visit this new online resource: <a href=\"http://www.jewishideasdaily.com\" style=\"font-size:14px;color:#0000cd\">Jewish Ideas Daily</a>",
	"<a href=\"http://www.orzarua.org/audio.shtml\" style=\"font-size:14px;color:#0000cd\">Sh'ma!</a> - Audio library of what's been going on at O\"Z",
	"<a href=\"http://www.orzarua.org/davening.shtml\" style=\"font-size:14px;color:#0000cd\">Shabbat Melodies</a> - Learn melodies for Shaharit and Musaf!",
	"<a href=\"http://www.ujafedny.org/uja-federation-news-2/view/uja-federation-joins-haiti-relief-effort\" style=\"font-size:14px;color:#0000cd\">Haiti Relief Fund</a> - How You Can Help"];


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 ()", 2400 );
}

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 ();
}