<!--

// MyDHTML 1.0 Layer library
// Development version 30.06.03
// By ivar@mindworks.ee
// Tested: IE5+, NN7+

// Layer handler >>> ******************************************

// Layer constructor >>> --------------------------------------

function layerHandler(strName, oBrowser)
{

	this.name = strName;
	this.id = ID_LAYER + strName;
	this.is = oBrowser;
	this.getObject = layerHandler_getLayerObject;
	this.object = this.getObject();
	this.visible = false;

	this.getWidth = layerHandler_getLayerWidth;
	this.getHeight = layerHandler_getLayerHeight;
	this.getLeft = layerHandler_getLayerLeft;
	this.getRight = layerHandler_getLayerRight;
	this.getTop = layerHandler_getLayerTop;
	this.getBottom = layerHandler_getLayerBottom;
	this.getZIndex = layerHandler_getLayerZIndex;
	this.getInfo = layerHandler_getLayerInfo;
	
	this.left = null;	
	this.top = null;	
	this.width = null;
	this.height = null;
	this.setLeft = layerHandler_setLayerLeft;
	this.setTop = layerHandler_setLayerTop;
	this.setWidth = layerHandler_setLayerWidth;
	this.setHeight = layerHandler_setLayerHeight;
	this.moveTo = layerHandler_setLayerLeftTop;
	this.setColor = layerHandler_setLayerColor;
	this.setOpacity = layerHandler_setLayerOpacity;
	this.setZIndex = layerHandler_setLayerZIndex;
	this.castShadow = layerHandler_castLayerShadow;
	this.show = layerHandler_showLayer;
	this.hide = layerHandler_hideLayer; 

	this.attached = new Array();
	this.attach = layerHandler_attachLayer;
	this.moveAttachedTo = layerHandler_setAttachedLayerLeftTop;
	this.showAttached = layerHandler_showAttachedLayer;
	this.hideAttached = layerHandler_hideAttachedLayer; 
	this.getAttached = layerHandler_getAttachedLayer; 

//	if (this.is.MZ5) this.object.style.clip = layerHandler_setClip(0, 0, this.getWidth(), this.getHeight());
	
}

// <<< Layer constructor --------------------------------------

// External >>> -----------------------------------------------

function layerHandler_setClip(intLeft, intTop, intRight, intBottom)
{
	return 'rect(' + intTop + 'px ' + intRight + 'px ' + intBottom + 'px ' + intLeft + 'px)';
}

// <<< External -----------------------------------------------

// Private >>> ------------------------------------------------

function layerHandler_getLayerObject() // OK
{
	if (this.is.IE5)
	{
		return eval('document.all.' + this.id);
	}
	else if (this.is.MZ5)
	{
		return document.getElementById(this.id);
	}
	else if (this.is.MZ4)
	{
		return eval('document.layers["' + this.id + '"]');
	}
}

// <<< Private ------------------------------------------------

// Public >>> -------------------------------------------------

// Visibility >>>

function layerHandler_showLayer() // OK
{

	if (this.is.IE5)
	{
		this.object.style.visibility = 'visible';
	}
	else if (this.is.MZ5)
	{
		this.object.style.visibility = 'visible';
	}
	else if (this.is.MZ4)
	{
		this.object.visibility = 'show';
	}

	if (this.shadow) this.shadow.show();

	this.visible = true;	
	
}

function layerHandler_hideLayer() // OK
{

	if (this.is.IE5)
	{
		this.object.style.visibility = 'hidden';
	}
	else if (this.is.MZ5)
	{
		this.object.style.visibility = 'hidden';
	}
	else if (this.is.MZ4)
	{
		this.object.visibility = 'hide';
	}

	if (this.shadow) this.shadow.hide();

	for (var intLooper = 0; intLooper < this.attached.length; intLooper++)
	{
		this.attached[intLooper][2].hide();
	}

	this.visible = false;	
	
}

// <<< Visibility

// Get >>>

function layerHandler_getLayerInfo()
{
	var sInfo;
	sInfo = 'ID: ' + this.id + "\n";
	sInfo += 'Left: ' + this.getLeft() + "\n";
	sInfo += 'Top: ' + this.getTop() + "\n";
	sInfo += 'Width: ' + this.getWidth() + "\n";
	sInfo += 'Height: ' + this.getHeight() + "\n";
	sInfo += 'Visible: ' + this.visible + "\n";
	sInfo += 'Z-Index: ' + this.getZIndex();
	alert(sInfo);
}

