var locX=0;
var locY=200;
var imgW=0;
var maxX=0;
var getC=0;
var docW=document.body.clientWidth;
var hldX=0;
var incX=1;
var cStat=1;
imgPoll=new Image();
imgPoll.onload=chkImg;
document.write('<div name="woInvite" id="woInvite" style="position: absolute; top:200; left: 0; z-index: 999" align="right">');
document.write('&nbsp;</div>');
setTimeout("getImg()",1000);
function woMove(){
 // debug('woMove()');
 if(hldX==0){
  newX=locX+incX;
  if(incX>0){
   if(newX<maxX){
    locX=newX;woDIVs.left=locX + 'px'; // RAK CORRECTION
    setTimeout('woMove()',12);
   } else {
    incX=-1;
    setTimeout('woMove()',1000);
   }
  } else {
   if(locX>0){
    locX=newX;woDIVs.left=locX + 'px'; // RAK CORRECTION
    setTimeout('woMove()',6);
   } else {
    setTimeout('stopInvite()',4000);
   }
 }
 }
}
function getImg(){
 // debug('getImg()');
 var rTimer=5000;
 if(cStat==1){
  // var pUrl="http://192.168.1.29:8080/poll.gif?domain=rakmac.digitalmail.com&stamp="+(new Date()).getTime();
  var pUrl="http://"+dmx_chatserver+":8080/poll.gif?domain="+domain+"&stamp="+(new Date()).getTime(); // RAK AMENDED LINE
  if(typeof(sSession)!="undefined"){pUrl+="&u="+sSession;}
  imgPoll.src=pUrl;
 }
 getC++;
 if(getC>6)rTimer=10000;
 if(getC>20)rTimer=15000;
 if(getC>30)rTimer=0;
 if(rTimer>0)setTimeout("getImg()",rTimer);
}
function chkImg(){
 // debug('chkImg()');
 if(imgPoll!=null){
  nStat=imgPoll.width;
  if(nStat!=cStat){
   cStat=nStat;
   if(cStat==3)startChat();
   if(cStat==2)startInvite();
   if(cStat==1)stopInvite();
  }
 }
}
function getIImgw(){
 // debug('getIImgw()');
 imgW=woIMG.width;maxX=docW-imgW-22;
}
function startInvite(){
 // debug('startInvite()');
 var ofsY;
 // ofsY=document.body.scrollTop; // RAK: commented out original code
 ofsY = typeof window.pageYOffset == 'number' ? window.pageYOffset : document.documentElement.scrollTop; // RAK alternative
 hldX=0;incX=1;locX=10;locY=200;
 woDIVs=document.getElementById('woInvite').style;
 woDIVh=document.getElementById('woInvite');
 // woDIVh.innerHTML='<a href="javascript:void(0);" onclick="return startChat(event);" onMouseOver="anPause()" onMouseOut="anResume()"><img border="0" src="http://192.168.1.29:8080/invite.gif?domain=rakmac.digitalmail.com&stamp='+(new Date()).getTime()+'" name="woIImg"</a>';
 woDIVh.innerHTML='<a href="javascript:void(0);" onclick="return startChat(event);" onMouseOver="anPause()" onMouseOut="anResume()" style="border-bottom: 0px;"><img border="0" src="/dmx/core/webchat/images/invite.gif" name="woIImg"></a><img border="0" src="http://'+dmx_chatserver+':8080/invite.gif?domain='+domain+'&stamp='+(new Date()).getTime()+'" style="display: none;">'; // RAK AMENDED
 woDIVs.top=(locY+ofsY) + 'px';woDIVs.left=locX + 'px'; // RAK CORRECTION
 woDIVs.display='block'; // RAK ADDITION
 setTimeout('woMove()',3000);
 woIMG=document.images.woIImg;
 woIMG.onload=getIImgw;
}
function stopInvite(){
 // debug('stopInvite()');
 cStat=1;woDIVh.innerHTML="";
 woDIVs.display='none'; // RAK ADDITION
 setTimeout("getImg()",10000);
}
function startChat(event){
 // debug('startChat()');
 clsX=locX+imgW-22;
 clsY=locY+22;
 if(event.clientX<clsX || event.clientY>clsY){
  // this.chatWindow=window.open("http://192.168.1.29/chat/chatstart.htm?domain=rakmac.digitalmail.com","Chat","width=484,height=361");
  this.chatWindow=window.open("http://"+dmx_chatserver+"/chat/chatstart.htm?domain="+domain+'&bg='+bg_img,"Chat","width=484,height=361"); // RAK AMENDED LINE
  this.chatWindow.focus();this.chatWindow.opener=window;
 }
 stopInvite();
}
function anPause(){
 // debug('anPause()');
 hldX=1;
}
function anResume(){
 // debug('anResume()');
 hldX=0;
 setTimeout('woMove()',1000);
}
