//----------------------------------------------------
// D23-Hover Prompt Javascript Library
// Written By:  Dean
// Website:     http://www.dscripting.com
// Copyright © 2007
//----------------------------------------------------

function d23_hoverprompt(id)
{
	this.obj;
	this.scroll_var;

	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;
	this.obj.style.left     = d['doc_width']/2-d['obj_width']/2+'px';
	this.obj.style.top      = d['scroll_top']+d['doc_height']/3-d['obj_height']/2+'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();

	this.obj.style.left = d['doc_width']/2-d['obj_width']/2+'px';
	this.obj.style.top  = d['scroll_top']+d['doc_height']/3-d['obj_height']/2+'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['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+')';
}