/*
	filename: scrollDiv.js
	project: youmark.it
	
	20081104 gag_cosmo: parametrizzata la funzione per lo scroll delle news
	20081104 gag-cosmo: usato per lo scroll della sezione le ultime del mercato e offerte di lavoro
	20081104 gag-cosmo: creato 
*/
var scrollDiv_off;
var hDiv_off;
var tClip_off;
var bClip_off;
var wClip_off;
var interval_off;
var topPos_off = 0;

function initScroller_off(id, controls_id) {
	//alert(id + " " + controls_id);
	scrollDiv_off = document.getElementById(id);   
    var margin_off = parseInt(scrollDiv_off.offsetTop);
    
    var scrollDiv__controls = document.getElementById(controls_id);

    /* Style per il div interno (testo) */
    scrollDiv_off.style.width    = (scrollDiv_off.parentNode.offsetWidth - (margin_off * 2)) - 24 + 'px';
    scrollDiv_off.style.height   = 'auto';
    scrollDiv_off.style.overflow = 'hidden';
    
    /* Style per il div esterno (contenitore) */
    scrollDiv_off.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_off  = scrollDiv_off.offsetHeight;

    tClip_off = 0;   
    wClip_off = scrollDiv_off.parentNode.offsetWidth - (margin_off * 2);
    bClip_off = scrollDiv_off.parentNode.offsetHeight - (margin_off * 2);

    scrollDiv_off.style.clip = 'rect('+ tClip_off +'px,'+ wClip_off +'px,'+ bClip_off +'px,0)';   
    // alert("tClip:"+tClip+"\nwClip:"+wClip+"\nbClip:"+bClip+"\n");
}

function scroll_off(scrollBy, time) {
	tClip_off += scrollBy;
    bClip_off += scrollBy;
    topPos_off -= scrollBy;

    
    if (tClip_off < 0 || bClip_off > hDiv_off) {
        tClip_off -= scrollBy;
        bClip_off -= scrollBy;
        topPos_off += scrollBy;    
    }
    
    
    scrollDiv_off.style.clip = 'rect('+ tClip_off +'px, '+ wClip_off +'px, '+ bClip_off +'px, 0)';   
    scrollDiv_off.style.top = topPos_off + 'px';    
    interval_off = setTimeout('scroll_off('+ scrollBy +', '+ time +')', time);
}

function stopScroll_off() {
    if (interval_off) clearTimeout(interval_off);
}