var scrollerdelay='4000' //delay between msg scrolls. 3000=3 seconds.
var scrollspeed=50;
var scrollerwidth='142px'
var scrollerheight='195px'

///////Do not edit pass this line///////////////////////
// some new variables
var scroll_running = 0;
var scroll_stopped = 0;
var scroll_stopCompleted = 0;
var scroll_scrollnext = 1;
var scroll_topLayer;
var scroll_bottomLayer;
var scroll_i=2;
if(messages.length<3){
	scroll_i=0;
}

function scroll_move1(whichdiv){
	scroll_tdiv=eval(whichdiv)
	if (parseInt(scroll_tdiv.style.top)>0&&parseInt(scroll_tdiv.style.top)<=5){
		scroll_tdiv.style.top=0+"px"
		if (scroll_stopped == 1) {scroll_switchButton(1); return;}
		setTimeout("scroll_move1(scroll_tdiv)",scrollerdelay)
		setTimeout("scroll_move2(scroll_second_obj)",scrollerdelay)
		return
	}
	if (parseInt(scroll_tdiv.style.top)>=scroll_tdiv.offsetHeight*-1){
		if (scroll_stopped == 1 && parseInt(scroll_tdiv.style.top) == 0) {scroll_switchButton(1); return;}
		if (scroll_stopped == 1 && parseInt(scroll_tdiv.style.top) == parseInt(scrollerheight)) {scroll_switchButton(1); return;}
		scroll_tdiv.style.top=parseInt(scroll_tdiv.style.top)-5+"px"
		setTimeout("scroll_move1(scroll_tdiv)",scrollspeed)
	}
	else{
		scroll_tdiv.style.top=parseInt(scrollerheight)
		scroll_tdiv.innerHTML=messages[scroll_i]
		scroll_itemStatus();
		if (scroll_i==messages.length-1)
			scroll_i=0
		else
			scroll_i++
	}
}

function scroll_move2(whichdiv){
	scroll_tdiv2=eval(whichdiv)
	if (parseInt(scroll_tdiv2.style.top)>0&&parseInt(scroll_tdiv2.style.top)<=5){
		scroll_tdiv2.style.top=0+"px"
		if (scroll_stopped == 1) {scroll_switchButton(1); return;}
		setTimeout("scroll_move2(scroll_tdiv2)",scrollerdelay)
		setTimeout("scroll_move1(scroll_first_obj)",scrollerdelay)
		return
	}
	if (parseInt(scroll_tdiv2.style.top)>=scroll_tdiv2.offsetHeight*-1){
		if (scroll_stopped == 1 && parseInt(scroll_tdiv2.style.top) == 0) {scroll_switchButton(1); return;}
		if (scroll_stopped == 1 && parseInt(scroll_tdiv2.style.top) == parseInt(scrollerheight)) {scroll_switchButton(1); return;}
		scroll_tdiv2.style.top=parseInt(scroll_tdiv2.style.top)-5+"px"
		setTimeout("scroll_move2(scroll_second_obj)",scrollspeed)
	}
	else{
		scroll_tdiv2.style.top=parseInt(scrollerheight)
		scroll_tdiv2.innerHTML=messages[scroll_i]
		scroll_itemStatus();
		if (scroll_i==messages.length-1)
			scroll_i=0
		else
			scroll_i++
	}
}

function startscroll(){
	// make sure function doesn't fun twice
	if (scroll_running != 0)
		return

	scroll_running++
	scroll_first_obj=document.getElementById("scroll_first")
	scroll_second_obj=document.getElementById("scroll_second")
	scroll_move1(scroll_first_obj)
	scroll_second_obj.style.top=scrollerheight
	scroll_second_obj.style.visibility='visible'
	scroll_switchButton(0);
	document.getElementById("scroll_itemStatus").innerHTML = getMess(1) + ' OF ' + members;
}

function scroll_itemStatus() {
	document.getElementById("scroll_itemStatus").innerHTML = getMess(scroll_i) + ' OF ' + members;
}

