

PsvPopup = function() {
		
};

PsvPopup.prototype.timeOut = null;
PsvPopup.prototype.timing = false;
PsvPopup.prototype.id = null;
PsvPopup.prototype.divContainer = null;
PsvPopup.prototype.divTitle = null;
PsvPopup.prototype.divDescription = null;
PsvPopup.prototype.divSources = null;
PsvPopup.prototype.divClose = null;
		
PsvPopup.prototype.init = function(id, title, description, sources)
{
	this.id = id;

	this.divContainer = document.createElement('div');
	this.divContainer.id = 'msg-details-' + id;
	this.divContainer.className = 'msg-details';
	this.divContainer.style.display = 'none';
	
	this.divTitle = document.createElement('div');
	this.divTitle.id  = this.divContainer.id + '-title';
	this.divTitle.className = 'msg-details-title';
	this.divTitle.innerHTML = title;
	
	this.divClose = document.createElement('div');
	this.divClose.id = this.divContainer.id + '-close';
	this.divClose.className = 'msg-details-close';
	this.divClose.observe('click', this.closePopup.bind(this));
	
	this.divDescription = document.createElement('div');
	this.divDescription.id  = this.divContainer.id + '-description';
	this.divDescription.className = 'msg-details-description';
	this.divDescription.innerHTML = description;
	
	this.divSources = document.createElement('div');
	this.divSources.id  = this.divContainer.id + '-sources';
	this.divSources.className = 'msg-details-sources';
	this.divSources.innerHTML = sources;
	
	this.divTitle.appendChild(this.divClose);
	this.divContainer.appendChild(this.divTitle);
	this.divContainer.appendChild(this.divDescription);
	this.divContainer.appendChild(this.divSources);
	
	$('msg-details-container').appendChild(this.divContainer);
	
	this.attachEvents();
	
	this.show();
};

PsvPopup.prototype.show = function()
{
	var row = $('message_' + this.id);
	
	var offset = row.cumulativeOffset();
	
	//details.style.top = (offset.top + row.getHeight() - 1) + 'px';
	this.divContainer.style.top = (offset.top) + 'px';
	this.divContainer.style.left = (offset.left) + 'px';
	
	Effect.BlindDown(this.divContainer, {duration:0.4});
};

PsvPopup.prototype.closePopup = function()
{
	Effect.BlindUp(this.divContainer, {duration:0.4});
};

PsvPopup.prototype.removeSetTimer = function()
{
	if (!this.timing)
	{
		this.timing = true;
		this.timeOut = setTimeout(this.closePopup.bind(this), 100);
	}
};

PsvPopup.prototype.removeClearTimer = function()
{
	if (this.timing)
	{
		clearTimeout(this.timeOut);
		this.timing = false;
	}
};

PsvPopup.prototype.attachEvents = function()
{
	this.divContainer.observe('mouseout', this.removeSetTimer.bind(this));
	this.divTitle.observe('mouseout', this.removeSetTimer.bind(this));
	this.divDescription.observe('mouseout', this.removeSetTimer.bind(this));
	this.divSources.observe('mouseout', this.removeSetTimer.bind(this));
	
	this.divContainer.observe('mouseover', this.removeClearTimer.bind(this));
	this.divTitle.observe('mouseover', this.removeClearTimer.bind(this));
	this.divDescription.observe('mouseover', this.removeClearTimer.bind(this));
	this.divSources.observe('mouseover', this.removeClearTimer.bind(this));
};

function moreInfo(id)
{
	var ajax = new Implex.Core.Ajax();
	
	ajax.get('/?module=Default&action=Details&id=' + id);
}
