/*
 *  Function : dhtmlObject
 *  Author   : Rogier Spieker
 *             Raymond Ris
 *  Date     : March 6th 2003
 *  Synopsis : object dhtmlObject( string layer [, string parentlayer ] );
 *  Purpose  : Create a DHTML accessible object from a layer, with the most
 *             primal methods aboard.
 */
function dhtmlObject( sLayer, sParent )
{
	// Assign properties
	this.object     = document.all ? document.all[ sLayer ] : document.getElementById ? document.getElementById( sLayer ) : document.layers ? eval( ( sParent != "" && sParent != null ? "document." + sParent + "." : "" ) + "document." + sLayer ) : 0;
	this.css        = this.object.style || this.object;
	this.ref        = this.css.document || document;
	this.pxlLeft    = parseInt( this.css.left ) || this.css.pixelLeft || this.object.offsetLeft || 0;
	this.pxlTop     = parseInt( this.css.top )  || this.css.pixelTop  || this.object.offsetTop  || 0;
	this.pxlWidth   = this.object.offsetWidth || this.ref.width || this.css.pixelWidth ||this.css.clip.width || 0;
	this.pxlHeight  = this.object.offsetHeight ||this.ref.height || this.css.pixelHeight || this.css.clip.height ||  0;
	this.posAppend  = document.doctype ? "px" : 0;

	// Assign methods
	this.move = function( x, y )
	{
		this.pxlLeft = parseInt( this.css.posLeft = this.css.left = x + this.posAppend );
		this.pxlTop  = parseInt( this.css.posTop  = this.css.top  = y + this.posAppend );
	}
	this.clip = function( t, r, b, l )
	{
		if ( this.css.clip.width )
		{
			this.pxlWidth  = this.css.clip.width  = ( r - l );
			this.pxlHeight = this.css.clip.height = ( b - t );
		}
		else
		{
			this.css.clip = "rect( " + t + "px " + r + "px " + b + "px " + l + "px )";
			this.pxlWidth  = ( r - l );
			this.pxlHeight = ( b - t );
		}
	}
	this.show = function()
	{
		this.css.visibility = "visible";
	}
	this.hide = function()
	{
		this.css.visibility = "hidden";
	}

	this.self = sLayer + "object";
	eval( this.self + "=this" );
	return this;
}

/*
 *  Function : dhtmlObjectPlus
 *  Author   : Rogier Spieker
 *  Date     : March 10th 2003
 *  Synopsis : object dhtmlObjectPlus( string layer [, string parentLayer ] )
 *  Purpose  : constructor for an extended dhtmlObject, capable of attaching methods and events
 */
function dhtmlObjectPlus( sLayer, sParent )
{
	// Hey Ma, look it's me!
	this.mom = dhtmlObject;
	this.mom( sLayer, sParent );

	// Methods for attaching/removing methods
	this.addMethod = function( sFunction )
	{
		eval( "this." + sFunction + "=" + sFunction );
	}

	this.delMethod = function( sFunction )
	{
		eval( "this." + sFunction + "=null" );
	}

	// Methods for declaration of event handlers
	this.addEventHandler = function( sEvent, sMethod )
	{
		if ( this.object.captureEvents )
			this.object.captureEvents( eval( "Event." + sEvent.toUpperCase() ) );
		eval( "this.object.on" + sEvent.toLowerCase() + "= new Function( \"evt\", \"return " + this.self + "." + sMethod +"( evt );\" )" );
	}

	this.delEventHandler = function( sEvent )
	{
		if ( this.object.releaseEvents )
			this.object.releaseEvents( eval( "Event." + sEvent.toUpperCase() ) );
		eval( "this.object.on" + sEvent.toLowerCase() + "=null" );
	}

}