function getMess(variable){
	var mes=variable-1;
	if(mes<0) mes=messages.length-1;
	var lastItem=(mes==messages.length-1?members:(mes+1)*numMembers);
	var firstItem=mes*numMembers+1;
	return(firstItem +"-"+lastItem);
}

function stopScroll() {
	scroll_stopped = 1;
	scroll_switchButton(2);
}

function restartScroll() {
	if (scroll_stopped == 0 ) {return;}
	scroll_stopped = 0;
	if (scroll_scrollnext == 0) {
		if (scroll_i==messages.length-1) {
			scroll_i=1;
		} else if (i==messages.length-2) {
			scroll_i=0;
		} else {
			scroll_i=scroll_i+2
		}
	}
	
	setTimeout("scroll_move1(scroll_first_obj)",scrollerdelay);
	setTimeout("scroll_move2(scroll_second_obj)",scrollerdelay);
	
	scroll_switchButton(0);
	scroll_scrollnext = 1;
	scroll_stopCompleted = 0;
}

function scroll_switchButton(what) {
	if (what==0) {
		document.getElementById("scroll_startstop").innerHTML = '<a href="javascript:stopScroll();"><img src="../../includes/site_images/modules/hold.gif" namd="hold" border="0" align="middle" width="13" height="13" alt="Pause" onMouseOver="scrollIconSwap(\'hold\',this,0);" onMouseOut="scrollIconSwap(\'hold\',this,1);"></a>';
		document.getElementById("scroll_nextbutton").innerHTML = '<a href="javascript:nextScroll();"><img src="../../includes/site_images/modules/next.gif" name="next" border="0" align="absmiddle" width="4" height="13" alt="Next" onMouseOver="scrollIconSwap(\'next\',this,0);" onMouseOut="scrollIconSwap(\'next\',this,1);"></a>';
		document.getElementById("scroll_backbutton").innerHTML = '<a href="javascript:backScroll();"><img src="../../includes/site_images/modules/back.gif" name="back" border="0" align="absmiddle" width="4" height="13" alt="Back" onMouseOver="scrollIconSwap(\'back\',this,0);" onMouseOut="scrollIconSwap(\'back\',this,1);"></a>';
	} else if (what==1) {
		first2_top=parseInt(document.getElementById("scroll_first").style.top)
		second2_top=parseInt(document.getElementById("scroll_second").style.top)
		if ((first2_top != 0 && first2_top != parseInt(scrollerheight)) || (second2_top != 0 && second2_top != parseInt(scrollerheight))) {
			setTimeout("scroll_switchButton(1)",50)
			return;
		}
		document.getElementById("scroll_startstop").innerHTML = '<a href="javascript:restartScroll();"><img src="../../includes/site_images/modules/play.gif" name="play" border="0" align="middle" width="13" height="13" alt="Play" onMouseOver="scrollIconSwap(\'play\',this,0);" onMouseOut="scrollIconSwap(\'play\',this,1);"></a>';
		document.getElementById("scroll_nextbutton").innerHTML = '<a href="javascript:nextScroll();"><img src="../../includes/site_images/modules/next.gif" name="next" border="0" align="absmiddle" width="4" height="13" alt="Next" onMouseOver="scrollIconSwap(\'next\',this,0);" onMouseOut="scrollIconSwap(\'next\',this,1);"></a>';
		document.getElementById("scroll_backbutton").innerHTML = '<a href="javascript:backScroll();"><img src="../../includes/site_images/modules/back.gif" name="back" border="0" align="absmiddle" width="4" height="13" alt="Back" onMouseOver="scrollIconSwap(\'back\',this,0);" onMouseOut="scrollIconSwap(\'back\',this,1);"></a>';
		scroll_stopCompleted = 1;
	} else if (what==2) {
		document.getElementById("scroll_startstop").innerHTML = '<img src="../../includes/site_images/modules/wait.gif" border="0" align="middle" width="13" height="13" alt="Wait">';
		document.getElementById("scroll_nextbutton").innerHTML = '<img src="../../includes/site_images/modules/next.gif" name="next" border="0" align="absmiddle" width="4" height="13" alt="Next">';
		document.getElementById("scroll_backbutton").innerHTML = '<img src="../../includes/site_images/modules/back.gif" name="back" border="0" align="absmiddle" width="4" height="13" alt="Back">';
	}
}

