// <![CDATA[

var scrollDiv;
var hDiv;
var tClip;
var bClip;
var wClip;
var interval;
var topPos = 0;
var i = 0;
var time = 2;
var nej = 0;


function initScroller(id) {
    scrollDiv = document.getElementById(id);   
    var margin = parseInt(scrollDiv.offsetTop);
    
    //var scrollDiv__controls = document.getElementById(id + '__controls');

    /* Style per il div interno (testo) */
    scrollDiv.style.width    = (scrollDiv.parentNode.offsetWidth - (margin * 2));
    scrollDiv.style.height   = 'auto';
    scrollDiv.style.overflow = 'hidden';
    
    /* Style per il div esterno (contenitore) */
    scrollDiv.parentNode.style.overflow = 'hidden';
    
    /* Style per il div con i controlli (testo) */
    //scrollDiv__controls.style.display = 'block';  


    /* Impostazioni per visualizzare la parte di testo superiore */
    hDiv  = scrollDiv.offsetHeight;

    tClip = 0;   
    wClip_init = scrollDiv.parentNode.offsetWidth - (margin * 2);
    bClip_init = scrollDiv.parentNode.offsetHeight - (margin * 2);
	wClip=wClip_init;
	bClip=bClip_init;
	var hFrame=	scrollDiv.parentNode.offsetHeight-20;
    scrollDiv.style.clip = 'rect('+ tClip +'px,'+ wClip +'px,'+ bClip +'px,0)';   
    //alert("tClip:"+tClip+"\nwClip:"+wClip+"\nbClip:"+bClip+"\n");
}
function skrolla(steps){
 i++;
//document.formen.texten.value=document.formen.texten.value +tClip+": ";
 if(i>Math.abs(steps) || nej==1){stopScroll(); i=0;nej=0;}else{scroll(Math.round(400/steps));} 

}


function scroll(scrollBy) {
	
    tClip += scrollBy;
    bClip += scrollBy;
    topPos -= scrollBy;

    if (tClip < 0 || bClip > hDiv) {
        nej=1;
		tClip -= scrollBy;
        bClip -= scrollBy;
        topPos += scrollBy;    
    }
    
    scrollDiv.style.clip = 'rect('+ tClip +'px, '+ wClip +'px, '+ bClip +'px, 0)';   
    scrollDiv.style.top = topPos + 'px';
    interval = setTimeout('skrolla('+ 400/scrollBy +')', time);

}

function stopScroll() {
	//alert(i);
    if (interval) clearTimeout(interval);
}

// ]]>
