// JavaScript Document

// Uses Actions.js

// Global vars
var addList = new Array();
var addInterval = 100;

function AddListCreate(id, displayInterval, fadeInterval)
{
  var el = document.getElementById(id);
	if (el == null)
    el = top.document.getElementById(id);

	if (el != null)
	{
	  addList.push(new _addListObject(id, el, displayInterval, fadeInterval));
	  setTimeout("_runAdds()", addInterval);
	}
	else
	{
		alert("AddListCreate: error - " + id);
	}
}

function AddImage(id, src)
{
	var ao = _getAddObject(id);
	if (ao != null)
	{
    ao.items.push(src);
	}
}

function AddStart(id)
{
	var ao = _getAddObject(id);
	if (ao != null)
    ao.run = 1;
}

function AddStop(id)
{
	var ao = _getAddObject(id);
	if (ao != null)
    ao.run = 0;
}

/***********************************************************************/

function _addListObject(id, el, displayInterval, fadeInterval)
{
	this.id       = id;
	this.el       = el;
	this.interval = displayInterval + fadeInterval;
	this.fadeInterval = fadeInterval;
	this.index    = 0;
	this.timeout  = 0;
	this.items    = new Array();;
	this.run      = 0;
}

function _getAddObject(id)
{
	var i;
	
  for (i = 0; i < addList.length; i++)
	{
		if (addList[i].id == id)
		  return addList[i];
	}
	
	return null;
}

function _runAdds() {
	var ao;
	var i;

  // Loop throuhg all active objects.
  for (i = 0; i < addList.length; i++)
	{

    // Get current object.
		ao = addList[i];
		
		// If add running, process timeouts.
		if (ao.run == 1)
		{
			if (ao.timeout == 0)
			{
//				ao.el.src = ao.items[ao.index];
        FadePage(ao.id, 'cross', ao.items[ao.index], ao.fadeInterval);
				ao.index++;
				if (ao.index >= ao.items.length)
				  ao.index = 0;
				
				ao.timeout = (ao.interval * 1000) / addInterval;
			}
			else
			{
				ao.timeout--;
			}
		}
	}

  setTimeout("_runAdds()", 100);
}

