/**
  * class DivScroller
  */

DivScroller = function (idContainer, leftHandle, rightHandle)
{
  this._init (idContainer, leftHandle, rightHandle);
}


/**
 * _init sets all DivScroller attributes to their default value. Make sure to call this
 * method within your class constructor
 */
DivScroller.prototype._init = function (idContainer, leftHandle, rightHandle)
{
	this.isIE = false;
	this.scrollStep = 1;
	this.timerLeft;
	this.timerRight;
	this.container = document.getElementById(idContainer);
	var ttl = document.getElementById(leftHandle);
	var ttr = document.getElementById(rightHandle);

	if((this.container.scrollHeight) <= this.container.clientHeight){
		
		ttl.style.display = "none";
		ttr.style.display = "none";
	}
	else{
		ttl.style.display = "block";
		ttr.style.display = "block";
	}
	
	if(navigator.appVersion.indexOf("MSIE") != -1){
		this.isIE = true;
	}

}

DivScroller.prototype.toLeft = function(){
  this.container.scrollLeft = 0;
}

DivScroller.prototype.scrollDivRight = function(){
  //il valore 50 funziona in questo caso....negli altri è da provare
  if(this.container.scrollWidth - this.container.offsetWidth > 50){
  	clearTimeout(this.timerRight);
  	this.container.scrollLeft += this.scrollStep;
  	this.timerRight = setTimeout("divScroller.scrollDivRight()",10);
  }
}

DivScroller.prototype.scrollDivLeft = function(){
  clearTimeout(this.timerLeft);
  this.container.scrollLeft -= this.scrollStep;
  this.timerLeft = setTimeout("divScroller.scrollDivLeft()",10);
}

DivScroller.prototype.toRight = function(){
  this.container.scrollLeft = this.container.scrollWidth;
}

DivScroller.prototype.scrollDivTop = function(){
  if(this.container.scrollHeight - this.container.offsetHeight > 0){
  	clearTimeout(this.timerTop);
  	this.container.scrollTop += this.scrollStep;
  	this.timerTop = setTimeout("divScroller.scrollDivTop()",10);
}}

DivScroller.prototype.scrollDivBottom = function(){
  if(this.container.scrollHeight - this.container.offsetHeight > 0){
  	clearTimeout(this.timerBottom);
  	this.container.scrollTop -= this.scrollStep;
  	this.timerBottom = setTimeout("divScroller.scrollDivBottom()",10);
}}

DivScroller.prototype.stop = function(){
  clearTimeout(this.timerRight);
  clearTimeout(this.timerLeft);
  clearTimeout(this.timerTop);
  clearTimeout(this.timerBottom);
}



// JavaScript Document
