var i = 0;
var wi = 330;

function getWidth() {
    return (document.body.clientWidth);
}

function Ticker(name, id, contID, shiftBy, interval) {
	this.name     = name;
	this.id       = id;
	this.contID   = contID;
	this.shiftBy  = shiftBy;
	this.interval = interval;
	this.runId	= null;
	
	this.div = document.getElementById(id);
	this.cont_div = document.getElementById(contID);
	
	var node = this.div.firstChild;
	var next;
	
	while (node) {
		next = node.nextSibling;
		if (node.nodeType == 3) this.div.removeChild(node);
		node = next;
	}

	this.left = getWidth() - wi;
	this.shiftLeftAt = this.div.firstChild.offsetWidth;
	this.div.style.height	= this.div.firstChild.offsetHeight;
	
	this.div.style.width = 2 * (getWidth() - wi);
	this.div.style.visibility = 'visible';
	this.cont_div.style.width = getWidth() - wi + 'px';
}

function startTicker() {
	this.stop();
	
	if(i==10) {
		this.cont_div.style.width = getWidth() - wi + 'px';
		i = 0;
	}  else { i++; }

	this.left -= this.shiftBy;

	if( this.shiftLeftAt == 0) {
		this.shiftLeftAt = this.div.firstChild.offsetWidth;
	}

	if (this.left <= -this.shiftLeftAt && this.shiftLeftAt != 0) {
		this.left = getWidth() - wi;
		this.div.appendChild(this.div.firstChild);
	}

	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;
}

function changeTickerInterval(newinterval) {
	if (typeof(newinterval) == 'string') newinterval =  parseInt('0' + newinterval, 10); 
	if (typeof(newinterval) == 'number' && newinterval > 0) this.interval = newinterval;
    this.stop();
    this.start();
}

/* Prototypes for Ticker */
Ticker.prototype.start = startTicker;
Ticker.prototype.stop = stopTicker;
Ticker.prototype.changeInterval = changeTickerInterval;
//var i = 0;
//var wi = 10;
//function getWidth()
//{
//	if (tickerW.width=='100%')
//	{
//		return document.body.clientWidth;
//	}
//	else
//	{
//		return tickerW.width;
//	}
//}
//
//function Ticker(name, id, contID, shiftBy, interval)
//{
//  this.name     = name;
//  this.id       = id;
//  this.contID   = contID;
//  this.shiftBy  = shiftBy;
//  this.interval = interval;
//  this.runId	= null;
//
//  this.div = document.getElementById(id);
//  this.cont_div = document.getElementById(contID);
//
//  var node = this.div.firstChild;
//  var next;
//
//  while (node)
//  {
//    next = node.nextSibling;
//    if (node.nodeType == 3)
//      this.div.removeChild(node);
//    node = next;
//  }
//
//  this.left = getWidth() - wi;
//  this.shiftLeftAt = this.div.firstChild.offsetWidth;
//  this.div.style.height	= this.div.firstChild.offsetHeight;
//  
//  this.div.style.width = 2 * (getWidth() - wi);
//  this.div.style.visibility = 'visible';
//  this.cont_div.style.width = getWidth() - wi + 'px';
//}
//
//function startTicker()
//{
//  this.stop();
//
//  if(i==10) {
//	  this.cont_div.style.width = getWidth() - wi + 'px';
//	  i = 0;
//  }  else { i++; }
//  
//  
//  this.left -= this.shiftBy;
//  
//  if( this.shiftLeftAt == 0) 
//  {
//	this.shiftLeftAt = this.div.firstChild.offsetWidth;
//  }
//
//  if (this.left <= -this.shiftLeftAt && this.shiftLeftAt != 0)
//  {
//
//    this.left = getWidth() - wi;
//    this.div.appendChild(this.div.firstChild);
//  }
//
//  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;
//}
//
//function changeTickerInterval(newinterval)
//{
//
//  if (typeof(newinterval) == 'string')
//    newinterval =  parseInt('0' + newinterval, 10); 
//	
//  if (typeof(newinterval) == 'number' && newinterval > 0)
//    this.interval = newinterval;
//    
//    this.stop();
//    this.start();
//}
//
///* Prototypes for Ticker */
//Ticker.prototype.start = startTicker;
//Ticker.prototype.stop = stopTicker;
//Ticker.prototype.changeInterval = changeTickerInterval;