var ticTac = null
var room   = ') - 1UP ! Chat Room'
var newmsg = 0

var mouse = 0
var moves = 0

window.document.onmouseover= function beta() { mouse=-1 }
window.document.onmouseout = function alpha() { mouse=1 }



function checkNew() {

var req = new XMLHttpRequest()
req.open('GET','updater.php?id='+lastId+'&'+new Date().getTime()+Math.random(), true)
req.onreadystatechange = function() {

if (req.readyState==4) {

if (req.status==200) {

var text

text=req.responseText; if (text==0) {return;}

var lines
var chatline = ''

text =text.split('"');
lines=text.length-=1
if (moves==20 && newmsg==0) {var border=true} else {var border=false}

for (var i in text) {

if (lines==parseInt(i)+1 && border) {para='<p style="padding-bottom: 6px; border-bottom: 1px solid #e0e0e0">'}
else {para='<p>'}

text[i]  = text[i].split('>');
chatline += para+"<u>!</u> <b>"+text[i][1]+"<b>:</b></b> "+text[i][2]+" <i>// "+text[i][3]+"</i></p>"

}

document.getElementById('fresh').innerHTML = chatline + document.getElementById('fresh').innerHTML
lastId = text[0][0]
if (moves==20) { newmsg+=lines; document.title='('+newmsg+room }

}

else {}

}

}

req.send(null)

}


function countdown() {

moves+=mouse
if (moves<0) {moves=0} else if (moves>20) {moves=20}

var tt = parseInt(document.getElementById('time').innerHTML.substring(3,5),10)-1
if (tt<10) {tt='00:0'+tt} else {tt='00:'+tt}
document.getElementById('time').innerHTML=tt
if (tt=='00:00') {checkNew(); document.getElementById('time').innerHTML='00:20'}

ticTac = setTimeout("countdown()",1000)

}


function aR(aa) { if (aa) {countdown()} else {clearTimeout(ticTac)} }
