

var infoBox = function(){

	// -=- begin saját változók

	this.divText=null;
	this.divCaption=null;
	this.divBox=null;
	this.lastTarget=null;
	this.frameColor='#1D5F85';
	this.initDone = false;
	this.sizeReference = document.body;

	this.popped = 0;


	this.on = false;

	// -=- e n d

	this.onShow = function(){}
	this.onHide = function(){}


	this.test = function(target,hPos,vPos,bubble)
	{
		this.showInfo(target,'teszt','egy ketto',hPos,vPos);
	}


	// -=- begin infó ablak mutatása
	this.showInfo = function(target,text,hPos,vPos,bubble)
	{
		/*
			a lastTarget azért kell, hogy az ablak ne villogjon több ráhívás esetén (pl onmouseover eseménykor felléphet ilyesmi)
		*/
		if(!this.initDone)
			this.init();

		if(this.lastTarget==target)
			return;

		this.lastTarget = target;
		this.popped = 0;

		var pos = this.getPos(target);

		if(typeof(text)=='object' && typeof(text.nodeName)=='string')
		{
			this.divText.innerHTML='';
			this.divText.appendChild(text.cloneNode(true));
			infoBox.divText.firstChild.style.display='';
		}
		else
		{
			this.divText.innerHTML = text;
		}

		bubble=1;
		this.divBottomNormal.style.display = bubble ? 'none' : '';
		this.divBottomBubble.style.display = bubble ? '' : 'none';


		this.onShow();
		this.on = true;

		this.divBox.style.display = '';

		switch(hPos)
		{
			case 'right' : pos.left += target.clientWidth+2;break;
			case 'left'  : pos.left -= this.divBox.clientWidth-1;break;
			case 'smart' : pos.left += ( pos.left > this.sizeReference.clientWidth/2 ? -this.divBox.clientWidth+1 : target.clientWidth+2);
		}

		var rootPos = this.getPos(this.sizeReference);
		switch(vPos)
		{
			case 'under'  : pos.top+=target.clientHeight+1;break;
			case 'above'  : pos.top+=target.clientHeight;pos.top-=this.divBox.clientHeight+1;break;
			case 'smart'  : pos.top += ( ( rootPos.top+this.divBox.clientHeight < pos.top && pos.top >= this.sizeReference.clientHeight-this.divBox.clientHeight) ? target.clientHeight-this.divBox.clientHeight+2 : 0);
		}

		this.divBox.style.left = pos.left+'px';
		this.divBox.style.top  = pos.top+'px';

		window.setTimeout('infoBox.popped = 1',200);

	}
	// -=- e n d



	// -=- begin infó ablak elrejtése
	this.hide = function()
	{
		if(!this.initDone)
		{
			this.init();
			return;
		}

		this.divBox.style.display = 'none';
		this.lastTarget = null;
		this.onHide();
		this.on = false;
	}
	// -=- e n d


	// -=- begin infó ablak létrehozása és stílusbeállításai
	this.init = function()
	{
		var tmpNode;
		this.divBox = document.createElement('div');
			this.divBox.className             = 'infobox';
			this.divBox.style.position        = 'absolute';
			this.divBox.style.display         = 'none';
		document.body.insertBefore(this.divBox,document.body.firstChild);

/*
		this.divTopBubble = document.createElement('div');
		this.divBox.appendChild(this.divTopBubble);
		this.divTopBubble.innerHTML = "<table cellpadding='0' cellspacing='0' border='0'><tr><td><img src='img/bubble_top_left.gif'/><td><td style='background-color:"+this.frameColor+"' width='100%'><img src='img/0.gif'/></td><td><img src='img/bubble_top_right.gif'/><td></tr></table>";
*/


		this.divText = document.createElement('div');
			this.divText.style.padding         = '2px';
			this.divText.style.backgroundColor = 'white';
			this.divText.style.borderLeft      = '2px solid '+this.frameColor;
			this.divText.style.borderRight     = '2px solid '+this.frameColor;
			this.divText.style.borderTop       = '2px solid '+this.frameColor;
			this.divText.className             = 'talalatok';
		this.divBox.appendChild(this.divText);

		this.divBottomBubble = document.createElement('div');
			this.divBottomBubble.style.backgroundImage = 'url('+site_domain+'bin/img/bubble_bg.gif)';
			this.imgBubble                             = document.createElement('img');
				this.imgBubble.src                     = site_domain+'bin/img/bubble_left.gif';
				this.imgBubble.style.height            = '6px';
			this.divBottomBubble.appendChild(this.imgBubble);
		this.divBox.appendChild(this.divBottomBubble);

		this.divBottomNormal = document.createElement('div');
			this.divBottomNormal.style.backgroundColor = this.frameColor;
			this.divBottomNormal.style.padding         = '1px';
		this.divBox.appendChild(this.divBottomNormal);

		this.initDone = true;
	}
	// -=- e n d


	this.getPos = function(element)
	{
		var pos={top: 0,left: 0};

		while(element && typeof(element) == "object" && typeof(element.offsetTop) == "number")
		{
			pos.top+=element.offsetTop;
			pos.left+=element.offsetLeft;

			element = element.offsetParent;
		}
		return pos;
	}
}

// -=- egyke létrehozása
infoBox = new infoBox();

