BannerRotator = function(id, banners, width, height, effect, speedMov, speedChange, deltaMov) {
	this.banners = banners || {};
	this.width = width || 500;
	this.height = height || 100;
	this.effect = effect || 'scroll_left';
	this.deltaMov = deltaMov || 5;
	this.speedMov = speedMov || 70;
	this.speedChange = speedChange || 10000;
	this.numBanners = banners.length;
	this.counter = 0;
	if (this.effect == 'scroll_right')
		this.currentPositionX = -width;
	else 
		this.currentPositionX = 0;
	if (this.effect == 'scroll_down')
		this.currentPositionY = -height;
	else 
		this.currentPositionY = 0;
	this.id = id;
}

BannerRotator.prototype.moveBanner = function() {
  layer = document.getElementById(this.id + '_layer2');
  layer.style.left = this.currentPositionX + "px";
  layer.style.top = this.currentPositionY + "px";
  switch (this.effect) {
	  case 'scroll_up': 
			  this.currentPositionY = this.currentPositionY - this.deltaMov;
			  if ( this.currentPositionY <= -(this.height) )
				this.updateBanners();
			  else {
				  var obj = this;
				  setTimeout(function () { obj.moveBanner(); }, this.speedMove);
			  }
		break;
	  case 'scroll_down': 
			  this.currentPositionY = this.currentPositionY + this.deltaMov;
			  if ( this.currentPositionY >= 0 )
				this.updateBanners();
			  else {
				  var obj = this;
				  setTimeout(function () { obj.moveBanner(); }, this.speedMove);
			  }
		break;
	  case 'scroll_right': 
			  this.currentPositionX = this.currentPositionX + this.deltaMov;
			  if ( this.currentPositionX >= 0 )
				this.updateBanners();
			  else {
				  var obj = this;
				  setTimeout(function () { obj.moveBanner(); }, this.speedMove);
			  }
		break;
	  default: 
		  this.currentPositionX = this.currentPositionX - this.deltaMov;
		  if ( this.currentPositionX <= -(this.width) )
			this.updateBanners();
		  else {
			  var obj = this;
			  setTimeout(function () { obj.moveBanner(); }, this.speedMove);
		  }
		break;
  }
}

BannerRotator.prototype.updateBanners = function() {
  layer = document.getElementById(this.id + '_layer2');
  switch (this.effect) {
	  case 'scroll_up': 
			  this.currentPositionY = 0;
			  layer.style.top = this.currentPositionY + "px";
		break;
	  case 'scroll_down': 
			  this.currentPositionY = -(this.height);
			  layer.style.top = this.currentPositionY + "px";
		break;
	  case 'scroll_right': 
			  this.currentPositionX = -(this.width);
			  layer.style.left = this.currentPositionX + "px";
		break;
	  default:
			  this.currentPositionX = 0;
			  layer.style.left = this.currentPositionX + "px";
  }

  this.counter++;
  c1 = document.getElementById(this.id + '_cell1');
  c2 = document.getElementById(this.id + '_cell2');
  switch (this.effect) {
	  case 'scroll_down': 
	  case 'scroll_right': 
		  c2.innerHTML = c1.innerHTML;
		  c1.innerHTML = this.banners[ this.counter % this.numBanners ];
		  break;
	  default: 
		  c1.innerHTML = c2.innerHTML;
		  c2.innerHTML = this.banners[ this.counter % this.numBanners ];
  }
  if (this.numBanners > 1) {
	  var obj = this;
	  setTimeout(function () { obj.moveBanner(); }, this.speedChange);
  }
}

BannerRotator.prototype.start = function() {
	switch (this.effect) {
	  case 'scroll_down': 
	  case 'scroll_right': 
	 	  c1 = document.getElementById(this.id + '_cell1');
		  c1.innerHTML = this.banners[ this.counter ]; 
		  break;
	  default: 
	 	  c2 = document.getElementById(this.id + '_cell2');
		  c2.innerHTML = this.banners[ this.counter ]; 
	}
	this.updateBanners();
}