if (!com) var com={};
if (!com.flexportal) com.flexportal={};

com.flexportal.NewsImage = function() {
	var priv = {};
	var pub = {};

	priv.rgNP = new Array();
	priv.fImg = false;

	priv.addEvent = function(obj, type, fn) {
		if (obj.addEventListener) {
			obj.addEventListener(type, fn, false);
		} else {
			obj.attachEvent("on" + type, fn);
		}
	}

	priv.AdjustBorders = function(iW, iH, fImg) {
		var iL = (iW > document.documentElement.clientWidth) ? document.documentElement.scrollLeft : ((document.documentElement.clientWidth / 2) - (iW / 2) + document.documentElement.scrollLeft);
		var iT = (iH > document.documentElement.clientHeight) ? document.documentElement.scrollTop+10 : ((document.documentElement.clientHeight / 2) - (iH / 2) + document.documentElement.scrollTop);
		var iTHt = 32;
		var hS;

		if (fImg) {
			iTHt = document.getElementById('puptxt').scrollHeight;
		}
		hS = document.getElementById('pupbrd1').style;
		hS.width = (iW+20) + 'px';
		hS.height = (iH+20+iTHt) + 'px';
		hS = document.getElementById('pupbrd2').style;
		hS.width = (iW+22) + 'px';
		hS.height = (iH+22+iTHt) + 'px';
		hS = document.getElementById('pupsh1').style;
		hS.width = (iW+22) + 'px';
		hS.height = (iH+22+iTHt) + 'px';
		hS = document.getElementById('pupsh2').style;
		hS.width = (iW+22) + 'px';
		hS.height = (iH+22+iTHt) + 'px';
		hS = document.getElementById('pupsh3').style;
		hS.width = (iW+22) + 'px';
		hS.height = (iH+22+iTHt) + 'px';
		hS = document.getElementById('pupsh4').style;
		hS.width = (iW+22) + 'px';
		hS.height = (iH+22+iTHt) + 'px';

		hS = document.getElementById('pupbox').style;
		hS.width = iW + 'px';
		hS.height = (iH+iTHt) + 'px';
		hS.left = iL + 'px';
		hS.top = iT + 'px';
	}

	pub.ShowNPic = function(szI, szT, iW, iH) {
		var hImg = document.getElementById('pupimg');
		var hCap = document.getElementById('puptxt');
		var fImg = (szI != '');

		if (priv.fImg) {
			if (hImg.firstChild) {
				hImg.removeChild(hImg.firstChild);
			}
		} else {
			hImg.innerHTML = '';
		}
		if (hCap.firstChild) {
			hCap.removeChild(hCap.firstChild);
		}
		priv.fImg = fImg;

		if (fImg) {
			if (!priv.rgNP[szI]) {
				priv.rgNP[szI] = new Image();
				priv.rgNP[szI].src = szI;
				priv.addEvent(priv.rgNP[szI], "click", function() { pub.ClosePic(); } );
			}
			hImg.style['display'] = 'block';
			hImg.appendChild(priv.rgNP[szI]);
			if (szT != '') {
				hCap.appendChild(document.createTextNode(szT));
			}
		} else {
			hImg.style['display'] = 'inline';
			hImg.innerHTML = szT;
		}
		hCap.style.width=iW + 'px';
		priv.AdjustBorders(iW, iH, fImg);
		document.getElementById('pupbox').style.visibility = 'visible';
	}

	pub.ClosePic = function() {
		var hImg = document.getElementById('pupimg');
		var hCap = document.getElementById('puptxt');

		if (priv.fImg) {
			if (hImg.firstChild) {
				hImg.removeChild(hImg.firstChild);
			}
		} else {
			hImg.innerHTML = '';
		}
		if (hCap.firstChild) {
			hCap.removeChild(hCap.firstChild);
		}
		document.getElementById('pupbox').style.visibility = 'hidden';
		priv.fImg = false;
	}

	return pub;
}();



