startPos = '21px';
endPos = -21;
step = 1;
delay = 25;
timeout = 10000;
message = '';

function getMsg() {
	var xmlhttp;
	// code for IE7+, Firefox, Chrome, Opera, Safari
	if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
	// code for IE6, IE5
	else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			//document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
			if(xmlhttp.responseText != message) {
				message = xmlhttp.responseText;
				doScrollOut();
			}
			else {
				setTimeout('getMsg()',timeout);
			}
		}
	}
	xmlhttp.open("GET","lastmsg.php",true);
	xmlhttp.send();
}	

function doScrollIn() {
	oScrollText.style.top = (parseInt(oScrollText.style.top)-step)+'px';
	if( parseInt(oScrollText.style.top) > 0 ) {
		setTimeout('doScrollIn()',delay);
	}
	else {
		setTimeout('getMsg()',timeout);
	}
}

function doScrollOut() {
	oScrollText.style.top = (parseInt(oScrollText.style.top)-step)+'px';
	//alert(parseInt(oScrollText.style.top));
	if( parseInt(oScrollText.style.top) > endPos ) {
		setTimeout('doScrollOut()',delay);
	}
	else {
		oScrollText.innerHTML = message;
		oScrollText.style.top = startPos;
		doScrollIn();
	}
}

function initScroll() {
	oScrollBox = document.getElementById('scrollBox');
	oScrollText = document.getElementById('scrollText');
	
	oScrollBox.style.overflow = 'hidden';
	oScrollBox.style.textAlign = 'center';

	oScrollText.style.position = 'relative';
	oScrollText.style.top = '25px';

	getMsg()
}

