/*

  coded by Imagician / BionFX for knuddels.com

  http://www.bionfx.de

  successfully tested with: IE4.0, IE5.0, NN4.5

*/

var mausX  = 0;
var mausY  = 0;
var mausXO = -1;
var mausYO = -1;
var changed = false;
var inited = false;

var hoverStarted = 0;
var badHP        = false;

function printUnsupp()
{
  window.status = 'UNSUPPORTED BROWSER! SOME JS WONT WORK, SORRY.';
  return true;
}

function setVis(name, visi)
{
  obj = (document.layers)? document.layers[name] : (document.all)? document.all.tags("div")[name].style : (document.getElementById)? document.getElementById(name).style : 'null';
  if (obj != 'null') obj.visibility = (visi) ? 'visible':'hidden';
  else printUnsupp();
}

function setPos(name, x, y)
{
  if (document.layers)
  {
    document.layers[name].left = x;
    document.layers[name].top  = y;
  }
  else if (document.all)
  {
    document.all.tags("div")[name].style.pixelLeft = x;
    document.all.tags("div")[name].style.pixelTop  = y;
  }
  else if (document.getElementById)
  {
    document.getElementById(name).style.left = x;
    document.getElementById(name).style.top  = y;  
  }
  else printUnsupp();
  
}

function checkPosition(e)
{
  if (!document.all)
  {
    mausX = e.pageX; mausY = e.pageY; // supported by NN4+ and NN6
  }
  else
  {
    mausX = event.clientX + document.body.scrollLeft; mausY = event.clientY + document.body.scrollTop;
  }
}

function setLayers()
{
  setPos('emo', mausX - 10, mausY - 30);
  setPos('quo', mausX + 15, mausY - 60);
}

function reSetLayers()
{
  setPos('emo', 0, 0);
  setPos('quo', 0, 0);
}


function timerInt()
{
  if (inited)
  {
    if (hoverStarted > 0) hoverStarted ++;

    if (((mausX != mausXO) || (mausY != mausYO)) && (hoverStarted > 0)) setLayers();

    if ((hoverStarted == 10) && (badHP)) setVis('quo', true);

    if (hoverStarted > 50) u();

    mausXO = mausX;  mausYO = mausY;
  }

  if (c > 0)
  {
    c ++;

    if (c == 20)
    { c = 0;
      if (lastHovered != '') document.images[lastHovered].src='i/trns.gif';
      lastHovered = '';
    }
  }
}

function s(judgement)
{
  hoverStarted = 1;
  setVis('quo', false);
  setVis('emo', false);

  if (judgement == 1)
  {
    setLayers();
    setVis('emo', true);
    badHP = true;
  }
  else badHP = false;

 window.status='';
//window.status = nick+g(nick)+' HP'; should get #nicko -> nick as 2nd arg.

}

function u()
{
  c = 1;  // start "edit" - fade counter
  hoverStarted = 0;
  setVis('emo', false);
  setVis('quo', false);
  reSetLayers()
  window.status = '';
}

function init()
{
  if (document.layers)
    document.captureEvents(Event.MOUSEMOVE);  // only NN4+ _needs_ this

  document.onmousemove = checkPosition;

  window.setInterval('timerInt()',100);

  inited = true;
}

/*

this goes for that >edit stuff...

*/

var lastHovered = '';
var c = 0;

function fBreite()
{
  /* if (!document.all)
    xx = top.innerWidth; //supported by NN4+ and NN6
  else */
    // xx = top.document.body.clientWidth; disallowed
    xx = 750;

  return xx;
}

function fHoehe()
{
  /* if (!document.all)
    yy = top.innerHeight; //supported by NN4+ and NN6
  else */
    // yy = top.document.body.clientHeight; disallowed
    { yy = 850; if (yy > (screen.availHeight - 100) ) yy = screen.availHeight - 200 }

  return yy;
}

function o(domain,nick,nu)
{
  if (lastHovered == 'n'+nu)
  {
    xb = fBreite(); ueps = fHoehe();

    editWin = window.open( '', 'edit',  'width='+xb+',height='+ueps+',location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes');
    editWin.moveTo( (screen.availWidth/2) - (xb/2), 50 );
    editWin.location.href = 'hp_edit.pl?domain='+domain+'&nickname='+nick;
  }
}

function g(i)
{
  e = i.substring(i.length-1,i.length);
  if ( (e == 's') || (e == 'z') || (e == 'ß') || (e == 'x') || (e == '1') || (e == '6') ) r = "'";
  else r = 's';
  return r;
}

function k(nick)
{
  var result = '';
  result = nick.toLowerCase();
  result = result.replace(/ /g,'_');
  result = result.replace(/\+/g,':');
  return result;
}

function d(nick,col,judge) // this Does unhide the "edit" and calls the lang-judging
{
  c = 0;
  if (lastHovered != '') document.images[lastHovered].src='i/trns.gif';
  lastHovered = 'n'+nick;
  document.images[lastHovered].src='i/edit_'+col+'.gif';
  s(judge);
//  window.status = nick+g(nick)+' HP';
}

function p(nick) // makes the "edit" Permanent when hovered
{
  if (lastHovered == nick) {c = 0;  window.status='HP bearbeiten';} else window.status='';
}

function h() // this puts the "edit"-time Half the way to disappearance
{
  c = 10;
  window.status = '';
}

function b()
{
  window.status = '';
}
