//////////////////////////////////////////////////////////////////////////////////////////////////////////// Slider orizzontale

var Slider = {};

Slider.effect = function(ContainerID, ScrollID, NToolID, ElementXPage, Seconds){
  this.n = 0;
  this.ListContainer = document.getElementById(ContainerID);
  this.RefID = NToolID;
  this.ElemXPage = ElementXPage;
  this.ScrollDiv = document.getElementById(ScrollID);
  this.ScrollDiv.scrollLeft = 0;
  this.ScrollStep = Number (this.ScrollDiv.style.width.replace('px',''));
  this.Pos = "";
  this.PosTo = "";
  this.SelPage = 0; 
  
  if(Seconds>0){
    this.TimeoutSec = Seconds * 1000;
    this.timeout = setTimeout('Slider'+this.RefID+'.AutoScroll()', this.TimeoutSec);  
  }                                                                                 
}

Slider.effect.prototype.init = function( DotShow, CounterShow, ArrowShow ){
  this.Pages = Math.ceil(this.n / this.ElemXPage) - 1;
  this.ListContainer.style.width = ((this.Pages + 1) * this.ScrollStep) + "px";
  this.DotShow = DotShow;
  if(this.DotShow){
    this.DotDiv = document.getElementById('Dots'+this.RefID);
    this.DotDiv.innerHTML = '<span class="FocusDotSel" onClick="javascript:Slider'+this.RefID+'.timeReset(); Slider'+this.RefID+'.ListScrollDirect(\'0\')" id="PageDot_0_'+this.RefID+'"><img src="../temp/imgs/void.gif" width="11" height="11" title="Clicca" alt="Clicca" border="0"></span>' + "\n";
    for(i=1;i<=this.Pages;i++){
      this.DotDiv.innerHTML += '<span class="FocusDot" onClick="javascript:Slider'+this.RefID+'.timeReset(); Slider'+this.RefID+'.ListScrollDirect(\''+i+'\')" id="PageDot_'+i+'_'+this.RefID+'"><img src="../temp/imgs/void.gif" width="11" height="11" title="Clicca" alt="Clicca" border="0"></span>' + "\n";
    }
  }
  this.CounterShow = CounterShow;
  if(this.CounterShow){
    this.CounterDiv = document.getElementById('Counter'+this.RefID);
    this.CounterDiv.innerHTML = (this.SelPage+1) + " / " + (this.Pages + 1 );
  }
  this.ArrowShow = ArrowShow;
  this.DoArrowShow();
}

Slider.effect.prototype.DotChangeClass = function( To ){
  if(this.DotShow) document.getElementById('PageDot_' + this.SelPage+'_'+this.RefID).className = 'FocusDot';
  this.SelPage = To;
  this.SelPage = Math.max(this.SelPage, 0);
  this.SelPage = Math.min(this.SelPage, this.Pages);
  if(this.DotShow) document.getElementById('PageDot_' + this.SelPage+'_'+this.RefID).className = 'FocusDotSel';
  if(this.CounterShow) this.CounterDiv.innerHTML = (this.SelPage+1) + " / " + (this.Pages + 1 );
  
  this.DoArrowShow(); 
  
}

Slider.effect.prototype.ListScrollDirect = function ( To ){
  this.DotChangeClass(To);
  this.Pos = this.ScrollDiv.scrollLeft;
  this.PosTo = Math.min ((To*this.ScrollStep), this.ScrollDiv.scrollWidth);      
  this.ListScrollStart();      
}

Slider.effect.prototype.ListScrollStep = function( dir ){
  this.DotChangeClass((this.SelPage + dir));
  this.Pos = this.ScrollDiv.scrollLeft;
  this.PosTo = Math.min (this.ScrollDiv.scrollLeft+(dir*this.ScrollStep), this.ScrollDiv.scrollWidth);
  this.ListScrollStart();       
} 

Slider.effect.prototype.DoArrowShow = function(){
  if(this.ArrowShow){
    if(this.SelPage==this.Pages){
      document.getElementById('ArrowNext'+this.RefID).style.display="none";
    } else {
      document.getElementById('ArrowNext'+this.RefID).style.display="block";
    }
     
    if(this.SelPage==0){
      document.getElementById('ArrowPrev'+this.RefID).style.display="none";
    } else {
      document.getElementById('ArrowPrev'+this.RefID).style.display="block";
    }
  }
   
}
     

