﻿
var mbInitialized = false;	//indica se inizializzato
var mbLoop = false;			//indica se attualmente in loop
var mBrowser;				//proprietà del browser corrente
var miSpeed = .3;			//velocità e direzione di scorrimento di default
							//se positiva scorre in SU se negativa scorre in GIU
							//0=fermo

//inizializza le variabili e crea gli oggetti virtuali per lo scroll
function ScrollVertical(divContainerName, divContentName, yStart, speed)
{
	var yStartInt = yStart ? yStart : 0;	//posizione d'inizio del testo nel DIV
	var speedInt = speed ? speed : miSpeed;	//velocità e direzione di scorrimento

	mBrowser = new VerifyCompatibleBrowser();
    objContainer = new ConstructObject(divContainerName);
    objScroller = new ConstructObject(divContentName, divContainerName);
    objScroller.MoveArea(0, yStartInt);
    objContainer.css.visibility = "visible";
    objScroller.css.visibility = "visible";

    mbInitialized = true;

    ScrollStart(speedInt);
}

//esegue lo step iniziale dello scroll alla velocità e direzione indicata
function ScrollStart(speed)
{
	if (!mbInitialized ) return;

	if (speed) miSpeed = speed;	//salva la velocità se la passo altrimenti usa quella impostata originalmente

	mbLoop = true;		//innesca il loop
	if (miSpeed > 0) {
		objScroller.MoveDown(miSpeed);
	}
	else {
		objScroller.MoveUp(miSpeed);
	}
}

//esegue lo step iniziale dello scroll alla velocità e direzione indicata
function ScrollStop()
{
	if (!mbInitialized) return;

	mbLoop = false;		//ferma il loop
}

//estrae dal broswer i parametri necessari a stabilire la compatibilità
function VerifyCompatibleBrowser()
{
    this.ver = navigator.appVersion;
    this.dom = document.getElementById;
    this.ie5 = (this.ver.indexOf("MSIE 5") > -1 && this.dom);
    this.ie4 = (document.all && !this.dom);
    this.ns5 = (this.dom && parseInt(this.ver) >= 5);
    this.ns4 = (document.layers && !this.dom);
    this.bw = (this.ie5 || this.ie4 || this.ns4 || this.ns5);
    return this;
}

//costruisce gli oggetti virtuali per effettuare lo scrolling

function ConstructObject(div1Name, div2name)
{
    var divIntName = (!div2name) ? "" : "document.container.left_col." + div2name + ".";
    this.el = mBrowser.dom ? document.getElementById(div1Name) : mBrowser.ie4 ? document.all[div1Name] : mBrowser.ns4 ? eval(divIntName + "document.container.left_col." + div1Name) : 0;
    this.css = mBrowser.dom ? document.getElementById(div1Name).style : mBrowser.ie4 ? document.all[div1Name].style : mBrowser.ns4 ? eval(nest + "document.container.left_col." + div1Name) : 0;
    this.scrollHeight = mBrowser.ns4 ? this.css.document.height : this.el.offsetHeight;
    this.clipHeight = mBrowser.ns4 ? this.css.clip.height : this.el.offsetHeight;
    this.MoveUp = MoveAreaUp;
    this.MoveDown = MoveAreaDown;
    this.MoveArea = MoveArea;
    this.obj  =  div1Name + "Object";
    eval(this.obj + " = this");

    return this;
}

//sposta l'area e la fissa alle coordinate indicate
function MoveArea(x, y)
{
	if (!mbInitialized || !mbLoop) return;

    this.x = x;
    this.y = y;

    this.css.left = this.x+'px';
    this.css.top = this.y+'px';
}

//scroll in GIU
function MoveAreaDown(move)
{

	if (!mbInitialized || !mbLoop) return;

	if (this.y > -this.scrollHeight) {

    	this.MoveArea(0, this.y - move);
	}
	else {
		this.MoveArea(0, objContainer.clipHeight);
	}
	setTimeout(this.obj + ".MoveDown( " + move + ") ", miSpeed);
}

//scroll in SU
function MoveAreaUp(move)
{
	if (!mbInitialized || !mbLoop) return;
	if (this.y < 0) {
		this.MoveArea(0, this.y + move);
		setTimeout(this.obj + ".MoveUp( " + move + " )", miSpeed);
	}
}

//-->
