// JScript source code

//---------------------------------------------------------------------------------------------
// Nombre: ticker
// Descripcion:
//
//
//
//----------------------------------------------------------------------------------------------

function Ticker(name, id, shiftBy, interval)
{
  this.name     = name;
  this.id       = id;
  this.shiftBy  = shiftBy ? shiftBy : 1;
  this.interval = interval ? interval : 100;
  this.runId	= null;

  this.div = document.getElementById(id);
  
  // remove extra textnodes that may separate the child nodes
  // of the ticker div
  
  //end of extra textnodes removal

  //this.table = this.div.firstChild;
  this.table = this.div.getElementsByTagName('table').item(0);
  this.rows = this.table.getElementsByTagName('tr');
  this.nrows = 	this.rows.length;

  this.left = 0;
  
  this.shiftLeftAt = this.rows.item(0).getElementsByTagName('td').item(0).offsetWidth;
  

  this.div.style.height	= this.div.firstChild.offsetHeight;
  this.div.style.width = 2 * screen.availWidth;
  this.div.style.visibility = 'visible';
  
  this.colspans = getColspans(this.rows);
  
  function getColspans(rowlist)
  {
	var colspans = new Array();
	var ncols = new Array();
	var min = 999999;
	var minpos;
	
	for(var z=0;z<rowlist.length;z++)
	{
		ncols[z] = rowlist.item(z).getElementsByTagName('td').length;
		if(ncols[z] < min)
		{
			minpos = z;
			min = ncols[z];
		}
	}
	for(var j=0;j<rowlist.length;j++)
	{
		colspans[j] = ncols[j] / ncols[minpos];
	}
	
	return colspans;
  }
}

function startTicker()
{
  this.stop();

  this.left -= this.shiftBy;

  if (this.left <= -this.shiftLeftAt)
  {
    this.left = 0;
    
	for(var z=0;z<this.nrows;z++)
	{	
		var orow = this.rows.item(z);
		var cols = orow.getElementsByTagName('td');
		var arr = new Array();
		for(j=0;j<this.colspans[z];j++)
		{
			arr[j] = cols.item(j);
		
		}
		for(j=0;j<this.colspans[z];j++)
		{
			orow.appendChild(arr[j]);
		}
	}
    	
    this.shiftLeftAt = this.rows.item(0).getElementsByTagName('td').item(0).offsetWidth;
    
  }

  this.div.style.left = (this.left + 'px');

  this.runId = setTimeout(this.name + '.start()', this.interval);
}

function stopTicker()
{
  if (this.runId)
    clearTimeout(this.runId);

  this.runId = null;
}

Ticker.prototype.start = startTicker;
Ticker.prototype.stop = stopTicker;

var ticker = null; 


function startticker()
{
	
	ticker = new Ticker('ticker', 'listado1', 1, 20);
	ticker.start();
}


function event_onmouseover() {

	if(ticker.runId)
	{
		ticker.stop();
	}

}

function event_onmouseout() {

	if(!ticker.runId)
	{
		ticker.start();
	}

}
startticker();

//Constante que determina el intervalo de tiempo que pasa entre cada movimiento del ticker

