/*
 * vtScrool - Scroolit
 * Copyright (C) 2008-2009 Vista Tecnologie www.vista.it
 * 
 * Licensed under the terms of the GNU Lesser General Public License:
 * 		http://www.opensource.org/licenses/lgpl-license.php
 * 
 * For further information visit:
 * 		http://www.vista.it/ 
 * 
 */
var tmr = null;
var dir = 1;
var spd = 1;
var x = 0;
var scrollTime = 0;

function scrollInit(id,speed) {
        spd = speed || 10;
        document.getElementById(id+"_freccie").style.display = 'block';
        document.getElementById(id+"_freccia-su").onmouseover = startScrollDown;
        document.getElementById(id+"_freccia-giu").onmouseover = startScrollUp;
        document.getElementById(id+"_freccia-su").onmouseout = stopScroll;
        document.getElementById(id+"_freccia-giu").onmouseout = stopScroll;
        //this.gallTn = document.getElementById(id+"-scroll");   
}
function scrollInitX(id,speed) {
        spd = speed || 10;
        document.getElementById(id+"_freccie").style.display = 'block';
        document.getElementById(id+"_freccia-sx").onmouseover = startScrollLeft;
        document.getElementById(id+"_freccia-dx").onmouseover = startScrollRight;
        document.getElementById(id+"_freccia-dx").onmouseout = stopScroll;
        document.getElementById(id+"_freccia-sx").onmouseout = stopScroll;
        //this.gallTn = document.getElementById(id+"-scroll");   
}

function startScrollUp(e) {
    //document.getElementById("div-gall-freccia-giu").style.backgroundImage = "url(imgsys/scroll-gall-giu_on.png)";
	if (!e) var e = window.event;
	var tgt = null;
	if (e.target) {
		tgt = e.target;
	} else {
		tgt = e.srcElement;
	}
    var a = tgt.id.indexOf('_');
    var b = tgt.id.substr(0,a);
	dir = -1;
	//scrollTime = 0;
    tmr = setInterval("scroll(\'"+b+ "\')",50);   
	return false;
}
function startScrollDown(e) {
    //document.getElementById("div-gall-freccia-su").style.backgroundImage = "url(imgsys/scroll-gall-su_on.png)";
	if (!e) var e = window.event;
	var tgt = null;
	if (e.target) {
		tgt = e.target;
	} else {
		tgt = e.srcElement;
	}
    var a = tgt.id.indexOf('_');
    var b = tgt.id.substr(0,a);
	dir = 1;
	//scrollTime = 0;
	tmr = setInterval("scroll(\'"+b+ "\')",50);
	return false;
}
function startScrollRight(e) {
    //document.getElementById("div-gall-freccia-giu").style.backgroundImage = "url(imgsys/scroll-gall-giu_on.png)";
    if (!e) var e = window.event;
    var tgt = null;
    if (e.target) {
        tgt = e.target;
    } else {
        tgt = e.srcElement;
    }
    var a = tgt.id.indexOf('_');
    var b = tgt.id.substr(0,a);
    dir = -1;
    //scrollTime = 0;
    tmr = setInterval("scrollX(\'"+b+ "\')",50);   
    return false;
}
function startScrollLeft(e) {
    //document.getElementById("div-gall-freccia-su").style.backgroundImage = "url(imgsys/scroll-gall-su_on.png)";
    if (!e) var e = window.event;
    var tgt = null;
    if (e.target) {
        tgt = e.target;
    } else {
        tgt = e.srcElement;
    }
    var a = tgt.id.indexOf('_');
    var b = tgt.id.substr(0,a);
    dir = 1;
    //scrollTime = 0;
    tmr = setInterval("scrollX(\'"+b+ "\')",50);
    return false;
}
function scroll(id) {
	var gallTn = document.getElementById(id+"_scroll");
	var pos = gallTn.scrollTop;
	if (gallTn.style.top!="") {
		pos = parseInt(gallTn.style.top);
	}
	var hgt = gallTn.offsetHeight;
	var parHgt = gallTn.parentNode.clientHeight;
	if ((hgt-parHgt)>10) {
		if (((pos<0) && (pos>(parHgt-hgt))) || ((pos==0) && (dir==-1)) || ((pos==(parHgt-hgt)) && (dir==1))) {
			x += dir*spd;
			gallTn.style.top = x+"px";
		} else {
			clearInterval(tmr);
			if (pos>0) {
				x = 0;
				gallTn.style.top = x+"px";
			}
			if (pos<(parHgt-hgt)) {
				x = parHgt-hgt;
				gallTn.style.top = x+"px";
			}
		}
	}
}
function scrollX(id) {
    var gallTn = document.getElementById(id+"_scroll");
    var pos = gallTn.scrollLeft;
    if (gallTn.style.left!="") {
        pos = parseInt(gallTn.style.left);
    }
    var wid = gallTn.offsetWidth;
    var parWid = gallTn.parentNode.clientHeight;
    if ((wid-parWid)>10) {
        if (((pos<0) && (pos>(parWid-wid))) || ((pos==0) && (dir==-1)) || ((pos==(parWid-wid)) && (dir==1))) {
            x += dir*spd;
            gallTn.style.left = x+"px";
        } else {
            clearInterval(tmr);
            if (pos>0) {
                x = 0;
                gallTn.style.left = x+"px";
            }
            if (pos<(parWid-wid)) {
                x = parWid-wid;
                gallTn.style.left = x+"px";
            }
        }
    }
}
function stopScroll(e) {
    //document.getElementById("div-gall-freccia-su").style.backgroundImage = "url(imgsys/scroll-gall-su.png)";
    //document.getElementById("div-gall-freccia-giu").style.backgroundImage = "url(imgsys/scroll-gall-giu.png)";
    if (!e) var e = window.event;
    var tgt = null;
    if (e.target) {
        tgt = e.target;
    } else {
        tgt = e.srcElement;
    }
    clearInterval(tmr);
    return false;
}