var uagent = navigator.userAgent.toLowerCase();
var is_safari = ((uagent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.") || (uagent.indexOf('konqueror') != -1) || (uagent.indexOf('khtml') != -1));
var is_opera = (uagent.indexOf('opera') != -1);
var is_webtv = (uagent.indexOf('webtv') != -1);
var is_ie = ((uagent.indexOf('msie') != -1) && (!is_opera) && (!is_safari) && (!is_webtv));
var is_ie4 = ((is_ie) && (uagent.indexOf("msie 4.") != -1));
var is_ie7 = ((is_ie) && (uagent.indexOf("msie 7.") != -1));
var is_ie8 = ((is_ie) && (uagent.indexOf("msie 8.") != -1));
var is_moz = (navigator.product == 'Gecko');
var is_ns = ((uagent.indexOf('compatible') == -1) && (uagent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_safari));
var is_ns4 = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_win = ((uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") != -1));
var is_mac = ((uagent.indexOf("mac") != -1) || (navigator.vendor == "Apple Computer, Inc."));
var ua_vers = parseInt(navigator.appVersion);



function my_getbyid(id)
{
  itm = null;
  if (document.getElementById)
  {
    itm = document.getElementById(id);
  }
  else if (document.all)
  {
    itm = document.all[id];
  }
  else if (document.layers)
  {
    itm = document.layers[id];
  }
  return itm;
}

function donone()
{
}

//----------------------------------------------------
// Окно приветствия
// Written By:  Dean
// Автор русского перевода: ..::NiK::..
// Copyright © 2007
//----------------------------------------------------

function d23_hoverprompt(id)
{
  this.obj;
  this.scroll_var;

  this.pos1 = 0;
  this.pos1x = 0;
  this.pos1y = 0;


  this.obj_id = id;
  this.screen_scroll = true;
  this.enable_fade = false;
  this.auto_hide = false;
  this.show_timer = false;
  this.suspend = false;
  this.hide_time = 0;
  this.langs = new Array();

  this.obj = my_getbyid(this.obj_id);

  return this;
}

d23_hoverprompt.prototype.display = function ()
{
  d = this._calc_data();
  this.obj.style.position = 'absolute';
  this.obj.style.display = '';
  this.obj.style.zIndex = 1000;

switch(this.pos1) {
case 1:
  this.obj.style.left = d['scroll_left'] - d['obj_width'] / 2 + this.pos1x + 'px';
  this.obj.style.top = d['scroll_top'] - d['obj_height'] / 2 + this.pos1y + 'px';

break;
case 2:
  this.obj.style.left = d['scroll_left'] + d['doc_width'] - d['obj_width'] / 2 - this.pos1x + 'px';
  this.obj.style.top = d['scroll_top'] - d['obj_height'] / 2 + this.pos1y + 'px';

break;
case 3:
  this.obj.style.left = d['scroll_left'] + d['doc_width'] - d['obj_width'] / 2 - this.pos1x + 'px';
  this.obj.style.top = d['scroll_top'] + d['doc_height'] - d['obj_height'] / 2 - this.pos1y + 'px';

break;
case 4:
  this.obj.style.left = d['scroll_left'] - d['obj_width'] / 2 + this.pos1x + 'px';
  this.obj.style.top = d['scroll_top'] + d['doc_height'] - d['obj_height'] / 2 - this.pos1y + 'px';

break;

default: 
  this.obj.style.left = d['scroll_left'] + d['doc_width'] / 2 - d['obj_width'] / 2 + this.pos1x + 'px';
  this.obj.style.top = d['scroll_top'] + d['doc_height'] / 2 - d['obj_height'] / 2 + this.pos1y + 'px';
}


  if (this.screen_scroll)
  {
    this.scroll_var = setInterval(this.obj_id + '.scroll_screen()', 15);
  }

  if (this.enable_fade)
  {
    this.start_fade_in();
  }
  else
  {
    this.initiate_countdown();
  }
}

d23_hoverprompt.prototype.start_fade_in = function ()
{
  if (this.enable_fade)
  {
    this.opacity(0, 100, 1000);
    setTimeout(this.obj_id + '.end_fade_in()', 100);
  }
}

d23_hoverprompt.prototype.end_fade_in = function ()
{
  if (this.enable_fade && this.obj.style.opacity >= 1)
  {
    this.initiate_countdown();
  }
  else
  {
    setTimeout(this.obj_id + '.end_fade_in()', 100);
  }
}

d23_hoverprompt.prototype.start_fade_out = function ()
{
  if (this.enable_fade)
  {
    this.opacity(100, 0, 1000);
    setTimeout(this.obj_id + '.end_fade_out()', 100);
  }
}

d23_hoverprompt.prototype.end_fade_out = function ()
{
  if (this.enable_fade && this.obj.style.opacity <= 0)
  {
    this.hide(true);
  }
  else
  {
    setTimeout(this.obj_id + '.end_fade_out()', 100);
  }
}

d23_hoverprompt.prototype.scroll_screen = function ()
{
  d = this._calc_data();

switch(this.pos1) {
case 1:
  this.obj.style.left = d['scroll_left'] - d['obj_width'] / 2 + this.pos1x + 'px';
  this.obj.style.top = d['scroll_top'] - d['obj_height'] / 2 + this.pos1y + 'px';

break;
case 2:
  this.obj.style.left = d['scroll_left'] + d['doc_width'] - d['obj_width'] / 2 - this.pos1x + 'px';
  this.obj.style.top = d['scroll_top'] - d['obj_height'] / 2 + this.pos1y + 'px';

break;
case 3:
  this.obj.style.left = d['scroll_left'] + d['doc_width'] - d['obj_width'] / 2 - this.pos1x + 'px';
  this.obj.style.top = d['scroll_top'] + d['doc_height'] - d['obj_height'] / 2 - this.pos1y + 'px';

break;
case 4:
  this.obj.style.left = d['scroll_left'] - d['obj_width'] / 2 + this.pos1x + 'px';
  this.obj.style.top = d['scroll_top'] + d['doc_height'] - d['obj_height'] / 2 - this.pos1y + 'px';

break;

default: 
  this.obj.style.left = d['scroll_left'] + d['doc_width'] / 2 - d['obj_width'] / 2 + this.pos1x + 'px';
  this.obj.style.top = d['scroll_top'] + d['doc_height'] / 2 - d['obj_height'] / 2 + this.pos1y + 'px';
}

}

d23_hoverprompt.prototype.hide = function ()
{
  if (arguments[0] !== true && this.suspend)
  {
    return false;
  }

  if (this.enable_fade && arguments[0] !== true)
  {
    this.start_fade_out();
  }
  else
  {
    this.obj.style.display = 'none';
    this.obj.style.top = '0px';
    this.obj.style.left = '0px';

    this._clear_vars();
  }

  return false;
}

d23_hoverprompt.prototype.register = function ()
{
  locationjump('act=reg');
}

d23_hoverprompt.prototype.focused = function ()
{
  this.suspend = true;

  //my_getbyid(this.obj_id+'-close').style.display     = '';
  my_getbyid(this.obj_id + '-timer-row').style.display = 'none';
}

d23_hoverprompt.prototype.initiate_countdown = function ()
{
  if (this.auto_hide && this.hide_time > 0)
  {
    t = parseInt(this.hide_time) * 1000;

    setTimeout(this.obj_id + '.hide()', t);
    if (this.show_timer)
    {
      setTimeout(this.obj_id + '.update_countdown(' + (t - 1000) + ')', 1000);
    }
  }
}

d23_hoverprompt.prototype.update_countdown = function (t)
{
  if (!this.show_timer || this.suspend)
  {
    return false;
  }

  var n = t / 1000;
  var o = my_getbyid(this.obj_id + '-timer');

  if (o)
  {
    o.innerHTML = "<small><i>" + this.langs['timetxt'] + " " + n + " " + ((n == 1) ? this.langs['timesec'] : this.langs['timesecs']) + "</i></small>";
  }

  n = t - 1000;
  if (n > 0)
  {
    setTimeout(this.obj_id + '.update_countdown(' + n + ')', 1000);
  }
}

d23_hoverprompt.prototype.add_langs = function (a)
{
  for (var i in a)
  {
    this.langs[i] = a[i];
  }
}

d23_hoverprompt.prototype._calc_data = function ()
{
  var a = new Array();

  a['body'] = (document.compatMode == 'CSS1Compat') ? document.documentElement : document.body;
  a['scroll_top'] = (is_ie) ? a['body'].scrollTop : window.pageYOffset;
  a['scroll_left'] = (is_ie) ? a['body'].scrollTop : window.pageXOffset;
  a['doc_width'] = (is_ie) ? a['body'].clientWidth : window.innerWidth;
  a['doc_height'] = (is_ie) ? a['body'].clientHeight : window.innerHeight;
  a['obj_width'] = this.obj.offsetWidth;
  a['obj_height'] = this.obj.offsetHeight;

  return a;
}

d23_hoverprompt.prototype._clear_vars = function ()
{
  if (typeof(this.scroll_var) != 'undefined')
  {
    clearInterval(this.scroll_var);
  }

  if (typeof(this.display_var) != 'undefined')
  {
    clearInterval(this.display_var);
  }

  if (typeof(this.fade_var) != 'undefined')
  {
    clearInterval(this.fade_var);
  }
}

d23_hoverprompt.prototype.opacity = function (s, e, m)
{
  var a = Math.round(m / 100);
  var b = 0;

  if (s > e)
  {
    for (var i = s; i >= e; i--)
    {
      setTimeout(this.obj_id + '.change_opacity(' + i + ')', (a * b));
      b++;
    }
  }
  else if (s < e)
  {
    for (var i = s; i <= e; i++)
    {
      setTimeout(this.obj_id + '.change_opacity(' + i + ')', (a * b));
      b++;
    }
  }
}

d23_hoverprompt.prototype.change_opacity = function (o)
{
  this.obj.style.opacity = o / 100;
  this.obj.MozOpacity = o / 100;
  this.obj.KhtmlOpacity = o / 100;
  this.obj.filter = 'alpha(opacity=' + o + ')';
}
