IE = document.all ? true : false;
var htext=new Array();
var TimerOn=-1;
var timerHide=-1;
var timerShow=-1;
var Timer2=-1;
var sleepTimer=-1;
var altActive=-1;
var altPic=-1;
var moveID='';
var mx=0;
var my=0;
var mtarget=null;
var hideTimeout=1000;
var showTimeout=400;
var myadjust=18-80;
var mxadjust=16+10;
var debug='';
var hideCallback=null;
var ns_db = (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
var is_ie = navigator.userAgent.indexOf('MSIE')>0;

function divIn(){
  if(moveID=='')return;
  var ad=document.getElementById(moveID);
  if(timerHide>0){
    clearTimeout(timerHide);
  }
}
function divOut(){
  if(moveID=='')return;
  var ad=document.getElementById(moveID);
  if(timerHide>0){
    clearTimeout(timerHide);
  }
  timerHide=setTimeout(doHideAlt,hideTimeout);
}

function sleep(n){
  if(n==-1){
    sleepTimer=-1;
    return;
  }
  if(sleepTimer==-1){
    sleepTimer=setTimeout("sleep(-1)",n);
    return true;
  }else{
    return false;
  }
}
function getAbsolutePosition(element) {
  var r = { x: element.offsetLeft, y: element.offsetTop };
  if (element.offsetParent) {
    var tmp = getAbsolutePosition(element.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
};
function captureMove(ee){
	var e = ee?ee:window.event;
  mtarget=ee?e.target:e.srcElement;
  
  var ad=false;
  if(e.pageX){
    mx=e.pageX;
    my=e.pageY;
  }else{
    mx=e.clientX;
    my=e.clientY;
  }
  if(moveID!='')ad=document.getElementById('altdiv');
  if(moveID!='')
    setMove();
}
function captureClick(ee){
	var e = ee || window.event;
  var ad=document.getElementById('altdiv');
  if(e.pageX){
    mx=e.pageX;
  }else{
    mx=e.x;
  }
}
function showAlt(altid){
  var ad=document.getElementById(altid);
//  if (TimerOn>=0) { clearTimeout(TimerOn); TimerOn=-1; }

//  if(moveID==''){
  if(timerHide>0){
    clearTimeout(timerHide);timerHide=-1;
    return;
  }
  if(altActive<0){
    moveID=altid;
    timerShow=setTimeout(doShowAlt,showTimeout);
/*    altActive=1;
    moveID=altid;
    setMove();
    ad.style.display='block';
    ad.onmouseout=divOut;
    ad.onmouseover=divIn;*/
  }else{
    if(timerHide>0){
      alert(timerHide);
      clearTimeout(timerHide);timerHide=-1;
    }
  }
}
function showAltNow(altid){
  var ad=document.getElementById(altid);
//  if (TimerOn>=0) { clearTimeout(TimerOn); TimerOn=-1; }

//  if(moveID==''){
  if(timerHide>0){
    clearTimeout(timerHide);timerHide=-1;
    return;
  }
  if(altActive<0){
    moveID=altid;
    doShowAlt();
/*    altActive=1;
    moveID=altid;
    setMove();
    ad.style.display='block';
    ad.onmouseout=divOut;
    ad.onmouseover=divIn;*/
  }else{
    if(timerHide>0){
      alert(timerHide);
      clearTimeout(timerHide);timerHide=-1;
    }
  }
}

function doShowAlt(){
  timerShow=-1;
  if(moveID==''){
    altActive=-1;
    return;
  }
  var ad=document.getElementById(moveID);
  altActive=1;
  setMove();
  ad.style.display='block';
  ad.onmouseout=divOut;
  ad.onmouseover=divIn;
}
function hideAlt(){
  altPic=0;
  if(timerShow>0){
//    moveID='';
    clearTimeout(timerShow);timerShow=-1;
    return;
  }
  if(timerHide>0){
    clearTimeout(timerHide);timerHide=-1;
  }
/*  if(moveID==''){
    altActive=-1;
  }*/
  timerHide=setTimeout(doHideAlt,hideTimeout);
}
function hideAltNow(){
  if(timerShow>0){
    clearTimeout(timerShow);timerShow=-1;
    return;
  }
  if(timerHide>0){
    clearTimeout(timerHide);timerHide=-1;
  }
  doHideAlt();
}
function doHideAlt(){
  if(moveID!=''){
    timerHide=-1;
    var ad=document.getElementById(moveID);
    ad.style.display='none';
    ad.onmouseout='';
    ad.onmouseover='';
    altActive=-1;
    if(hideCallback!=null){
      hideCallback();
      hideCallback=null;
    }
    moveID='';
  }
}
function setMove(){
  if(moveID=='')return;
  var ad=document.getElementById(moveID);
  if(altActive>0){
/*    var hx = mx+document.body.scrollLeft;
    var hy = my+document.body.scrollTop;*/
/*      doch=document.body.offsetHeight+document.body.scrollTop;
    docw=document.body.offsetWidth+document.body.scrollLeft;
    a=parseInt(ad.style.height);
    b=parseInt(ad.style.width);
    if((a+hy+40)>doch){
      hy=hy-40-a;
    }
    if((b+hx+40)>docw){
      hx=hx-63-a;
    }*/
//    ad.style.top=(my+16)+'px';
    if(is_ie){
      ad.style.top=(my+document.body.scrollTop+18)+'px';
      ad.style.left=(mx+document.body.scrollLeft+16)+'px';
    }else{
      ad.style.top=(my+myadjust)+'px';
      ad.style.left=(mx+mxadjust)+'px';
    }
    altActive=-1;
  }
}
function showPicture(altid,picid,nn,pid,online,gender){
  var picid36=base_convert(picid,10,36);
  var picdir=base_convert(picid%(36*36),10,36);
  var ad=document.getElementById(altid);
  var adb=document.getElementById('altdivbar');
  var adnn=document.getElementById('altdivnn');
  var adpl=document.getElementById('altdivpl');
  adb.style.display='none';
  var tmp='No:'+pid+'<br>&nbsp;'+nn+'&nbsp;<a href="/profile/'+pid+'.html" target="blank" title="Open profile in new window" style="padding:1px;"><img src="/img/popup.png" border=0></a>&nbsp;<BR>';
  tmp+='<font color='+(online?'green':'red')+'><b>';
  tmp+=online?lang_online:lang_offline;
  tmp+='</b></a>';
//  tmp+='<BR>'+mx+':'+my;
//  tmp+='<BR>'+debug;
  adnn.innerHTML=tmp;
  if(picid<=0){
    adpl.href='';
    adpl.onclick=function(){return false;};
  } else {
      adpl.href='/photos/'+picdir+'/p-'+picid36+'.jpg';
      adpl.onclick=null;
    }
  if(altPic!=picid && moveID!=''){
    if(is_ie){
      ad.style.top=(my+document.body.scrollTop+18)+'px';
      ad.style.left=(mx+document.body.scrollLeft+16)+'px';
    }else{
      ad.style.top=(my+myadjust)+'px';
      ad.style.left=(mx+mxadjust)+'px';
    }
//    setMove();
  }
  pic=ad.getElementsByTagName('IMG')[0];
  if(picid<=0){
    pic.src="/img/"+(gender=="m"?"tn-man.png":gender=="w"?"tn-woman.png":"nophoto-120x120.png");
    pic.src="/img/nophoto-120x120.png";
  } else {
    pic.src="/photos/"+picdir+'/t-'+picid36+'.jpg';
  }
  altPic=picid;
  hideCallback=hidePicture;
  showAlt(altid);
}
function hidePicture(){
  var ad=document.getElementById(moveID);
  pic=ad.getElementsByTagName('IMG')[0];
  pic.src="/img/spacer.gif";
}
function hideHelp(){
  var altscript=document.getElementById('genaltscript');
  altscript.src='/js/help/clean.js';
}
function showHelp(helpid,lang){
  var ad=document.getElementById('genalt');
  var altscript=document.getElementById('genaltscript');
//  var tmp='<div id=helpdiv>Help</div>';
//  ad.innerHTML=tmp;
  ad.style.width='320px';
  ajaxpage('/help/'+lang+'/'+helpid+'.htm','genalt');
//  hideCallback=hideHelp;
  showAlt('genalt');
}
document.onmousemove = captureMove;
//document.onclick = captureClick;

