/*
	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);
}



/*
AddEvent Manager (c) 2005 Angus Turnbull http://www.twinhelix.com
Free usage permitted as long as this credit notice remains intact.
*/
if (typeof aeOL == 'undefined')
{
 var aeOL = [];
 var addEvent = function(o, n, f, l)
 {
  var d = 'addEventListener', h = 'on' + n, t, a;
  if (o[d] && !l) return o[d](n, f, false);
  if (!o.aE) { o.aE = aeOL.length || 1; aeOL[o.aE] = { o:o } }
  t = aeOL[o.aE][n] || (aeOL[o.aE][n] = []);
  for (var i = 0; i < t.length; i++)
   for (var j = 0; j < t[i].length; j++)
    if (t[i][j] == f) return;
  if (o[h] && o[h]._ae)
  {
   a = t[t.length - 1];
   a[a.length] = f;
  }
  else
  {
   t[t.length] = o[h] ? [o[h], f] : [f];
   o[h] = new Function('e', 'var r = true, i = 0, o = aeOL[' + o.aE + '].o,' +
    'a = aeOL[' + o.aE + ']["' + n + '"][' + (t.length - 1) + '];' +
    'for (; i < a.length; i++) { ' +
	 'o._f = a[i]; r = o._f(e||window.event) != false && r; o._f = null;' +
    '} return r');
   o[h]._ae = 1;
  }
 };

 var removeEvent = function(o, n, f, l)
 {
  var d = 'removeEventListener', t, a, i, j, s;
  if (o[d] && !l) return o[d](n, f, false);
  if (!o.aE || !aeOL[o.aE]) return;
  t = aeOL[o.aE][n];
  i = t.length;
  while (i--)
  {
   a = t[i];
   j = a.length;
   s = 0;
   while (j--)
   {
    if (a[j] == f) s = 1;
    if (s) a[j] = a[j + 1];
   }
   if (s) { a.length--; break }
  }
 };

}