Slider.effect.prototype.ListScrollStart = function(){
  this.Pos += (this.PosTo - this.Pos) / 10;
  this.ScrollDiv.scrollLeft = this.Pos;
	
  if( this.Pos < this.PosTo+1 && this.Pos > this.PosTo-1 ){		
    this.Pos = this.PosTo;
    this.ScrollDiv.scrollLeft	= this.Pos;
  } else {		
    this.ScrollDiv.scrollLeft = this.Pos;
    setTimeout('javascript:Slider'+this.RefID+'.ListScrollStart();', 5);
  }               	
}

Slider.effect.prototype.AutoScroll = function(){  
  if(this.TimeoutSec){
    var to = this.SelPage+1;   
    if(to>this.Pages) to=0;        
    this.ListScrollDirect(to);
    this.timeout = setTimeout('javascript:Slider'+this.RefID+'.AutoScroll();', this.TimeoutSec);
  }      
}


Slider.effect.prototype.timeReset = function(){
  if(this.TimeoutSec){ 
    clearTimeout(this.timeout);
    this.timeout = setTimeout('javascript:Slider'+this.RefID+'.AutoScroll();', this.TimeoutSec);
  }
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
var ElemXPage = 1;

var ScrollDiv = document.getElementById('ListScroll');
ScrollDiv.scrollLeft = 0;
var ScrollStep = Number (ScrollDiv.style.width.replace('px',''));

var Pos;
var PosTo;
var Pages = Math.ceil(n / ElemXPage) - 1;
var SelPage = 0;
var timeout;

//var ListCont = document.getElementById('ListContainer');
ListCont.style.width = ((Pages + 1) * ScrollStep) + "px";

if( document.getElementById('TopTenCounter') ){
	document.getElementById('TopTenCounter').innerHTML =  n + " / " + (Pages + 1);
}

var DotDiv = document.getElementById('PageDots');
//DotDiv.style.marginLeft = 560 - (Pages * 20);
DotDiv.innerHTML = '<span class="FocusDotSel" onClick="javascript:timeReset(); ListScrollDirect(\'0\')" id="PageDot_0"><img src="../temp/imgs/void.gif" width="11" height="11" title="Clicca" alt="Clicca" border="0"></span>' + "\n";
for(i=1;i<=Pages;i++){
	DotDiv.innerHTML += '<span class="FocusDot" onClick="javascript:timeReset(); ListScrollDirect(\''+i+'\')" id="PageDot_'+i+'"><img src="../temp/imgs/void.gif" width="11" height="11" title="Clicca" alt="Clicca" border="0"></span>' + "\n";
}

function DotChangeClass( To ){		
	document.getElementById('PageDot_' + SelPage).className = 'FocusDot';
	SelPage = To;
	SelPage = Math.max(SelPage, 0);
	SelPage = Math.min(SelPage, Pages);
	document.getElementById('PageDot_' + SelPage).className = 'FocusDotSel';
}

function ListScrollDirect( To ){
	DotChangeClass(To);
	Pos = ScrollDiv.scrollLeft;
	PosTo = Math.min ((To*ScrollStep), ScrollDiv.scrollWidth);		
	ListScrollStart();			
}

function ListScrollStep( dir ){
	DotChangeClass((SelPage + dir));
	Pos = ScrollDiv.scrollLeft;
	PosTo = Math.min (ScrollDiv.scrollLeft+(dir*ScrollStep), ScrollDiv.scrollWidth);
	ListScrollStart();       
}      
                                                                                                
function ListScrollStart(){
	Pos += (PosTo - Pos) / 10;
	ScrollDiv.scrollLeft = Pos;
	
	if( Pos < PosTo+1 && Pos > PosTo-1 ){
		Pos = PosTo;
	} else {
		ScrollDiv.scrollLeft = Pos;
		setTimeout('javascript:ListScrollStart();', 5);
	}               
}

function AutoScroll(){				
	var to = SelPage+1;	

	if(to>Pages) to=0;				
	ListScrollDirect(to);
	timeout = setTimeout(AutoScroll, 5000);
}
timeout = setTimeout(AutoScroll, 5000);

function timeReset(){
	clearTimeout(timeout);
	timeout = setTimeout(AutoScroll, 5000);
}
*/

