function popUpDivs () {}
popUpDivs.prototype.hiddenTags = ['SELECT','OBJECT','EMBED','IFRAME'];

popUpDivs.prototype.timeIntShow = 500;
popUpDivs.prototype.timeIntHide = 250;

popUpDivs.prototype.caching = false;
popUpDivs.prototype.ajaxCaching = true;
popUpDivs.prototype.removeTitle = true;
popUpDivs.prototype.positionByMouseX = true;
popUpDivs.prototype.positionByMouseY = true;

popUpDivs.prototype.childId = 'prflpudv';
popUpDivs.prototype.childPosition = "y";
popUpDivs.prototype.childAlwaysDown = false;
popUpDivs.prototype.childAlwaysLeft = false;

popUpDivs.prototype.parentAllowClassName = ['boy', 'girl'];
popUpDivs.prototype.parentReg = /\.ua\/user\/([0-9]+)\/$/;
popUpDivs.prototype.dataLoadScript = 'http://narod.i.ua/js/popupdiv.js';

popUpDivs.prototype.phrases = {'0':{load: 'Загружается'},
		     '2':{load: 'Завантажується'},
		     '3':{load: 'Load'}};
popUpDivs.prototype._showTimeout = null;
popUpDivs.prototype._hideTimeout = null;
popUpDivs.prototype._pCollections = [];
popUpDivs.prototype._child = null;
popUpDivs.prototype._parent = null;
popUpDivs.prototype._current = null;
popUpDivs.prototype._hiddenObj = [];
popUpDivs.prototype._browser = null;
popUpDivs.prototype._langId = null;
popUpDivs.prototype.name = 'popUpDivs';

