<!--

// MyDHTML 1.0 Images library
// Version: 02.04.04

// Images handler >>> *****************************************

// Images constructor >>>

function imagesHandler(sRoot, oBrowser)
{
	this.is = oBrowser;
	this.root = sRoot;

	this.add = imagesHandler_addImage;
	this.overwrite = imagesHandler_overwriteImage;
	this.get = imagesHandler_getImage;
	this.getVirtual = imagesHandler_getVirtualImage;
	this.getVirtualIndex = imagesHandler_getVirtualImageIndex;

	this.images = new Array(); 	
}

// <<< Images constructor

// Public >>>

function imagesHandler_addImage(sName, sSrc, sAlt, iWidth, iHeight)
{
	var iIndex = this.getVirtualIndex(sName);

	if (iIndex == null)
		iIndex = this.images.length;

	this.images[iIndex] = new Array();
	this.images[iIndex][0] = ID_IMAGE + sName;
	this.images[iIndex][1] = new Image();
	this.images[iIndex][1].src = this.root + sSrc;
	this.images[iIndex][2] = new Array();
	this.images[iIndex][2]['width'] = iWidth;
	this.images[iIndex][2]['height'] = iHeight;
	this.images[iIndex][2]['alt'] = decodeURIComponent(sAlt);
}

function imagesHandler_overwriteImage(sName, sName1, div_height)
{
	var oImage = this.get(sName);
	var aImage = this.getVirtual(sName1);

	if (oImage)
	{
		oImage.src = aImage[1].src;
		oImage.alt = aImage[2]['alt'];
		oImage.width = aImage[2]['width'];
		oImage.height = aImage[2]['height'];
		oImage.style.width = aImage[2]['width'];
		oImage.style.height = aImage[2]['height'];

		if (div_height > 0)
			oImage.style.marginTop = Math.round((div_height - aImage[2]['height']) / 2);
	}
	else
	{
		doHalt('Unknown image "' + sName + '"');
	}
}

function imagesHandler_getImage(sName)
{
	var oImage = new elementHandler(sName, ID_IMAGE, this.is);

	return oImage.object;
}

function imagesHandler_getVirtualImage(sName)
{
	for (var i = 0; i < this.images.length; i++)
	{
		if (this.images[i][0] == (ID_IMAGE + sName))
			return this.images[i];
	}

	doHalt('Unknown virtual image "' + sName + '"');

	return null;
}

function imagesHandler_getVirtualImageIndex(sName)
{
	for (var i = 0; i < this.images.length; i++)
	{
		if (this.images[i][0] == (ID_IMAGE + sName))
			return i;
	}

	return null;
}

// <<< Public

// <<< Images handler *****************************************

// -->

