﻿// Funzioni per lo scorrimento del banner di testata.
// Autore: Vincenzo Pizio
// Data: 6/6/2008

var b_scroll;

function banner_scroll()
{
    b_scroll = this;
    this.pos = 0;
    this.scostamento = 0;
    this.step = 710;
    this.idImmagine = "img";
    this.limite = 7100;
    this.name = "banner_scroll";
    
    banner_scroll.prototype.step_right = function(){
        
        //***************************************************************************
        document.getElementById("fr_sx").style.visibility = 'visible';
        document.getElementById("fr_dx").style.visibility = 'visible';
        //***************************************************************************
    
        if((this.scostamento > (-this.step))&&(this.pos > (-this.limite + this.step)))
        {
            this.pos = this.pos - 10;
            this.scostamento = this.scostamento - 10;
            document.getElementById(this.idImmagine).style.marginLeft = this.pos + "px";
            timer1 = setTimeout("b_scroll.step_right();",1);
        }
        else
        {
            this.scostamento = 0;
            clearTimeout(timer1);
            
            //***************************************************************************
            //Parte aggiuntiva per la gestione delle frecce.
            //***************************************************************************
            if((-this.pos) == (this.limite - this.step))
            {
                document.getElementById("fr_dx").style.visibility = 'hidden';
            }
            if((-this.pos) == 0)
            {
                document.getElementById("fr_sx").style.visibility = 'hidden';
            }
            //***************************************************************************
            //***************************************************************************
        }
    };
    
    banner_scroll.prototype.step_left = function(){
    
        //***************************************************************************
        document.getElementById("fr_sx").style.visibility = 'visible';
        document.getElementById("fr_dx").style.visibility = 'visible';
        //***************************************************************************
    
        if((this.pos < 0)&&(this.scostamento < this.step))
        {
            this.pos = this.pos + 10;
            this.scostamento = this.scostamento + 10;
            document.getElementById(this.idImmagine).style.marginLeft = this.pos + "px";
            timer1 = setTimeout("b_scroll.step_left();",1);
        }
        else
        {
            this.scostamento = 0;
            clearTimeout(timer1);
            
            //***************************************************************************
            //Parte aggiuntiva per la gestione delle frecce.
            //***************************************************************************
            if((-this.pos) == (this.limite - this.step))
            {
                document.getElementById("fr_dx").style.visibility = 'hidden';
            }
            if((-this.pos) == 0)
            {
                document.getElementById("fr_sx").style.visibility = 'hidden';
            }
            //***************************************************************************
            //***************************************************************************
        }
    };
    
    banner_scroll.prototype.goTo_right = function(start){
        if(start < this.limite)
        {
            this.pos = -start;
            document.getElementById(this.idImmagine).style.marginLeft = this.pos + "px";
        }
    };
    
    banner_scroll.prototype.go_right = function(step_original){
    
        //***************************************************************************
        document.getElementById("fr_sx").style.visibility = 'visible';
        document.getElementById("fr_dx").style.visibility = 'visible';
        //***************************************************************************
        if((this.scostamento > (-this.step)))
        {
            this.pos = this.pos - 10;
            this.scostamento = this.scostamento - 10;
            document.getElementById(this.idImmagine).style.marginLeft = this.pos + "px";
            timer1 = setTimeout("b_scroll.go_right(" + step_original + ");",1);
        }
        else
        {
            this.scostamento = 0;
            clearTimeout(timer1);
            
            //***************************************************************************
            //Parte aggiuntiva per la gestione delle frecce.
            //***************************************************************************
            if((-this.pos) == (this.limite - step_original))
            {
                document.getElementById("fr_dx").style.visibility = 'hidden';
            }
            if((-this.pos) == 0)
            {
                document.getElementById("fr_sx").style.visibility = 'hidden';
            }
            //***************************************************************************
            //***************************************************************************
        }
    };
    
    banner_scroll.prototype.go_left = function(step_original){
    
        //***************************************************************************
        document.getElementById("fr_sx").style.visibility = 'visible';
        document.getElementById("fr_dx").style.visibility = 'visible';
        //***************************************************************************
        
        if((this.pos < 0)&&(this.scostamento < (-this.step)))
        {
            this.pos = this.pos + 10;
            this.scostamento = this.scostamento + 10;
            document.getElementById(this.idImmagine).style.marginLeft = this.pos + "px";
            timer1 = setTimeout("b_scroll.go_left(" + step_original + ");",1);
        }
        else
        {
            this.scostamento = 0;
            clearTimeout(timer1);
            
            //***************************************************************************
            //Parte aggiuntiva per la gestione delle frecce.
            //***************************************************************************
            if((-this.pos) == (this.limite - step_original))
            {
                document.getElementById("fr_dx").style.visibility = 'hidden';
            }
            if((-this.pos) == 0)
            {
                document.getElementById("fr_sx").style.visibility = 'hidden';
            }
            //***************************************************************************
            //***************************************************************************
        }
    };
}