popUpDivs.prototype.start = function ()
{
	var instance = this;

	instance._browser = b;
	instance._langId = (JS_LANG_ID == 2 || JS_LANG_ID == 3) ? JS_LANG_ID : 0;
	var a = document.getElementsByTagName('A');
	var tmp, flg;
	var _pCollections = [];

	for (var i = 0; i < a.length; i++) {

		flg = '';
		for (var ii=0; ii < instance.parentAllowClassName.length; ii++){
			flg += (ii > 0) ? ' || ' : '';
			flg += '('+a[i].className.indexOf(instance.parentAllowClassName[ii]) + ' != -1)';
		}
		flg = (flg == '') ? true : eval(flg);
		if (flg && (tmp = a[i].href.match(instance.parentReg))) {
			tmp.splice(0, 1);
			_pCollections[_pCollections.length] = {'i':tmp,'o':a[i]};
		}
	}
	if (_pCollections.length > 0) {
		instance._child = instance._createDiv(instance.childId);
		instance._child.position = instance.childPosition||'';
		instance._child.alwaysDown = instance.childAlwaysDown||false;
		instance._child.alwaysLeft = instance.childAlwaysLeft|| false;
		//document.instancePUD = instance;
		//window.instancePUD = instance;

		if (document.attachEvent) {
			document.attachEvent('onclick', instance.__hideOnDocClick);
			window.attachEvent('onresize', instance.__hideOnWinResize);
		} else {
			document.addEventListener('click', instance.__hideOnDocClick, true);
			window.addEventListener('resize', instance.__hideOnWinResize, false);
		}
		for (var i = 0; i < _pCollections.length; i++) {
			instance._attach(_pCollections[i]['o'], _pCollections[i]['i']);

		}
	}
}
popUpDivs.prototype._createDiv = function (id)
{
	var d = null;
	var instance = this;
	if (d = document.getElementById(id)) {
		//d["upThis"] = instance;
		if (document.attachEvent) {
			d.attachEvent('onmouseover', instance.__showFromChild);
			d.attachEvent('onmouseout', instance.__hideFromChild);
		} else {
			d.addEventListener('mouseover', instance.__showFromChild, true);
			d.addEventListener('mouseout', instance.__hideFromChild, true);
		}
	} else {
		var d = document.createElement("DIV");
		//d["upThis"] = instance;
		d.id = id;
		d.className = "popupWrapper";
		d.style.position = "absolute";
		d.style.display = "none";
		if (document.attachEvent) {
			d.attachEvent('onmouseover', instance.__showFromChild);
			d.attachEvent('onmouseout', instance.__hideFromChild);
		} else {
			d.addEventListener('mouseover', instance.__showFromChild, true);
			d.addEventListener('mouseout', instance.__hideFromChild, true);
		}
		document.body.appendChild(d);
		var d1 = document.createElement("DIV");
		d1.id = "userInfoPopUp";
		d1.innerHTML = '<div class="preload">' + this.phrases[this._langId]['load'] + ':</div><div class="pupshad1"></div><div class="pupshad2"></div><div class="pupshad3"></div>';
		d.appendChild(d1);
		var d2 = document.createElement("DIV");
		d2.id = "puppointer";
		d.appendChild(d2);
	}
	return d;
}
popUpDivs.prototype._hideOnDocClick = function () {
	if (this._hideTimeout)
		clearTimeout(this._hideTimeout);
	if (this._showTimeout)
		clearTimeout(this._showTimeout);
	if (this._child.style.display != 'none')
		this._child.style.display = 'none';
	this._parent = null;
	this._showBanners();
	if (this.positionByMouseX || this.positionByMouseY)
		this._current = null;
}
popUpDivs.prototype._toJson = function (arr)
{
	var str = [];
	for (var i=0; i < arr.length; i++) {
		str[str.length] = "'" + arr[i].replace(/'/g,"\\\'") + "'";
	}
	return '[' + str.toString() + ']';
}
popUpDivs.prototype._attach = function (p, arr)
{
	var instance = this;
	if (!p)
		return;
	p["upThis"] = this;
	//p["upId"] = id;
	p["upArr"] = this._toJson(arr);

	if (this.removeTitle) {
		if (p['title'])
			p['title'] = '';
		for (var k=0; k < p.childNodes.length; k++) {
			if (p.childNodes[k]['title'])
				p.childNodes[k]['title'] = '';
		}
	}
	p.onmouseover = instance.__showWithDelay;
	p.onmouseout  = instance.__hide;
	if (this.positionByMouseX || this.positionByMouseY)
		p.onmousemove  = instance.__getPosition;

}
popUpDivs.prototype._showData = function (data)
{
	if (data.length < 1 ) {
		this._hideOnDocClick();
		return;
	}
	document.getElementById('userInfoPopUp').innerHTML = this._getInnerHtmlStr(data);
	var pos = this._position();
	this._hideBanners(pos);
}
popUpDivs.prototype._getInnerHtmlStr = function (data)
{
	return '';
}
popUpDivs.prototype._position = function ()
{
	var p = this._parent;
	var c = this._child;
	c.style.visibility = 'hidden';
	c.style.display = "block";
	var top  = (c.position == "y") ? p.offsetHeight : 0;
	var left = (c.position == "x") ? p.offsetWidth+2 : 0;
	var pE = p;
	for (; pE; pE = pE.offsetParent) {
		top  += pE.offsetTop;
		left += pE.offsetLeft;
	}
	left = (this.positionByMouseX) ? p.upPos.x : left;
	top = (this.positionByMouseY) ? p.upPos.y : top;
	var sHeight, sWidth;
	if (this._browser.ie) {
		sHeight = (document.documentElement.scrollTop    != 0 ? document.documentElement.scrollTop : document.body.scrollTop)
			+(document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);//self.document.body.offsetHeight;
		sWidth = (document.documentElement.scrollLeft   != 0 ? document.documentElement.scrollLeft : document.body.scrollLeft)
			+ (document.documentElement.clientWidth  != 0 ? document.documentElement.clientWidth : document.body.clientWidth);//self.document.body.offsetWidth;
	} else if (this._browser.opera) {
		sHeight = document.documentElement.scrollTop + window.innerHeight;
		sWidth = document.documentElement.scrollLeft + window.innerWidth;
	} else if (this._browser.moz) {
		sHeight = ((document.documentElement.scrollTop) ? document.documentElement.scrollTop : 0) + window.scrollX + window.innerHeight;
		sWidth = ((document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : 0) + window.scrollY + window.innerWidth;
	}
	var pointVType = (c.position == "y") ? 't' : '';
	var turn = false;
	if (!c.atAlwaysDown) {
		if (top + c.offsetHeight >= sHeight) {
			turn = true;
			var pTop = top;
			if (this.positionByMouseY)
				top -= c.offsetHeight - ((c.position == "y") ?  0 : 11);
			else
				top -= c.offsetHeight + ((c.position == "y") ? p.offsetHeight : 0) - ((c.position == "x") ? p.offsetHeight : 0);
			if (top < 0) {
				top = pTop;
				turn = false;
			} else {
				pointVType = (c.position == "y") ? 'b' : '';
			}
		}
		if (!turn && this.positionByMouseY) {
			top -= ((c.position == "y") ?  -9 : 18);
		}
	}
	var pointHType = (c.position == "y") ? 'l' : '';
	turn = false;
	if (!c.atAlwaysLeft) {
		if (left + c.offsetWidth >= sWidth){
			turn = true;
			var pLeft = left;
			if (this.positionByMouseX)
				left -= c.offsetWidth + ((c.position == "y") ?  -18 : 11) ;
			else
				left -= c.offsetWidth - ((c.position == "y") ? p.offsetWidth+2 : 0) + ((c.position == "x") ? p.offsetWidth+2 : 0);
			if (left < 0) {
				left = pLeft;
				turn = false;
			} else {
				pointHType = (c.position == "y") ? 'r' : '';
			}
		}
		if (!turn && this.positionByMouseX) {
			left -= ((c.position == "y") ?  9 : -9);
		}
	}
	c.style.top = top + 'px';
	c.style.left = left + 'px';
	document.getElementById('puppointer').className = 'puppointer p'+pointVType+pointHType;
	c.style.visibility = '';
	this._current = p;
	return { x: left, y: top, w: c.offsetWidth, h: c.offsetHeight };
}
popUpDivs.prototype._showLoad = function ()
{
	this._child.className = "popupWrapper offline";
	document.getElementById('userInfoPopUp').innerHTML = '<div class="preload">' + this.phrases[this._langId]['load'] + ':</div><div class="pupshad1"></div><div class="pupshad2"></div><div class="pupshad3"></div>';
	var pos = this._position();
	this._hideBanners(pos);
}
popUpDivs.prototype._showBanners = function ()
{
	for (var i=0; i < this._hiddenObj.length; i++) {
		this._hiddenObj[i].style.visibility = '';
	}
}
popUpDivs.prototype._hideBanners = function (o)
{
	var sel = bpos = null;
	for (var i = 0; i < this.hiddenTags.length; i++) {
		this._hiddenObj = this._hiddenObj.concat(toggleDisplay(this.hiddenTags[i], 'hidden', null, o));
	}
}
popUpDivs.prototype._loadData = function ()
{
	var data = null;
	if (this.caching) {
		for (var i = 0; i < this._pCollections.length; i++) {
			if (this._pCollections[i]['p'] == this._parent) {
				data = this._pCollections[i]['d'];
				break;
			}
		}
	}
	if (this.caching && data) {
		this._showData(data);
		return;
	}
	this._showLoad();
	var getData = new Subsys_JsHttpRequest_Js();
	getData.instance = this;
	getData.onreadystatechange = function() {
		if (getData.readyState == 4) {
			try {
				var tmp = getData.responseJS;
				//if (upopUpDivs.caching)
				//	upopUpDivs._pCollections[upopUpDivs._parent] = tmp;
				if (getData.instance.caching)
					getData.instance._pCollections[getData.instance._pCollections.length] = {'p':getData.instance._parent, 'd':tmp};
					//getData.instance._pCollections[getData.instance._parent] = tmp;
				if (typeof(tmp.length) == "undefined") {
					tmp.length = 0;
					for (i in tmp)
						tmp.length++;
				}
				if (tmp.length < 1) {
					throw 1;
				}
				//upopUpDivs._showData(tmp);
				getData.instance._showData(tmp);
			} catch (e) {
				//upopUpDivs._hideOnDocClick();
				getData.instance._hideOnDocClick();
			}
		}
	}
	getData.caching = this.ajaxCaching;
	getData.open('POST', this.dataLoadScript, true);
	//getData.send({id: this._parent['upId']});
	eval('getData.send({param: ' + this._parent['upArr'] + ', lang: ' + this._langId +'});');
}
popUpDivs.prototype.__getPosition = function(e)
{
	var instance = this["upThis"];
	if (typeof(instance) != "undefined" && instance && typeof(mouseCoords) != "undefined" && mouseCoords) {
		if (instance._current != this) {
			instance._parent = this;
			instance._parent.upPos = mouseCoords(e || window.event);
		}
	}
}
popUpDivs.prototype.__showWithDelay = function(e)
{
	var instance = this["upThis"];
	if (typeof(instance) != "undefined" && instance && typeof(mouseCoords) != "undefined" && mouseCoords) {
		instance._parent = this;
		if (instance.positionByMouseX || instance.positionByMouseY)
			instance._parent.upPos = mouseCoords(e || window.event);
		eval('instance._showTimeout = setTimeout("'+instance.name+'.__show()", instance.timeIntShow);');
	}
}
popUpDivs.prototype.__show = function ()
{
	this._child['upppThis'] = this;
	var p = this._parent;
	var c = this._child;

	if (this._hideTimeout)
 		clearTimeout(this._hideTimeout);
	if (this._showTimeout)
		clearTimeout(this._showTimeout);
	if (!this.positionByMouseX && !this.positionByMouseY && this._current && this._current==p && c.style.display == 'block' && c.style.visibility != 'hidden')
		return;

	if (!this.positionByMouseX && !this.positionByMouseY && this._current && this._current==p){
		c.style.display = 'block';
		c.style.visibility = '';
		return;
	}
	this._loadData();
}
popUpDivs.prototype._hide = function()
{
	var instance = this;
	if (this._hideTimeout)
		clearTimeout(this._hideTimeout);
	if (this._showTimeout)
		clearTimeout(this._showTimeout);
	if (this._child.style.display != 'none')
		eval('this._hideTimeout = setTimeout("document.getElementById(\'' + this._child.id + '\').style.display = \'none\';' + instance.name + '._showBanners();", this.timeIntHide);');
	this._parent = null;
	if (this.positionByMouseX || this.positionByMouseY)
		this._current = null;
}
popUpDivs.prototype.__hide = function()
{
	var instance = this['upThis'];
	if (typeof(instance) != "undefined" && instance)
		instance._hide();
}
popUpDivs.prototype._showFromChild = function()
{
	if (this._hideTimeout)
 		clearTimeout(this._hideTimeout);
	if (this._showTimeout)
		clearTimeout(this._showTimeout);
}
popUpDivs.prototype.__hideFromChild = function(e)
{
//	upopUpDivs._hide();
	if (typeof(e.fromElement) != "undefined" && e.fromElement) {
		var instance = e.fromElement
		if (typeof(instance['upppThis']) == "undefined") {
			while (instance = instance.parentNode) {
				if (typeof(instance['upppThis']) != "undefined")
					break;
			}
//		} else {
//			e.cancelBubble=true;
		}
	} else {
		var instance = this;
	}
	if (typeof(instance) != "undefined" && instance && typeof(instance['upppThis']) != "undefined" && instance['upppThis'])
		instance['upppThis']._hide();
}
popUpDivs.prototype.__showFromChild = function(e)
{
//	upopUpDivs._showFromChild();
	if (typeof(e.fromElement) != "undefined" && e.fromElement) {
		var instance = e.fromElement
		if (typeof(instance['upppThis']) == "undefined") {
			while (instance = instance.parentNode) {
				if (typeof(instance['upppThis']) != "undefined")
					break;
			}
//		} else {
//			e.cancelBubble=true;
		}
	} else {
		var instance = this;
	}
	if (typeof(instance) != "undefined" && instance && typeof(instance['upppThis']) != "undefined" && instance['upppThis'])
		instance['upppThis']._showFromChild();
}
/*function debugObj(obj){
	var res=[];
	var str = '';
	var k=0;
	for (var i in obj){
		k++;
		str += i+'='+obj[i] + "\n";
		if (k >20) {
			k=0;
			res[res.length] = str;
			str='';
		}
	}
res[res.length-1] +='----------------------------------';
	for (i=0; i<res.length; i++){
		alert(res[i]);
	}
}
*/
