threadpreview = function(obj, path){
	var tPopup = new threadpopup(obj, path);
	return false;
}

threadpopup = function(obj, path){
	this.parent = obj;
	this.screen = new solidscreen;
	this.screen.parent = this;

	this.buffer = new htmlbuffer(this);
	this.buffer.setSrc('/forumThreadPopup.buffer?path=' + path);

	this.close = function(){
		this.screen.clickEnable = true;
		this.screen.clear();
	}

	this.onDone = function(result){
		this.screen.clickEnable = false;

		var owinelm = document.createElement("DIV");
		owinelm.style.visibility = 'hidden';
		owinelm.className = 'threadpopupElement';
		this.screen.element.appendChild(owinelm);

		var odiv = document.createElement("DIV");

		odiv.className = 'threadpopup';
		if(result.type == 'error'){
			odiv.className += ' error';
		}
		owinelm.appendChild(odiv);

		var oWidth = owinelm.offsetWidth;
		var oHeight = owinelm.offsetHeight;

		var objTop = offsetY(this.parent) + this.parent.offsetHeight / 2;
		var objLeft = offsetX(this.parent) + this.parent.offsetWidth;

		var oLeft = objLeft + oWidth > document.body.clientWidth ? document.body.clientWidth - oWidth : objLeft;
		var oTop = objTop - (oHeight) / 2;

		var arrdiv = document.createElement("DIV");
		arrdiv.className = 'arr';
		odiv.appendChild(arrdiv);

		var cdiv = document.createElement("DIV");
		cdiv.className = 'container';
		odiv.appendChild(cdiv);

		if(result.title){
			var d = document.createElement("DIV");
			d.className = 'tableHeader';
			cdiv.appendChild(d);
			var dd = document.createElement("DIV");
			d.appendChild(dd);

			var tdiv = document.createElement("DIV");
			tdiv.className = 'title';
			tdiv.innerHTML = result.title;
			cdiv.appendChild(tdiv);

			if(result.subtitle){
					var stdiv = document.createElement("DIV");
					stdiv.className = 'sub';
					tdiv.appendChild(stdiv);
					stdiv.innerHTML = result.subtitle;
			}
		}

		if(result.commands){
			var cb = document.createElement("DIV");
			cb.className = 'commandsBar';
			cdiv.appendChild(cb);

			for(var cmd in result.commands){
				var command = result.commands[cmd];
				var cA = document.createElement("A");
				if(command.url){
					cA.href = command.url;
				}
				cb.appendChild(cA);
				cA.innerHTML = cmd;
			}
		}

		var cntnt = document.createElement("DIV");
		cntnt.className = 'content';
		cdiv.appendChild(cntnt);
		cntnt.style.height = 377 - cntnt.offsetTop;

		var cntntDiv = document.createElement("DIV");
		cntntDiv.className = 'div';
		cntnt.appendChild(cntntDiv);

		cntntDiv.innerHTML = result.content;

		with(owinelm.style){
			top			= oTop;
			left		= oLeft;
			visibility	= 'visible';
		}

		var odivClose = document.createElement("DIV");
		odivClose.parent = this;
		odivClose.className = 'close';
		cdiv.appendChild(odivClose);

		odivClose.style.left = cdiv.offsetWidth - odivClose.offsetWidth;

		odivClose.onclick = function(){
			this.parent.close();
		}

	}
}
