function ScrollWindow(n,s,d) {
  if (!document.getElementById(n)) {return}
  this.speed=s
  this.direction=d
  this.stop=false
  var obj=document.getElementById(n)
  var temp=obj.innerHTML
  obj.innerHTML='<div id=\"'+n+'1\" style=\"position: absolute; left: 0px; top: 0px; width: auto; height: auto\" onmouseover=\"smsg.ScrollPause(true)\" onmouseout=\"smsg.ScrollPause(false)\"></div><div id=\"'+n+'2\" style=\"position: absolute; left: 0px; top: 0px; width: auto; height: auto\" onmouseover=\"smsg.ScrollPause(true)\" onmouseout=\"smsg.ScrollPause(false)\"></div>'
  this.content=document.getElementById(n+'1')
  this.trailer=document.getElementById(n+'2')
  this.content.style.textAlign=obj.style.textAlign
  this.trailer.style.textAlign=obj.style.textAlign
  if (d=='v') {
    this.content.innerHTML=temp
    this.content.style.width=obj.style.width
    this.trailer.style.width=obj.style.width
  }
  else {
    this.content.innerHTML=temp
    this.content.style.height=obj.style.height
    this.trailer.style.height=obj.style.height
  }
  if (d=='v') {
    this.containerheight=parseInt(obj.style.height)
    this.contentheight=this.content.offsetHeight
    if (this.contentheight>this.containerheight) {
      if (s>0) {
        this.trailer.style.top=this.contentheight+'px'
        this.trailer.innerHTML=temp
        var thisobj=this
        setTimeout(function(){thisobj.ScrollUp()}, 3000)
      }
      else {
        this.content.style.height=obj.style.height
        this.content.style.overflow='scroll'
      }
    }
  }
  else {
    this.containerwidth=parseInt(obj.style.width)
    this.contentwidth=this.content.offsetWidth
    if (this.contentwidth>this.containerwidth) {
      if (s>0) {
        this.trailer.style.left=this.contentwidth+'px'
        this.trailer.innerHTML=temp
        var thisobj=this
        setTimeout(function(){thisobj.ScrollUp()}, 3000)
      }
      else {
        this.content.style.width=obj.style.width
        this.content.style.overflow='scroll'
      }
    }
  }
}

ScrollWindow.prototype.ScrollUp=function() {
  if (this.direction=='v') {
    if (parseInt(this.content.style.top)<=-this.contentheight) {
      this.content.style.top='0px'
      this.trailer.style.top=this.contentheight+'px'
    }
  }
  else {
    if (parseInt(this.content.style.left)<=-this.contentwidth) {
      this.content.style.left='0px'
      this.trailer.style.left=this.contentwidth+'px'
    }
  }
  var thisobj=this
  setTimeout(function(){thisobj.ScrollUp()}, 30)
  if (this.stop) {return}
  if (this.direction=='v') {
    this.content.style.top=parseInt(this.content.style.top)-this.speed+'px'
    this.trailer.style.top=parseInt(this.trailer.style.top)-this.speed+'px'
  }
  else {
    this.content.style.left=parseInt(this.content.style.left)-this.speed+'px'
    this.trailer.style.left=parseInt(this.trailer.style.left)-this.speed+'px'
  }
}

ScrollWindow.prototype.ScrollPause=function(p) {
  this.stop=p
}

var lastchatstat=''
var chatwinw='0'

function ChatAjax_Start() {
  try {return new ActiveXObject("Msxml2.XMLHTTP");} catch(e) {}
  try {return new ActiveXObject("Microsoft.XMLHTTP");} catch(e) {}
  try {return new XMLHttpRequest();} catch(e) {}
  return null;
}

function ChatAjax_Get() {
  var chatajx = ChatAjax_Start();
  chatajx.onreadystatechange = function () {
    if (chatajx.readyState==4) {
      if (chatajx.status==200) {
	if (lastchatstat!=chatajx.responseText) {
          lastchatstat=chatajx.responseText
          var c=lastchatstat.split('\r\n')
          chatwinw=c[0]
          document.getElementById('ChatStatus').style.background='url(/images/'+c[1]+')'
          if (c[0]=='0') {document.getElementById('ChatStatus').style.cursor=''}
          else {document.getElementById('ChatStatus').style.cursor='pointer'}
        }
      }
    }
  }
  chatajx.open('GET', '/chat/chat.asp?i=i', true)
  chatajx.setRequestHeader("Content-Type", "text/xml")
  chatajx.send();
  setTimeout(function(){ChatAjax_Get()}, 15000)
}

function OpenChatWindow() {
  if (chatwinw=='0') {return}
  window.open('http://www.intelligenttracing.co.uk/chat/chat.asp','Chat','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width='+chatwinw+',height=600')
}

var smsg
var scriptstarted = false
function ScriptInit() {
  if (scriptstarted) {return}
  scriptstarted = true
  smsg=new ScrollWindow('scrlmsg',1,'h')
  ChatAjax_Get()
}

if (window.attachEvent) {
  window.attachEvent("onload", ScriptInit)
}
else if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", ScriptInit, false)
}
else {
  window.onload = ScriptInit
}

