/**
 * Funkcja tworząca dla zawartości 'content' funkcjonalność suwaka
 * obsługiwanego elementem 'draggable'
 *
 * UWAGA! Wymaga dołączonej biblioteki 'DOMready_utils.js'
 *
 * tworzenie:
 * 
 * var nazwaScrolla = new verticalScroll($('id_diva_z_zawartością'), $('id_elementu_draggable')); 
 * [ gdzie $() to alias dla document.getElementById() ]
 */
function verticalScroll(content, draggable) {
	return false;
	
	var wys, poz;
    var m	= this;
    var tresc = content;
    var gala = draggable;
    
    var zeroGala = tresc.parentNode.offsetTop + 5, poczMyszy, pozPocz, czyWogole = !0;
    gala.onmousedown = drag;
    if (document.addEventListener) 
        tresc.addEventListener('DOMMouseScroll', wheel, false);
    tresc.onmousewheel = wheel;

    m.reset = function(){
        wys = {
            kont: tresc.parentNode.offsetHeight,
            tresc: tresc.offsetHeight - tresc.parentNode.offsetHeight,
            rynna: tresc.parentNode.offsetHeight - gala.offsetHeight - 0,
            gala: gala.offsetHeight
        }
        poz = {
        	tresc: parseInt(tresc.style.top),
			gala: -1*(Math.round(parseInt(tresc.style.top)*(wys.rynna))/(tresc.offsetHeight - tresc.parentNode.offsetHeight))
        }
        
        czyWogole = true;
        czyWogole = (tresc.offsetHeight - parseInt(tresc.parentNode.style.height) < 0)?false:true;
        
        if(window.newFAQset) {
	        poz.tresc = 0;
			poz.gala = 0;
			
			window.newFAQset = false;
        }
        ustaw('g');
        if (wys.tresc <= 0) 
		{
            czyWogole = false;
			draggable.style.display = 'none';
		}
        else 
		{
            czyWogole = true;
			draggable.style.display = 'block';
		}
        gala.onmousedown = drag;
    }
    
    function ustaw(co){
        if (!czyWogole) 
            return;
        if (co == 't') {
            if (poz.tresc > 0) 
                poz.tresc = 0;
            if (poz.tresc < -wys.tresc) 
                poz.tresc = -wys.tresc;
            tresc.style.top = poz.tresc + 'px';
            gala.style.top = zeroGala + (poz.gala = -poz.tresc / wys.tresc * wys.rynna) + 'px'
        }
        else {
            if (poz.gala < 0) 
                poz.gala = 0;
            if (poz.gala > wys.rynna) 
                poz.gala = wys.rynna;
            gala.style.top = zeroGala + poz.gala + 'px';
            tresc.style.top = (poz.tresc = -poz.gala / wys.rynna * wys.tresc) + 'px';
        }
    }
    function drag(e){
        if (!czyWogole) 
            if (wys.tresc > 0) 
                czyWogole = true;
        if (!czyWogole) 
            return false;
	    poczMyszy = utils.pozMyszy(e).t;
        pozPocz = gala.offsetTop - zeroGala;
        document.onmousemove = move;
        document.onmouseup = drop;
        return false;
    }
    function move(e){
        poz.gala = pozPocz + utils.pozMyszy(e).t - poczMyszy;
        ustaw('g');
        return false;
    }
    function drop(){
        document.onmousemove = document.onmouseup = null;
    }
    function wheel(e){
        e = e || event;
        var delta;
        if (e.wheelDelta) 
            delta = -e.wheelDelta / 120
        else 
            if (e.detail) 
                delta = e.detail / 3
        poz.tresc -= delta * 25;
        ustaw('t');
        
        e.returnValue = false;
        if (e.preventDefault) 
            e.preventDefault();
    }
    window.newFAQset = true;
    m.reset();
}
