// class.popup.js

// dependencies - jQuery

function popup()
{
	this._caller_id = null;
	this._popup_id = null;
	this._popup_bg_id = null;
	this._invoke = function(){};
	this._devoke = function(){ return false; };
	this._top = 0;
	this._left = 0;
	
	this.invoked = null;
	
	this.init = function(popup, popup_bg, invoker, devoker, offset_top, offset_left)
	{
		if ( popup.substring(0,1) != '#' ) popup = '#' + popup;
		this._popup_id = popup;
		if ( popup_bg.substring(0,1) != '#' ) popup_bg = '#' + popup_bg;
		this._popup_bg_id = popup_bg;
		this._hide_popup();
		
		this._invoke = invoker;
		this._devoke = devoker;
		this._top = offset_top;
		this._left = offset_left;
	}
	
	this.invoke = function(_id)
	{
		if ( _id.substring(0,1) != '#' ) _id = '#' + _id;
		if ( $(_id) == undefined ) return false;
		this._caller_id = _id;
		this._show_popup();
		this._invoke();
	}
	
	this.devoke = function()
	{
		this._hide_popup();
		var val = this._devoke();
		$(this._caller_id).val(val);
		this._caller_id = null;
	}
	
	this.toggle = function(_id)
	{
		if ( this.invoked )
		{
			this.devoke();
		}
		else
		{
			this.invoke(_id);
		}
	}
	
	this._show_popup = function()
	{
		$(this._popup_bg_id).show();
		$(this._popup_id).show();
		var pos = $(this._caller_id).offset();
		pos.top += this._top;
		pos.left += this._left;
		$(this._popup_id).offset(pos);
		this.invoked = true;
	}
	
	this._hide_popup = function()
	{
		$(this._popup_bg_id).hide();
		$(this._popup_id).hide();
		this.invoked = false;
	}
} // function popup()

// end of file
