﻿// JavaScript Document

var StopScrollDx = true;    //vero se ci spostiamo a destra
var StopScrollSx = false;   //vero se ci spostiamo a sinistra
var shift = 0;              //indica di quanto ci spostiamo
var direction = 0;          //se 0 vado a dx, se 1 vado a sx
var OneTime = false;        //parametro di supporto
var altAutoScroll=true;  //parametro per stoppare l'autoscroll
var pos_gallery = 0;


function startAutoScroll(id) {
    var wBox1 = document.getElementById("motioncontainer").offsetWidth;
    var wContent1 = document.getElementById("motiongallery").offsetWidth;
    var wDiff1 = wContent1 - wBox1;
    scorri(wBox1,wContent1,wDiff1,id);
}


function scorri(wBox1,wContent1,wDiff1,id){

    if(altAutoScroll==true){
        if (direction == 0) {
            shift = shift - 1;
        } else {
            shift = shift + 1;
        }
        document.getElementById(id).style.left = shift + "px";
        pos_gallery = shift;
        
        OneTime = true
        if ((shift <= -wDiff1) && (direction == 0)) {
            StopScrollDx = false;
            StopScrollSx = true;
            direction = 1;
            OneTime = false;
         } else if ((shift >= 0) && (direction == 1)) {
            StopScrollDx = true;
            StopScrollSx = false;
            direction = 0;
            OneTime = false;
        }
        document.getElementById("ctl00_body_posizione_gallery").value = pos_gallery;
    }
        setTimeout("startAutoScroll('motiongallery')", 35);
}

function stopMotion() {
    altAutoScroll = false;
}

function startMotion() {
    altAutoScroll = true;
}
