// JavaScript Document

document.write("<style type=\"text/css\">.textbox1 { width:100px; position:absolute; z-index:1000; border:solid 1px #333; background-color:#fff; } .textbox2 { padding:5px; font-family:Arial; font-size:14px; color:#333; } .textbox3 { position:absolute; z-index:1001; width:20px; height:20px; background-image:url(mate/box_arrow.png); }</style>");

var _textBoxImg1 = new Image();
_textBoxImg1.src = "mate/box_arrow.png";
var _textBoxImg2 = new Image();
_textBoxImg2.src = "mate/box_arrow2.png";
var _textBoxImg3 = new Image();
_textBoxImg3.src = "mate/box_arrow3.png";
var _textBoxImg4 = new Image();
_textBoxImg4.src = "mate/box_arrow4.png";
var _textBoxBox = null;
var _textBoxArea = null;
var _textBoxAr = null;

function textBox(el,txt,width,lmtRight) {
	if (width == undefined) width = 200;
	if (lmtRight == undefined) lmtRight = fullXR;
	this.width = width;
	if (_textBoxBox == null) _textBoxBox = document.createElement("div");
	if (_textBoxArea == null) {
		_textBoxArea = document.createElement("div");
		_textBoxBox.appendChild(_textBoxArea);
		_textBoxBox.className = "textbox1";
		_textBoxBox.style.width = width + "px";
		_textBoxArea.className = "textbox2";
		if (_textBoxAr == null) _textBoxAr = document.createElement("div");
		_textBoxAr.className = "textbox3";
		document.body.appendChild(_textBoxBox);
		document.body.appendChild(_textBoxAr);
	}
	

	this._box = _textBoxBox;
	this._area = _textBoxArea;
	this._ar = _textBoxAr;
	//mdd.innerHTML = txt;
	boxl = el.offsetLeft + Math.floor(el.offsetWidth / 2) - Math.floor(width / 2);
	boxr = boxl + width;
	_textBoxArea.innerHTML = txt;
	if (boxl < 2) boxl = 2;
	if (boxr > lmtRight) {
		boxl = lmtRight - width - 2;
		boxr = boxl + width;
		//mdd.innerHTML += ":" + boxl;
	}
	//boxt = el.offsetTop - (el.offsetHeight);
	this._box.style.left = boxl + "px";
	//mdd.innerHTML += ":-" + boxl + "-";
	boxt = el.offsetTop - _textBoxBox.offsetHeight - 10;
	if (boxt < 2) {
		boxt = el.offsetTop + el.offsetHeight + 10;
		boxb = boxt + _textBoxBox.offsetHeight;
		if (boxb > fullYR) {
			boxt = el.offsetTop + Math.floor(el.offsetHeight / 2) - Math.floor(_textBoxBox.offsetHeight / 2);
			boxl = el.offsetLeft - _textBoxBox.offsetWidth - 10;
			boxr = boxl + _textBoxBox.offsetWidth;
			if (boxl < 2) {
				boxl = el.offsetLeft + el.offsetWidth + 10;
				boxr = boxl + _textBoxBox.offsetWidth;
				_textBoxAr.style.backgroundImage = "url(" + _textBoxImg4.src + ")";
				_textBoxAr.style.left = (boxl - 19) + "px";
				_textBoxAr.style.top = (el.offsetTop + 20) + "px";
			}
			else {
				_textBoxAr.style.backgroundImage = "url(" + _textBoxImg3.src + ")";
				_textBoxAr.style.left = (boxr - 1) + "px";
				_textBoxAr.style.top = (el.offsetTop + 20) + "px";
			}
		}
		else {
			_textBoxAr.style.backgroundImage = "url(" + _textBoxImg2.src + ")";
			_textBoxAr.style.left = (el.offsetLeft + 20) + "px";
			_textBoxAr.style.top = (boxt - 19) + "px";
		}
	}
	else {
		boxb = boxt + _textBoxBox.offsetHeight;
		_textBoxAr.style.backgroundImage = "url(" + _textBoxImg1.src + ")";
		_textBoxAr.style.left = (el.offsetLeft + 20) + "px";
		_textBoxAr.style.top = (boxb - 1) + "px";
	}
	this._box.style.top = boxt + "px";
	this._box.style.left = boxl + "px";
}

textBox.prototype.close = function() {
	//document.body.removeChild(this._box);
	//document.body.removeChild(this._ar);
	delete this;
}