function layerHandler_getLayerWidth() // OK
{
	if (this.width == null)
	{
		if (this.is.IE5)
		{
			return(this.object.style.pixelWidth);
		}
		else if (this.is.MZ5)
		{
			return(parseInt(this.object.style.width));
		}
		else if (this.is.MZ4)
		{
			return(this.object.clip.width);
		}
	}
	else
	{
		return this.width;
	}
}

function layerHandler_getLayerHeight() // OK
{
	if (this.height == null)
	{
		if (this.is.IE5)
		{
			return(this.object.style.pixelHeight);
		}
		else if (this.is.MZ5)
		{
			return(parseInt(this.object.style.height));
		}
		else if (this.is.MZ4)
		{
			return(this.object.clip.height);
		}
	}
	else
	{
		return this.height;
	}
}

function layerHandler_getLayerLeft() // OK
{
	if (this.left == null)
	{
		if (this.is.IE5)
		{
			return(this.object.style.pixelLeft);
		}
		else if (this.is.MZ5)
		{
			return parseInt(this.object.style.left);
		}
		else if (this.is.MZ4)
		{
			return(this.object.left);
		}
	}
	else
	{
		return this.left;
	}
}

function layerHandler_getLayerRight() // OK
{
	return this.getLeft() + this.getWidth();
}

function layerHandler_getLayerTop() // OK
{
	if (this.top == null)
	{
		if (this.is.IE5)
		{
			return this.object.style.pixelTop;
		}
		else if (this.is.MZ5)
		{
			return parseInt(this.object.style.top);
		}
		else if (this.is.MZ4)
		{
			return this.object.top;
		}
	}
	else
	{
		return this.top;
	}
}

function layerHandler_getLayerBottom() // OK
{
	return this.getTop() + this.getHeight();
}

function layerHandler_getLayerZIndex() // OK
{
	if (this.is.IE5)
	{
		return this.object.style.zIndex;
	}
	else if (this.is.MZ5)
	{
		return this.object.style.zIndex;
	}
	else if (this.is.MZ4)
	{
		return this.object.zIndex;
	}
}

// <<< Get

// Set >>>

function layerHandler_setLayerColor(strColor) // OK
{
	if (this.is.IE5)
	{
		this.object.style.backgroundColor = '#' + strColor;
	}
	else if (this.is.MZ5)
	{
		this.object.style.backgroundColor = '#' + strColor;
	}
	else if (this.is.MZ4)
	{
		this.object.bgColor = '#' + strColor;
	}
}

function layerHandler_setLayerWidth(intWidth) // OK
{

	this.width = intWidth;

	if (this.is.IE5)
	{
		this.object.style.width = intWidth;
	}
	else if (this.is.MZ5)
	{
		this.object.style.width = intWidth;
	}
	else if (this.is.MZ4)
	{
		this.object.clip.width = intWidth;
	}

	if (this.shadow) this.shadow.setWidth(intWidth);
	
}

function layerHandler_setLayerHeight(intHeight) // OK
{

	this.height = intHeight;

	if (this.is.IE5)
	{
		this.object.style.height = intHeight;
	}
	else if (this.is.MZ5)
	{
		this.object.style.height = intHeight;
	}
	else if (this.is.MZ4)
	{
		this.object.clip.height = intHeight;
	}

	if (this.shadow) this.shadow.setHeight(intHeight);

}

function layerHandler_setLayerLeft(intLeft) // OK
{

	this.left = intLeft;

	if (this.is.IE5)
	{
		this.object.style.left = intLeft;
	}
	else if (this.is.MZ5)
	{
		this.object.style.left = intLeft;
	}
	else if (this.is.MZ4)
	{
		this.object.left = intLeft;
	}

	if (this.shadow) this.shadow.setLeft(intLeft + SHADOW_OFFSETX);

	for (var intLooper = 0; intLooper < this.attached.length; intLooper++)
	{
		this.attached[intLooper][2].setLeft(intLeft + this.attached[intLooper][0]);
	}

}

function layerHandler_setLayerTop(intTop) // OK
{

	this.top = intTop;

	if (this.is.IE5)
	{
		this.object.style.top = intTop;
	}
	else if (this.is.MZ5)
	{
		this.object.style.top = intTop;
	}
	else if (this.is.MZ4)
	{
		this.object.top = intTop;
	}

	if (this.shadow) this.shadow.setTop(intTop + SHADOW_OFFSETY);

	for (var intLooper = 0; intLooper < this.attached.length; intLooper++)
	{
		this.attached[intLooper][2].setTop(intTop + this.attached[intLooper][1]);
	}

}