function scrollIconSwap(iconImg, what, which) {
	var imgPath = "../../includes/site_images/modules/";
	if (which == 0) {
		what.src = imgPath + iconImg + "_over.gif";
	} else {
		what.src = imgPath + iconImg + ".gif";
	}
}

function nextScroll() {
	if (scroll_stopped == 0) {	stopScroll(); }
	if (scroll_stopCompleted == 0) {
		setTimeout("nextScroll()",scrollspeed)
		return;
	}
	if (parseInt(document.getElementById("scroll_first").style.top)==0) {
		scroll_topLayer = document.getElementById("scroll_first");
		scroll_bottomLayer = document.getElementById("scroll_second");
	} else {
		scroll_bottomLayer = document.getElementById("scroll_first");
		scroll_topLayer = document.getElementById("scroll_second");
	}
	if (scroll_scrollnext == 0) {
		if (scroll_i==messages.length-1) {
			scroll_i=1;
		} else if (scroll_i==messages.length-2) {
			scroll_i=0;
		} else {
			scroll_i=scroll_i+2
		}
	}
	eval(scroll_topLayer).innerHTML = (scroll_i==0?messages[messages.length-1]:messages[scroll_i-1]);
	eval(scroll_bottomLayer).innerHTML = messages[scroll_i];
	scroll_itemStatus();
	scroll_scrollnext = 1;
	if (scroll_i==messages.length-1) {
		scroll_i=0;
	} else {
		scroll_i++;
	}
}

function backScroll() {
	if (scroll_stopped == 0) {	stopScroll(); }
	if (scroll_stopCompleted == 0) {
		setTimeout("backScroll()",scrollspeed)
		return;
	}
	if (parseInt(document.getElementById("scroll_first").style.top)==0) {
		scroll_topLayer = document.getElementById("scroll_first");
		scroll_bottomLayer = document.getElementById("scroll_second");
	} else {
		scroll_bottomLayer = document.getElementById("scroll_first");
		scroll_topLayer = document.getElementById("scroll_second");
	}
	if (scroll_scrollnext == 1) {
		if (scroll_i==0) {
			scroll_i=messages.length-2;
		} else if (scroll_i==1) {
			scroll_i=messages.length-1;
		} else {
			scroll_i=scroll_i-2
		}
	}
	eval(scroll_topLayer).innerHTML = (scroll_i==0?messages[messages.length-1]:messages[scroll_i-1]);
	eval(scroll_bottomLayer).innerHTML = messages[scroll_i];
	scroll_itemStatus();
	scroll_scrollnext = 0;
	if (scroll_i==0) {
		scroll_i=messages.length-1;
	} else {
		scroll_i--;
	}
}

document.writeln('<div id="main" style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hidden;">')
document.writeln('<div style="position:absolute;width:'+scrollerwidth+';height:'+scrollerheight+';clip:rect(0 '+scrollerwidth+' '+scrollerheight+' 0);left:0px;top:0px">')
document.writeln('<div id="scroll_first" style="position:absolute;width:'+scrollerwidth+';left:0px;top:1px;">')
document.write(messages[0])
document.writeln('</div>')
document.writeln('<div id="scroll_second" style="position:absolute;width:'+scrollerwidth+';left:0px;top:0px;visibility:hidden">')
if(messages.length==1){
	document.write(messages[0])
}else{
	document.write(messages[1])
}
document.writeln('</div>')
document.writeln('</div>')
document.writeln('</div>')

MM_preloadImages("../../includes/site_images/modules/hold_over.gif","../../includes/site_images/modules/next_over.gif","../../includes/site_images/modules/back_over.gif","../../includes/site_images/modules/wait.gif","../../includes/site_images/modules/play.gif","../../includes/site_images/modules/play_over.gif");

window.onload=startscroll;

