var WebText;
function WebText(pid)
{
	var E = new Array(); //binded elements
	var P = new Array(); //parsed paragraph
	var A = new Array(); //advertisements data
	var R = new Array(); //requests
	var responder_url = "http://webtext.sitelement.sk/";
	var portal_id = pid;
	var min_word_len = new Number(3);
	var min_words_count = new Number(20);
	var min_article_chars = new Number(150);
	var max_req_len = new Number(2038); //server-side limitation is 8199
	var max_advertisements = new Number(0); //0 means unlimited
	var iframe = document.createElement("iframe"); //iframe for sending views

	var erm	= {
		"i":true,
		"a":true,
		"u":true,
		"y":true,
		"e":true,
		"o":true,
		"m":true,
		"t":true,
		"s":true,
		"l":true,
		"j":true,
		"ov":true,
		"om":true,
		"mi":true,
		"am":true,
		"ou":true,
		"ia":true,
		"ta":true,
		"tu":true,
		"ti":true,
		"me":true,
		"te":true,
		"ju":true,
		"li":true,
		"la":true,
		"lo":true,
		"ym":true,
		"ej":true,
		"ch":true,
		"ho":true,
		"mu":true,
		"ovi":true,
		"och":true,
		"ami":true,
		"ach":true,
		"iam":true,
		"tam":true,
		"tom":true,
		"uje":true,
		"uju":true,
		"eho":true,
		"emu":true,
		"ych":true,
		"ymi":true,
		"ovia":true,
		"iach":true,
		"tach":true,
		"tami":true,
		"ovat":true,
		"ujem":true,
		"ujes":true,
		"oval":true,
		"ujeme":true,
		"ujete":true,
		"ovali":true,
		"ovala":true,
		"ovalo":true
	}; //endings to remove
	var tts = {
		"a":true,
		"h1":true,
		"h2":true,
		"h3":true,
		"h4":true,
		"select":true,
		"table":true,
		"textarea":true,
		"script":true,
		"noscript":true,
		"style":true,
		"comment":true,
		"iframe":true,
		"nointext":true
	}; //tags to skip
	var rpl = {
		225:"a",
		228:"a",
		269:"c",
		271:"d",
		233:"e",
		237:"i",
		314:"l",
		318:"l",
		328:"n",
		243:"o",
		244:"o",
		341:"r",
		353:"s",
		357:"t",
		250:"u",
		253:"y",
		382:"z"
	}; //accent chars and it's non accent's
	var separators = {
		"p":true,
		"div":true
	}; //tags which separates paragraphs

	//functions
	function o_p(e, pos)
	{
		this.element = e;
		this.query = new String();
		this.startPosition = new Number(pos);
		this.wordsCount = new Number(0);

		this.underline = function(phrase, aid){
			var pid = new Number(0);
			var length = new Number(P.length);
			for (; pid < length; pid++)
			{
				if (P[pid] == this)
				{
					break;
				}
			}
			var source = new String(this.element.newHTML.toLowerCase() + " ");
			var word = new String();
			var position = new Number(source.indexOf("<!--inclick:" + pid + "-->"));
			var c = new String();
			var tempHTML = new String();
			var r = new String();
			var x = new Number();
			var open_tag = false;
			length = new Number(source.length);

			var words =	  phrase.split(" ");
			var wcounter	  =	   new Number(0);
			var wlength	  =	   words.length;
			var startPos	  =	   position;

			for (; position < length; position++)
			{
				c = source.charAt(position);

				if ((c >= "a" && c <= "z") && open_tag === false)
				{
					word += c;
				}
				else if ((r = rpl[c.charCodeAt(0)]) && open_tag === false)
				{
					word += r;
				}
				else if (c == "<")
				{
					//dont manipulate with word var!
					//now seek for tag
					if (source.substr(position, 4) == "<!--")
					{
						position = ((x = (source.indexOf("-->", (position + 4)))) == -1) ? source.length : x;
					}
					else
					{
						x = new Number(position);
						if ((c = source.charAt(x + 1)) && ((c >= "a" && c <= "z") || (c == "/")))
						{
							var endingTag = false;
							var temp = new String();
							var inside_attr = false;
							while (((c = source.charAt(++x)) != ">" || inside_attr !== false) && x < length)
							{
								if ((c == '"' || c == "'") && source.charAt(x - 1) != "\\")
								{
									if (c == inside_attr || inside_attr === false)
									{
										inside_attr = (inside_attr === false) ? c : false;
									}
								}
								else
								{
									temp += (inside_attr === false) ? c : "";
								}
							}
							//now we have the whole inside tag stored in temp, check it for the / and space on the beginning
							if (temp.substr(0, 1) == "/")
							{
								endingTag = true;
								temp = temp.substr(1);
							}
							while (temp.substr(0, 1) == " ")
							{
								temp = temp.substr(1);
							}
							var tagNameEnd = ((temp.indexOf(" ") == -1) ? temp.length : temp.indexOf(" "));
							var tagName = temp.substr(0, tagNameEnd);
							//now we have tag name and type
							if (tts[tagName] === true)
							{
								//this tag is to be skipped with all it's contents
								if (open_tag === false && endingTag === false)
								{
									open_tag = tagName;
								}
								else if (open_tag === tagName && endingTag === true)
								{
									open_tag = false;
								}
							}
						}
					}
					//store the word to the paragraph
					if (getWordBase(word) == words[wcounter])
					{
						wcounter++;
						if(wcounter == wlength)
						{
							break;
						}
					}
					else
					{
						position = x;
						wcounter = 0;
						startPos  =	position;
					}
					word = new String();
				}
				else if (open_tag === false)
				{
					//store the word to the paragraph
					if (getWordBase(word) == words[wcounter])
					{
						wcounter++;
						if(wcounter == wlength)
						{
							break;
						}
					}
					else
					{
						wcounter = 0;
						startPos  =	position;
					}
					word = new String();
				}
			}

			length = new Number(position - ++startPos);

			var newHTML = this.element.newHTML;
			tempHTML = new String(newHTML.substr(0, (position - length)));
			tempHTML += new String("<a href=\"" + A[aid]["url"] + "\" target='_blank' onmouseover='javascript:if(!this.bubble || !this.bubble.visible()){this.bubble=new WebText.bubble(this, new Number(" + aid + "));}this.bubble.onmouseover();' onmouseout='javascript:this.bubble.onmouseout();' class='inclick_underline'>");
			tempHTML += new String(newHTML.substr((position - length), length));
			tempHTML += new String("</a>");
			tempHTML += new String(newHTML.substr(position));
			this.element.newHTML = tempHTML;
		}
		this.clear = function(){
			delete(this.element);
			delete(this.query);
			delete(this.startPosition);
			delete(this.wordsCount);
		}
	}
	function parse_paragraphs(element)
	{
		var source = element.innerHTML.toLowerCase() + "<p>";
		var word = new String();
		var position = new Number(0);
		var c = new String();
		var r = new String();
		var x = new Number(0);
		var open_tag = false;
		var length = source.length;
		var p = new o_p(element, position);
		var d = new Number(0);
		var tempHTML = new String(element.innerHTML);
		var word_ok = new Boolean(false);

		for (; position < length; position++)
		{
			c = source.charAt(position);

			if ((c >= "a" && c <= "z") && open_tag === false)
			{
				word += c;
			}
			else if ((r = rpl[c.charCodeAt(0)]) && open_tag === false)
			{
				word += r;
			}
			else if (c == "<")
			{
				//store the word to the paragraph
				word = getWordBase(word);
				if (word.length >= min_word_len)
				{
					p.query += ((word_ok === true) ? "-" : ".") + word;
					p.wordsCount++;
				}
				word_ok = false; //words cant group over any tag
				word = new String();
				//now seek for tag
				if (source.substr(position, 4) == "<!--")
				{
					position = ((x = (source.indexOf("-->", (position + 4)))) == -1) ? source.length : x;
				}
				else
				{
					x = new Number(position);
					if ((c = source.charAt(x + 1)) && ((c >= "a" && c <= "z") || (c == "/")))
					{
						var endingTag = false;
						var temp = new String();
						var inside_attr = false;
						while (((c = source.charAt(++x)) != ">" || inside_attr !== false) && x < length)
						{
							if ((c == '"' || c == "'") && source.charAt(x - 1) != "\\")
							{
								if (c == inside_attr || inside_attr === false)
								{
									inside_attr = (inside_attr === false) ? c : false;
								}
							}
							else
							{
								temp += (inside_attr === false) ? c : "";
							}
						}
						//now we have the whole inside tag stored in temp, check it for the / and space on the beginning
						if (temp.substr(0, 1) == "/")
						{
							endingTag = true;
							temp = temp.substr(1);
						}
						while (temp.substr(0, 1) == " ")
						{
							temp = temp.substr(1);
						}
						var tagNameEnd = ((temp.indexOf(" ") == -1) ? temp.length : temp.indexOf(" "));
						var tagName = temp.substr(0, tagNameEnd);
						//now we have tag name and type
						if (tts[tagName] === true)
						{
							//this tag is to be skipped with all it's contents
							if (open_tag === false && endingTag === false)
							{
								open_tag = tagName;
							}
							else if (open_tag === tagName && endingTag === true)
							{
								open_tag = false;
							}
						}
						else if (separators[tagName] === true)
						{
							//this tag separates paragraphs
							if (p.wordsCount >= min_words_count)
							{
								tempHTML = tempHTML.substr(0, p.startPosition + d) + "<!--inclick:" + P.length + "-->" + tempHTML.substr(p.startPosition + d);
								d = tempHTML.length - element.innerHTML.length;
								P.push(p);
							}
							p = new o_p(element, (x + 1));
						}
						else if (tagName == "br")
						{
							//check for doubble br to separate paragraphs
							var y = new Number(x);
							while ((r = source.charAt(++y)) && (r == " " || r == "\n") && y < length)
							{
								continue;
							}
							if (r == "<")
							{
								temp = new String();
								inside_attr = false;
								while (((c = source.charAt(++y)) != ">" || inside_attr !== false) && y < length)
								{
									if ((c == '"' || c == "'") && source.charAt(y - 1) != "\\")
									{
										if (c == inside_attr || inside_attr === false)
										{
											inside_attr = (inside_attr === false) ? c : false;
										}
									}
									else
									{
										temp += (inside_attr === false) ? c : "";
									}
								}
								if (temp.substr(0, 1) == "/")
								{
									temp = temp.substr(1);
								}
								while (temp.substr(0, 1) == " ")
								{
									temp = temp.substr(1);
								}
								tagNameEnd = new Number(((temp.indexOf(" ") == -1) ? temp.length : temp.indexOf(" ")));
								tagName = new String(temp.substr(0, tagNameEnd));
								if (tagName == "br")
								{
									if (p.wordsCount >= min_words_count)
									{
										tempHTML = tempHTML.substr(0, p.startPosition + d) + "<!--inclick:" + P.length + "-->" + tempHTML.substr(p.startPosition + d);
										d = (tempHTML.length - element.innerHTML.length);
										P.push(p);
									}
									p = new o_p(element, (y + 1));
									x = y;
								}
							}
						}
						position = x;
					}
				}
			}
			else if (open_tag === false)
			{
				//store the word to the paragraph
				word = getWordBase(word);
				if (word.length >= min_word_len)
				{
					p.query += ((word_ok === true) ? "-" : ".") + word;
					p.wordsCount++;
					word_ok = ((c == " ") ? true : false);
				}
				else
				{
					word_ok = false;
				}
				word = new String();
			}
		}
		element.newHTML = tempHTML;
	}
	function getWordBase (word)
	{
		var i =	(word.length>5) ? new Number(5) : (word.length - 3);
		for(;i>0;i--)
		{
			if(erm[word.substring((word.length - i))]===true)
			{
				word	=	word.substring(0, (word.length - i));
				break;
			}
		}
		return word;
	}
	function is_in_array(needle, array)
	{
		var contains = false;
		for (var id in array)
		{
			if (needle == array[id])
			{
				contains = id;
				break;
			}
		}
		return contains;
	}
	function preloadImages(images) {
		var d = document;
		if(d.images) {
			if(!d.preloader)
			{
				d.preloader = {};
			}

			var length = images.length;
			var x = new Number(0);
			for(;x < length; x++)
			{
				d.preloader[x]=new Image;
				d.preloader[x].src = images[x];
			}
		}
	}
	this.setMaxAdvs = function(max){
		max_advertisements = max;
	};
	this.getAd = function(){
		var length = E.length;
		var id = new Number(0);

		for (id = 0; id < length; id++)
		{
			parse_paragraphs(E[id]);
		}

		var queries = new Array();
		var query = new String();
		length = P.length;
		for (id = 0; id < length; id++)
		{
			if ((query.length + P[id].query.length) > max_req_len)
			{
				if(query.length > 100)
				{
					queries.push(query);
				}
				query = new String();
			}
			query += ":" + id + P[id].query;
		}
		if(query.length > 100)
		{
			queries.push(query);
		}

		var script;
		length = queries.length;
		for (id = 0; id < length; id++)
		{
			script	=	document.createElement("script");
			script.setAttribute("charset", "utf-8");
			script.src	=	(responder_url + "returns/request2.php?pid," + portal_id + ",rid," + R.length + queries[id]).substr(0, max_req_len);
			document.body.appendChild(script);
			R.push("sent");
		}
	};
	this.bindByClassName = function(parentTag, classNames){
		var i;
		parentTag = ((parentTag && typeof(parentTag) == "object") ? parentTag : document);
		var elements = parentTag.getElementsByTagName("*");
		var length = new Number(elements.length);
		for (i = 0; i < length; i++)
		{
			if (is_in_array(elements[i].className, classNames) !== false)
			{
				this.bind(elements[i]);
			}
		}
	};
	this.bindByTagName = function(parentTag, tagNames){
		var i, x;
		var elements;
		var length = new Number();
		parentTag = ((parentTag && typeof(parentTag) == "object") ? parentTag : document);
		for (i = 0; i < tagNames.length; i++)
		{
			elements = parentTag.getElementsByTagName(tagNames[i]);
			length = elements.length;
			for (x = 0; x < length; x++)
			{
				this.bind(elements[x]);
			}
		}
	};
	this.bind = function(e){
		if (typeof(e) == "object" && e.innerHTML && e.innerHTML.length > min_article_chars)
		{
			if (is_in_array(e, E) === false)
			{
				E.push(e);
			}
		}
	};
	this.bubble = function(e, aid){
		var a = A[aid];
		var mouseover = true;
		var bubble_type = a["bubble_type"];
		var bubble = document.createElement("div");
		bubble.id = "InClickBubble";
		bubble.className = "arrowbottom";
		bubble.style.position = "absolute";
		bubble.pointer = this;
		if(bubble_type < 3)
		{
			//bubble.innerHTML = '<table cellpadding="0" cellspacing="0"><tbody><tr class="ic_header"><td class="ic_inclick ic_hand" onclick="javascript:window.open(\'http://sitelement.sk/bannerova-reklama-ako-to-funguje-intext.html\');">&nbsp;</td><td class="ic_close ic_hand" onclick="javascript:this.parentNode.parentNode.parentNode.style.display=\'none\';">&nbsp;</td></tr><tr><td colspan="2" class="ic_content ic_hand" onclick="javascript:window.open(\''+a["url"]+'\');">'+((bubble_type=="2") ? '<img class="ic_icon" src="'+a["bubble_options"][1]+'" style="width:'+a["bubble_options"][2]+'px;height:'+a["bubble_options"][3]+'px;" align="left">' : '')+'<span class="ic_title">'+a["title"]+'</span>'+a["bubble_options"][0]+'</td></tr><tr class="ic_bar"><td class="ic_url"><a class="ic_underlineOut" href="'+a["url"]+'" target="_blank">'+a["name"]+'</a></td><td class="ic_help"></td></tr><tr><td class="ic_foot" colspan="2"></td></tr></tbody></table>';
			bubble.innerHTML = '<table cellpadding="0" cellspacing="0"><tbody><tr class="ic_header"><td class="ic_inclick ic_hand" onclick="javascript:window.open(\'http://sitelement.sk/bannerova-reklama-ako-to-funguje-intext.html\');">&nbsp;</td><td class="ic_close ic_hand" onclick="javascript:this.parentNode.parentNode.parentNode.style.display=\'none\';">&nbsp;</td></tr><tr><td colspan="2" class="ic_content ic_hand" onclick="javascript:window.open(\''+a["url"]+'\');">'+((bubble_type=="2") ? '<img class="ic_icon" src="'+a["bubble_options"][1]+'" style="width:'+a["bubble_options"][2]+'px;height:'+a["bubble_options"][3]+'px;" align="left">' : '')+'<span class="ic_title">'+a["title"]+'</span>'+a["bubble_options"][0]+'</td></tr><tr class="ic_bar"><td class="ic_url"></td><td class="ic_help"></td></tr><tr><td class="ic_foot" colspan="2"></td></tr></tbody></table>';
		}
		else if(bubble_type == 3)
		{
			//bubble.innerHTML = '<table cellpadding="0" cellspacing="0"><tbody><tr class="ic_header"><td class="ic_inclick ic_hand" onclick="javascript:window.open(\'http://sitelement.sk/bannerova-reklama-ako-to-funguje-intext.html\');">&nbsp;</td><td class="ic_close ic_hand" onclick="javascript:this.parentNode.parentNode.parentNode.style.display=\'none\';">&nbsp;</td></tr><tr><td colspan="2" class="ic_content ic_hand" onclick="javascript:window.open(\''+a["url"]+'\');"><span id="lc_title" class="ic_title">'+a["title"]+'</span><span id="lc_flash_object"><div style="height:'+a["bubble_options"]["2"]+'px;width:'+a["bubble_options"]["1"]+'px;"><img height="'+a["bubble_options"]["2"]+'" width="'+a["bubble_options"]["1"]+'" src="'+a["bubble_options"]["0"]+'"/></div></span></td></tr><tr class="ic_bar"><td class="ic_url"><a class="ic_underlineOut" href="'+a["url"]+'" target="_blank">'+a["name"]+'</a></td><td class="ic_help" ></td></tr><tr><td class="ic_foot" colspan="2"></td></tr></tbody></table>';
			bubble.innerHTML = '<table cellpadding="0" cellspacing="0"><tbody><tr class="ic_header"><td class="ic_inclick ic_hand" onclick="javascript:window.open(\'http://sitelement.sk/bannerova-reklama-ako-to-funguje-intext.html\');">&nbsp;</td><td class="ic_close ic_hand" onclick="javascript:this.parentNode.parentNode.parentNode.style.display=\'none\';">&nbsp;</td></tr><tr><td colspan="2" class="ic_content ic_hand" onclick="javascript:window.open(\''+a["url"]+'\');"><span id="lc_title" class="ic_title">'+a["title"]+'</span><span id="lc_flash_object"><div style="height:'+a["bubble_options"]["2"]+'px;width:'+a["bubble_options"]["1"]+'px;"><img height="'+a["bubble_options"]["2"]+'" width="'+a["bubble_options"]["1"]+'" src="'+a["bubble_options"]["0"]+'"/></div></span></td></tr><tr class="ic_bar"><td class="ic_url"></td><td class="ic_help" ></td></tr><tr><td class="ic_foot" colspan="2"></td></tr></tbody></table>';
		}
		else if (bubble_type == 4)
		{
			var tt=a['url'];
			var urlcko=escape(tt);
			bubble.innerHTML = '<table cellpadding="0" cellspacing="0"><tbody><tr class="ic_header"><td class="ic_inclick ic_hand" onclick="javascript:window.open(\'http://sitelement.sk/bannerova-reklama-ako-to-funguje-intext.html\');">&nbsp;</td><td class="ic_close ic_hand" onclick="javascript:this.parentNode.parentNode.parentNode.style.display=\'none\';">&nbsp;</td></tr><tr><td colspan="2" class="ic_content ic_hand" onclick="javascript:window.open(\''+a["url"]+'\');"><span id="lc_title" class="ic_title">'+a["title"]+'</span><span id="lc_flash_object"><div style="height:'+a["bubble_options"]["2"]+'px;width:'+a["bubble_options"]["1"]+'px;"><object id="bubble" height="'+a["bubble_options"]["2"]+'" width="'+a["bubble_options"]["2"]+'" type="application/x-shockwave-flash" name="bubble" data="'+a["bubble_options"]["0"]+'?clickTAG='+urlcko+'"><param name="clickTAG" value="'+urlcko+'"/><param name="movie" value="'+a["bubble_options"]["0"]+'?clickTAG='+urlcko+'"/><param name="wmode" value="transparent" /><embed href="'+a["bubble_options"]["0"]+'?clickTAG='+urlcko+'"></embed></object></div></span></td></tr><tr class="ic_bar"><td class="ic_url"></td><td class="ic_help" ></td></tr><tr><td class="ic_foot" colspan="2"></td></tr></tbody></table>';
		}
		document.body.appendChild(bubble);

		var left = e.offsetLeft;
		var top = e.offsetTop;
		var width = e.offsetWidth;
		var height = e.offsetHeight;

		while ((e = e.offsetParent) !== null)
		{
			left += e.offsetLeft;
			top += e.offsetTop;
		}
		left = Math.max((left + Math.ceil(width >> 1) - 67), 0);

		var bubble_width = new Number(bubble.offsetWidth);
		var bubble_height = new Number(bubble.offsetHeight);
		var window_width = new Number(0);
		if (self.innerWidth)
		{
			window_width = parseInt(self.innerWidth);
		}
		else if (document.documentElement && document.documentElement.clientWidth)
		{
			window_width = parseInt(document.documentElement.clientWidth);
		}
		else if (document.body)
		{
			window_width = parseInt(document.body.clientWidth);
		}
		var window_scrollx = new Number(0);
		var window_scrolly = new Number(0);

		if (self.pageYOffset)
		{
			window_scrollx = self.pageXOffset;
			window_scrolly = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
		{
			window_scrollx = document.documentElement.scrollLeft;
			window_scrolly = document.documentElement.scrollTop;
		}
		else if (document.body)
		{
			window_scrollx = document.body.scrollLeft;
			window_scrolly = document.body.scrollTop;
		}
		//relocate the bubble if needed
		//x
		var d = (window_scrollx + window_width - (left + bubble_width));
		if (d < 15) //scrollbar
		{
			left = (((left + d - 15) > window_scrollx) ? (left + d - 15) : window_scrollx);
		}
		bubble.style.left = Math.max(left, 0) + "px";
		//y
		if ((top - bubble_height) < window_scrolly)
		{
			top = top + height;
			bubble.className = "arrowtop";
			document.body.removeChild(bubble);
			document.body.appendChild(bubble);
		}
		else
		{
			top = top - bubble_height;
		}
		bubble.style.top = top + "px";

		bubble.onmouseover = this.onmouseover = function()
		{
			mouseover = true;
			window.setTimeout(bubble.mouse, 300);
		}
		bubble.onmouseout = this.onmouseout = function()
		{
			mouseover = false;
			window.setTimeout(bubble.mouse, 300);
		}
		bubble.mouse = function()
		{
			if (mouseover === false && bubble !== false)
			{
				document.body.removeChild(bubble);
				bubble = false;
			}
		};
		this.visible = function()
		{
			return ((bubble !== false) ? true : false);
		};

		if (a["views"] == 0)
		{
			iframe.src = a["impression_url"];
		}
		a["views"]++; //increment views for advertisement
	};
	this.response = function(request_id, data){
		R[request_id] = "received";

		var i = new Number(0);
		var length = new Number(data.length);
		for (; i < length; i++)
		{
			A.push({
				"paragraph_id" : data[i][0],
				"word_to_underline" : data[i][1],
				"advertisement_id" : data[i][2],
				"title" : data[i][3],
				"name" : data[i][4],
				"url" : data[i][5],
				"impression_url" : data[i][6],
				"bubble_type" : data[i][7],
				"bubble_options" : data[i][8],
				"priority" : data[i][9],
				"views" : 0
			});
		}
		if(is_in_array("sent", R) === false) //no requests lefts
		{
			A.sort(function (a, b) {
				return (a["priority"] - b["priority"])
			});

			var rebuild = new Array();
			length = (((max_advertisements > 0) && (max_advertisements < A.length)) ? max_advertisements : A.length);
			for(i = 0; i < length; i++)
			{
				P[A[i]["paragraph_id"]].underline(A[i]["word_to_underline"], i, A[i]["paragraph_id"]);

				if(A[i]["bubble_type"] == 2)
				{
					preloadImages([A[i]["bubble_options"][1]]);
				} else if(A[i]["bubble_type"] == 3) {
					preloadImages([A[i]["bubble_options"][0]]);
				}

				if (is_in_array(P[A[i]["paragraph_id"]].element, rebuild) === false)
				{
					rebuild.push(P[A[i]["paragraph_id"]].element);
				}
			}

			length = new Number(rebuild.length);
			for (i = 0; i < length; i++)
			{
				rebuild[i].innerHTML = rebuild[i].newHTML;
			}

			//append iframe for sending views
			iframe.style.display = "none";
			iframe.style.width = "0px";
			iframe.style.height = "0px";
			document.body.appendChild(iframe);

			//preload images
			preloadImages(["http://webtext.sitelement.sk/bubble/img/light_head.gif",
				"http://webtext.sitelement.sk/bubble/img/light_head_arrow.gif",
				"http://webtext.sitelement.sk/bubble/img/light_body.gif",
				"http://webtext.sitelement.sk/bubble/img/light_help.gif",
				"http://webtext.sitelement.sk/bubble/img/light_foot.gif",
				"http://webtext.sitelement.sk/bubble/img/light_foot_arrow.gif"]);
		}
	};
}
