
	// JavaScript Document
	// CEvent v01
	// Ailantd & Additive Works 
	// www.ailantd.com & www.additiveworks.com

	oEvent = new CEvent ;				// Initialize singleton

	// CEvent()
	//------------------------------------------------------------
	//
	// METODOS
	//------------------------------------------------------------
	// HasEvent( sEvent , oFunction )
	// Handle( sEvent , oFunction )
	// UnHandle( sEvent , oFunction )
	// UnHandleAll( sEvent )
	// Throw( sEvent )
	//------------------------------------------------------------
	function CEvent()
	{
		this.vEvent = [] ;				// Array de Eventos		
		
		//------------------------------------------
		// METODOS
		//------------------------------------------

		// HAS EVENT
		//
		//-------------------------------------------------
		this.HasEvent = function HasEvent( sEvent , oFunction )
		{
			if( this.vEvent.hasOwnProperty( sEvent ) )
			{
				var nEventLength = this.vEvent[sEvent].length ;
				for( var i = 0 ; i < nEventLength ; i++ )
				{
					if( this.vEvent[sEvent][i] == oFunction ) return true ;
				}
			}
			return false ;
		}

		// HANDLE
		//
		//-------------------------------------------------
		this.Handle = function Handle( sEvent , oFunction )
		{
			if( !this.vEvent.hasOwnProperty( sEvent ) ) this.vEvent[ sEvent ] = [] ;
			this.vEvent[ sEvent ].push( oFunction ) ;
		}

		// UN HANDLE
		// 
		//-------------------------------------------------
		this.UnHandle = function UnHandle( sEvent , oFunction )
		{
			if( this.vEvent.hasOwnProperty( sEvent ) )
			{
				var nEventLength = this.vEvent[sEvent].length ;
				for( var i = 0 ; i < nEventLength ; i++ )
				{
					if( this.vEvent[sEvent][i] == oFunction )
					{
						this.vEvent[sEvent].splice( i , 1 ) ;
						if( this.vEvent[sEvent].length == 0 ) delete this.vEvent[sEvent] ;
						return true ;
					}
				}
			}
			return false ;
		}

		//UN HANDLE ALL
		//
		//-------------------------------------------------
		this.UnHandleAll = function UnHandleAll( sEvent )
		{
			if( this.vEvent.hasOwnProperty( sEvent ) )
			{
				delete this.vEvent[sEvent] ;
				return true ;
			}
			return false ;
		}

		// THROW
		// Lanza un evento - ( Ejecuta todas las funciones asociadas )
		//-------------------------------------------------
		this.Throw = function Throw( sEvent )
		{
			if ( this.vEvent.hasOwnProperty( sEvent ) )
			{
				var nEventLength = this.vEvent[sEvent].length ;
				for( i = 0 ; i < nEventLength ; i++ )
				{
					if( this.vEvent[sEvent][i] ) this.vEvent[sEvent][i]() ;  //CHEQUEAR ESTO... QUE TIENE ALGUN BUG
				}
			}
		}
	}
