function cBubble(id)
{
	this.textDiv = null;
	this.table = null;
	this.id = null;
	this.time = null;
	
	this.init(id);
	
}

cBubble.prototype.init = function(id)
{
	this.id = id;
	
}

cBubble.prototype.showBubble = function(data,srcEl,e,delImage)
{
 
	this.srcEl = srcEl;
	if(this.time!==null)
	{
		clearTimeout(this.time);
	}
	
	if(this.table!==null)
	{
		this.table.parentNode.removeChild(this.table);
		this.table = null;
	}
	
	this.createHTML();
	var txt = '';
	if(typeof(data)!='string')
	{
		var setPo=false;
		for(var i=0;i<data.length;i++)
		{
			if(data[i].length>0)
			{
				if(data[i].substr(0,9)=='***img***')
				{
					var img = window.top.getCE('img');
					img.src = data[i].replace('***img***','');
					img.setAttribute('bubbleId',this.id);
					img.onload = function(){eval(this.getAttribute('bubbleId')+'.setPosition();');}
					setPo=true;
					this.textDiv.appendChild(img);
				}
				else
				{
					var txNode = window.top.getTN(data[i]);
					this.textDiv.appendChild(txNode);
				}
				
				var br = window.top.getCE('br');
				this.textDiv.appendChild(br);
			}
			if(setPo==false){this.setPosition();}
		}
	}
	else
	{
		if(data.substr(0,9)=='***img***')
		{
			var img = window.top.getCE('img');
			img.src = data.replace('***img***','');
			img.setAttribute('bubbleId',this.id);
			img.onload = function(){eval(this.getAttribute('bubbleId')+'.setPosition();');}					
			this.textDiv.appendChild(img);
			if(delImage==true)
			{
				var a = window.top.getCE('a');
				a.href = 'javascript:void(0);';
				a.setAttribute('bubbleName',this.id);
				a.appendChild(window.top.getTN(GLSAT(201,1,'Odstranit obrázek')));
				a.onclick = function(){
								if(Br.IE)
								{
									window.setTimeout("getE('"+srcEl.id+"').src = '/img/admin/menu/PictureDesatur.gif';",100);
								}
								else
								{
									srcEl.src = '/img/admin/menu/PictureDesatur.gif';
								}
								//alert(srcEl.src);
								var splited = srcEl.id.split('_');
								var inpId = 'paramsAdditionalImage_' + splited[1] + '_' + splited[4] + '_' + splited[3];
								//alert(inpId);
								var inp = getE(inpId);
								inp.parentNode.removeChild(inp);
								srcEl.onmouseover = null;
								eval(this.getAttribute('bubbleName')+'.plopBubbleDo(true);');
								
								getE('params_paramsChanged_'+splited[1]).value = 'changed';
							}
				a.style.color = 'red';
				a.style.fontSize = '11px';
				a.style.fontWeight = 'bold';
				
				var div = window.top.getCE('div');
				div.style.textAlign = 'right';
				div.appendChild(a);
				
				this.textDiv.appendChild(window.top.getCE('br'));
				this.textDiv.appendChild(div);
			}
		}
		else
		{
			var txNode = window.top.getTN(data);
			this.textDiv.appendChild(txNode);
			this.setPosition(e);
		}
	}

	if(Br.IE){this.setPosition();}	
}

