/*
	Created by       : Petyo Ivanov
	Last modified by : Petyo Ivanov
	Last Updated     : 10/4/2003
	Comments         :
	Jscript extensions to improve the engine - put only the most generic methods and prototype assignments here
*/


// stollen from moonjogger < http://moonjogger.host.sk >
ASBroadcaster = new Object();

ASBroadcaster.addListener = function(listener)
{
   this.removeListener(listener);
   this._listeners.push(listener);
   return true;
}

ASBroadcaster.removeListener = function(listener)
{
   var i = this._listeners.length;
   
   while(--i >= 0)
       if(this._listeners[i] == listener)
       {
               this._listeners.splice(i,1);
               return true;
       }
       
   return false;
}

ASBroadcaster.broadcastMessage = function(theEvent)
{
    var i = this._listeners.length;
    while(--i >= 0)
	try
	{
		this._listeners[i][theEvent]();
	}

	catch (e)
	{

	}
}

ASBroadcaster.initialize = function(obj)
{
   obj.addListener = this.addListener;
   obj.removeListener = this.removeListener;
   obj.broadcastMessage = this.broadcastMessage;
   obj._listeners = [];
}

// prepare the objects for the OO style

ASBroadcaster.initialize(window);

window.onload = function ()
{
	this.broadcastMessage("onLoad");
}

// map it to whatever needed
function getByAttribute (nodeName, attributeName, attributeValue) {
   if (this.nodeName == nodeName && this.attributes[attributeName] == attributeValue)
      return this;
   else
      return this.firstChild.nextSibling.getByAttribute(nodeName, attributeName, attributeValue) || this.firstChild.getByAttribute(nodeName, attributeName, attributeValue);
}