function layerHandler_setLayerLeftTop(intLeft, intTop) // OK
{
	this.setLeft(intLeft);
	this.setTop(intTop);
}

function layerHandler_castLayerShadow(intOpacity) // OK
{
	if ((this.is.IE5) && (!this.shadow))
	{
		if (typeof(this.object.filters) == 'object')
		{
			var oShadowLayer = eval('document.all.' + ID_LAYER + 'FWShadow');
			var oShadowLayerClone = oShadowLayer.cloneNode(true);
			oShadowLayerClone.id = ID_LAYER + this.name + '_shadow';
			document.body.appendChild(oShadowLayerClone);
			this.shadow = new layerHandler((this.name + '_shadow'), this.is);
			this.shadow.setHeight(this.getHeight());
			this.shadow.setWidth(this.getWidth());
			this.shadow.setZIndex(this.getZIndex() - 1);
			if (!this.shadow.setOpacity(intOpacity))
			{
				this.shadow = false;
			}
			else
			{
				this.shadow.moveTo(this.getLeft() + SHADOW_OFFSETX, this.getTop() + SHADOW_OFFSETY);
			}
		}
	}
}

function layerHandler_setLayerOpacity(intOpacity) // OK
{
	if (this.is.IE5)
	{
		// Modern way
		this.object.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + intOpacity + ')';
		if (this.object.filters.length == 1)
		{
			return true;
		} 
		else
		{
			// Old way
			this.object.style.filter = 'alpha(opacity=' + intOpacity + ')';
			if (this.object.filters.length == 1)
			{
				return true;
			}
		}
	}
}

function layerHandler_setLayerZIndex(intZIndex) // OK
{

	if (this.is.IE5)
	{
		this.object.style.zIndex = intZIndex;
	}
	else if (this.is.MZ5)
	{
		this.object.style.zIndex = intZIndex;
	}
	else if (this.is.MZ4)
	{
		this.object.zIndex = intZIndex;
	}

	if (this.shadow) this.shadow.setZIndex(intZIndex - 1);

	for (var intLooper = 0; intLooper < this.attached.length; intLooper++)
	{
		this.attached[intLooper][2].setZIndex(intZIndex + 1);
	}
	
}

// <<< Set

// Attached >>>

function layerHandler_attachLayer(strName, oLayer) // OK
{
	var intIndex = this.attached.length;
	this.attached[intIndex] = new Array();
	this.attached[intIndex][0] = 0; // Relative left
	this.attached[intIndex][1] = 0; // Relative top
	this.attached[intIndex][2] = oLayer;
	this.attached[intIndex][3] = strName;
	oLayer.setZIndex(this.getZIndex() + 1);
}

function layerHandler_setAttachedLayerLeftTop(strName, intLeft, intTop) // OK
{
	for (var intLooper = 0; intLooper < this.attached.length; intLooper++)
	{
		if (strName == this.attached[intLooper][3])
		{
			this.attached[intLooper][0] = intLeft;
			this.attached[intLooper][1] = intTop;
			break;
		}
	}
}

function layerHandler_showAttachedLayer(strName) // OK
{
	for (var intLooper = 0; intLooper < this.attached.length; intLooper++)
	{
		if (strName == this.attached[intLooper][3])
		{
			this.attached[intLooper][2].show();
			return true;
		}
	}
	doHalt('Unknown attached layer "' + strName + '"');
	return null;
}

function layerHandler_hideAttachedLayer(strName) // OK
{
	for (var intLooper = 0; intLooper < this.attached.length; intLooper++)
	{
		if (strName == this.attached[intLooper][3])
		{
			this.attached[intLooper][2].hide();
			return true;
		}
	}
	doHalt('Unknown attached layer "' + strName + '"');
	return null;
}

function layerHandler_getAttachedLayer(strName) // OK
{
	for (var intLooper = 0; intLooper < this.attached.length; intLooper++)
	{
		if (strName == this.attached[intLooper][3])
		{
			return this.attached[intLooper][2];
			break;
		}
	}
}

// <<< Attached

// <<< Public -------------------------------------------------

// <<< Layer handler ******************************************

// -->