cBubble.prototype.createHTML = function()
{
	/*var div = window.top.getCE('div');
	document.body.appendChild(div);
	div.style.width='100px';
	div.style.textAlign='right';
	div.appendChild(span);*/
	
	
	var tbl = window.top.getCE('table');
	tbl.cellSpacing = 0;
	tbl.cellPadding = 0;
	tbl.border = 0;
	this.table = tbl;
	tbl.style.position = 'absolute';
	tbl.style.top = '-5000';
	tbl.style.left = '-5000';
	tbl.setAttribute('owner',this.id);
	
	window.top.getE('bodyId').appendChild(tbl);
	
	var tbody = window.top.getCE('tbody');
	tbl.appendChild(tbody);

	var tr = window.top.getCE('tr');
	tbody.appendChild(tr);

	// ****************************************    top left TD start
	var td = window.top.getCE('td');
	td.style.width = '4px';
	tr.appendChild(td);

/*	var img = window.top.getCE('img');
	img.alt = '';
	img.src = '/administration/images/progressbarTL.gif';
	td.appendChild(img);
*/
	// ****************************************    top center TD start
	td = window.top.getCE('td');
	td.className = 'progressBarTop';
	

/*	var img = window.top.getCE('img');
	img.alt = '';
 	img.src = '/administration/images/progressbarTC.gif';
	td.appendChild(img);*/
	
	//td.appendChild(window.top.getTN('br'));
	tr.appendChild(td);

	// ****************************************    top right TD start
	td = window.top.getCE('td');
	td.style.width = '4px';
	tr.appendChild(td);

/*
	img.alt = '';
	img.src = '/administration/images/progressbarTR.gif';
	td.appendChild(img);*/
	/////////////////////////////////////////////////////////////////////
	var tr = window.top.getCE('tr');
	tbody.appendChild(tr);

	// ****************************************    mid left TD start
	var td = window.top.getCE('td');
	td.style.width = '4px';
//	td.className = 'progressBarML';
	tr.appendChild(td);

	// ****************************************    mid center TD start
	td = window.top.getCE('td');
	td.className = 'progressBarCenter';
	tr.appendChild(td);
	
	var div = window.top.getCE('div');
	this.textDiv = div;
	div.style.backgroundColor='#CA364E';
	div.onmouseover = this.tableMouseOver;
	if(!Br.IE)
	{
		div.onmouseout = this.tableMouseOut;
	}
	div.setAttribute('owner',this.id);
	div.setAttribute('over','false');
	div.style.padding = '10px';

	td.appendChild(div);

	// ****************************************    mid right TD start
	td = window.top.getCE('td');
	td.style.width = '4px';
	td.className = 'progressBarMR';
	tr.appendChild(td);
	////////////////////////////////////////////////////////////////////////////////
	tr = window.top.getCE('tr');
	tbody.appendChild(tr);

	// ****************************************    bottom left TD start
	var td = window.top.getCE('td');
	td.style.width = '4px';
	tr.appendChild(td);

/*	var img = window.top.getCE('img');
	img.alt = '';
	img.src = '/administration/images/progressbarBL.gif';
	td.appendChild(img);
	*/

	// ****************************************    bottom center TD start
	td = window.top.getCE('td');
	td.className = 'progressBarBottom';
	//td.appendChild(window.top.getCE('br'));
	tr.appendChild(td);

	// ****************************************    bottom right TD start
	td = window.top.getCE('td');
	td.style.width = '4px';
	tr.appendChild(td);

/*	var img = window.top.getCE('img');
	img.alt = '';
	img.src = '/administration/images/progressbarBR.gif';
	td.appendChild(img);*/
	
	/*var bunky = this.table.getElementsByTagName('td');
	for(var i=0;i<bunky.length;i++)
	{
		bunky[i].setAttribute('owner',this.id);
		bunky[i].onmouseout = this.bunkaOut;
	}*/
	
}

cBubble.prototype.plopBubble = function()
{
	this.time = window.setTimeout(this.id + ".plopBubbleDo();",500);
}

cBubble.prototype.plopBubbleDo = function(force)
{
	if(force==true || this.textDiv.getAttribute('over')=='false')
	{
		if(this.table!=null){this.table.parentNode.removeChild(this.table);}
		this.table=null;
		this.time = null;
	}
}

cBubble.prototype.setPosition = function(e)
{	
	var tblWidth = this.table.offsetWidth;	
	var tblHeight = this.table.offsetHeight;
	
	var newPosition = poziceElementuBubble(this.srcEl)
	
	var newLeft = newPosition[0]-tblWidth;
	var newTop = newPosition[1];
	
	if(window!=window.top)
	{
		var prnt = window;
		var win = window;
		var more=true;
		while(more)
		{
			prnt=prnt.parent;
			if(prnt==window.top){more=false;}
			var frms = prnt.frames;
	  		for (var i = 0; i<frms.length; i++)
	  		{
	  			if(frms[i]==win)
	  			{
	  				var id=frms[i].name;
	  				var pos = poziceElementu(prnt.getE(id));
	  				newLeft += pos[0];
	  				newTop += pos[1];
					win=prnt;
					break; 
	  			}
	  		}
			
		}
	}	
	
	if(newLeft<10){newLeft = 10;}
	if(newTop<62){newTop = 62;}
	
	//alert(newTop + '\n' + newLeft);
	
	this.table.style.top = newTop + 'px';
	this.table.style.left = newLeft + 'px';
	
}

cBubble.prototype.tableMouseOver = function()
{
	this.setAttribute('over','true');
	eval("clearTimeout(" + this.getAttribute('owner')+".time);");
	if(Br.IE)
	{
		eval(this.getAttribute('owner') + ".table.onmouseout = " + this.getAttribute('owner') + ".tableMouseOut;");
	}
}

cBubble.prototype.tableMouseOut = function()
{
	
	eval(this.getAttribute('owner') + ".textDiv.setAttribute('over','false');");
	eval(this.getAttribute('owner')+".plopBubble();");	
}


function poziceElementuBubble(el)
{
	if (el.offsetParent)
	{
		var elOrig = el;
		var vystup=new Array(el.offsetLeft,el.offsetTop);
		while(el=el.offsetParent)
		{
			vystup[0]+=el.offsetLeft;
			vystup[1]+=el.offsetTop;
		}
		while(elOrig=elOrig.parentNode)
		{
			vystup[0]-=elOrig.scrollLeft===undefined?0:elOrig.scrollLeft;
			vystup[1]-=elOrig.scrollTop===undefined?0:elOrig.scrollTop;
		}
		return vystup;
	}
}

