/*
 *               ____
 *              /\   \
 *             ___\   \___
 *            /\          \
 *            \ \___    ___\
 *        ____ \/__/\   \__/
 *       /\   \    \ \___\    klof  |  innovative web technology
 *      ___\   \___ \/___/
 *     /\          \          keen/dynamic.js
 *     \ \___    ___\         HTML Element manipulation
 *      \/__/\   \__/
 *          \ \___\           Copyright 2003-2007, klof
 *           \/___/           http://keen.klof.net/
 *
 *                            requirements: keen/style.js
 */


/* Create the master Keen object if it doesn't exist */
if ( typeof Keen != "object" )
	Keen = new ( function(){ this._child = 0 } )();



Keen.dynamic = function( mElement )
{
	this._version = "1.1.3";
	if ( typeof mElement != "undefined" )
		this.init( mElement );
	return this;
};
Keen.dynamic.prototype.init = function( mElement )
{
	if ( typeof mElement == "string" && document.getElementById )
		this._object = document.getElementById( mElement );
	else if ( typeof mElement == "object" )
		this._object = mElement;
	else
		return false;

	this._id      = typeof this._object.id == "string" && this._object.id != "" ? this._object.id : "Keen" + ( ++Keen._child ) + "_"; 
	this._x       = this._object.offsetLeft || parseInt( this.getStyle( "left" ) ) || 0;
	this._y       = this._object.offsetTop || parseInt( this.getStyle( "top" ) ) || 0;
	this._z       = this.getStyle( "zIndex" );
	this._width   = this._object.offsetWidth || parseInt( this.getStyle( "width" ) ) || 0;
	this._height  = this._object.offsetHeight || parseInt( this.getStyle( "height" ) ) || 0;
	this._visible = this.getStyle( "visibility" ) != "hidden";
	this._fps     = 20;

	window[ ( this._self = this._id + "Object" ) ] = this;
};
Keen.dynamic.prototype.getStyle = function( sProperty )
{
	return Keen.style.get( this._object, sProperty );
};
Keen.dynamic.prototype.setStyle = function( sProperty, mValue )
{
	return Keen.style.set( this._object, sProperty, mValue );
};
Keen.dynamic.prototype.attachMethod = function( sMethod, oFunction )
{
	this[ sMethod ] = oFunction;
};
Keen.dynamic.prototype.detachMethod = function( sMethod )
{
	this[ sMethod ] = null;
	delete this[ sMethod ];
};
Keen.dynamic.prototype.attachEvent = function( sEvent, sMethod )
{
	// we will be using addEventListener and attachEvent in the near future.
	eval( "this._object.on" + sEvent.toLowerCase() + "= new Function( \"evt\", \"return " + this._self + "." + sMethod + "( evt );\" )" );
};
Keen.dynamic.prototype.detachEvent = function( sEvent )
{
	this._object[ "on" + sEvent.toLowerCase() ] = null;
};
Keen.dynamic.prototype.timedcall = function( mCall, nMillisecond )
{
	return setTimeout( typeof mCall == "function" ? mCall : this._self + "." + mCall, nMillisecond );
};

Keen.dynamic.prototype.setX = function( nValue )
{
	this._x = parseInt( this.setStyle( "left", nValue + "px" ) );
};
Keen.dynamic.prototype.setY = function( nValue )
{
	this._y = parseInt( this.setStyle( "top", nValue + "px" ) );
};
Keen.dynamic.prototype.setWidth = function( nValue )
{
	this._width = parseInt( this.setStyle( "width", nValue + "px" ) );
};
Keen.dynamic.prototype.setHeight = function( nValue )
{
	this._height = parseInt( this.setStyle( "height", nValue + "px" ) );
};
Keen.dynamic.prototype.setVisible = function( mValue )
{
	this._visible = this.setStyle( "visibility", typeof mValue == "boolean" ? mValue ? "visible" : "hidden" : mValue   ) == "visible";
};
Keen.dynamic.prototype.getAlpha = function()
{
	this._alpha = this.getStyle( "opacity" ) || this.getStyle( "MozOpacity" ) || this.getStyle( "KHTMLOpacity" ) || false;
	if ( !this._alpha )
	{
		if ( typeof object.filters != "undefined" && typeof object.filters.alpha != "undefined" && typeof object.filters.alpha.opacity != "undefined" )
			this._alpha = parseInt( object.filters.alpha.opacity );
		else
			this._alpha = 100;
	}
	else
	{
		this._alpha *= 100;
	}
	return this._alpha;
};
Keen.dynamic.prototype.setAlpha = function( nPercentage )
{
/*
	if ( typeof object.filters != "undefined" && typeof object.filters.alpha != "undefined" && typeof object.filters.alpha.opacity != "undefined" )
	{
		object.filters.alpha.opacity = nPercentage;
	}
	else
	{
*/
		this.setStyle( "filter", "alpha(opacity=" + nPercentage + ")" );
		nPercentage /= 100;
		this.setStyle( "opacity", nPercentage );
		this.setStyle( "MozOpacity", nPercentage );
		this.setStyle( "KHTMLOpacity", nPercentage );
/*
	}
*/
};

Keen.dynamic.prototype.move = function( nX, nY )
{
	this.setX( nX );
	this.setY( nY );
};
Keen.dynamic.prototype.resize = function( nW, nH )
{
	this.setWidth( nW );
	this.setHeight( nH );
};
Keen.dynamic.prototype.show = function()
{
	this.setVisible( true );
};
Keen.dynamic.prototype.hide = function()
{
	this.setVisible( false );
};
