
/* -------  ImageProfile  -----*/
extendsObj(ImageProfile, PopupDiv);
function ImageProfile(objName, ajaxPHPScript)
{
	if ( arguments.length > 0 )
	{
        this.init(objName, ajaxPHPScript);
	}
}	
ImageProfile.prototype.init = function(objName, ajaxPHPScript)
{    
    ImageProfile.superclass.init.call(this, 'uploadImage');
	this.objName = objName;
	this.ajaxPHPScript = ajaxPHPScript;
	this.imageId = 0;
	this.clear();
	this.setContentDiv();
}

ImageProfile.prototype.setContentDiv = function()
{
	var html = '<div class="title"><span id="title" style="float: left;"></span><span  style="float: right;"><a class="menulink" style="cursor: pointer;"  onclick="' + this.objName + '.hideDiv(); return false;">Close popup</a></span><br></div>';
	html += '<img id="img">';
	html += '<div id="description" class="description"></div><br>';
	ImageProfile.superclass.setContentDiv.call(this, html);
}
ImageProfile.prototype.showDiv = function(imageId)
{
	this.imageId = imageId;
	this.loadImageFromServer();
	ImageProfile.superclass.showDiv.call(this);
};
ImageProfile.prototype.clear = function()
{
	this.data = null;
	this.responseText = null;
}
ImageProfile.prototype.hideDiv = function()
{
	ImageProfile.superclass.hideDiv.call(this);
}
ImageProfile.prototype.loadImageFromServer = function()
{
	this.clear();
	var referenceThis = this;
	var url = this.ajaxPHPScript + '?event=LoadImage&id=' + this.imageId;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport)
		{
			try
			{
				referenceThis.data = transport.responseText.evalJSON();
				referenceThis.responseText = transport.responseText;
			}catch(e){}
			referenceThis.answerOnRequest();
		},
		onFailue: function(transport)
		{
			alert('Please, check your connection!');
		}
	});
}
ImageProfile.prototype.answerOnRequest = function()
{
	if ( this.data != null )
	{
		setImageElement('img', this.data.imgFull);
		setDivContent('title', this.data.title);
		setDivContent('description', this.data.description);
	}
	else
	{
		alert(this.responseText);
	}
}

