var num=0;
function scrollup()
{
if (listo) {
        if (nav=="ie") {
                if (texto.style.pixelTop < limitesuptexto) texto.style.pixelTop += brusquedad;

                        num += brusquedad * longdelscroll / (texto.scrollHeight-limiteinftexto); // Desplz. proporcional respecto el scroll
                        if (num >= 1) {
                                dragitem.ypos -= parseInt(num);
                                num -= parseInt(num);
                        }
                        if (dragitem.ypos < limitesupscroll) dragitem.ypos = limitesupscroll;    // Limites del scroller
                        else if (dragitem.ypos > limiteinfscroll) dragitem.ypos = limiteinfscroll;
                        dragitem.pixelTop = dragitem.ypos;
                        anty=dragitem.ypos
        }
        else {
                if (document.ventana.document.texto.top < limitesuptexto) document.ventana.document.texto.top += brusquedad;

                num += brusquedad * longdelscroll / (document.ventana.document.texto.document.height-limiteinftexto);
                if (num >= 1) {
                        dragitem.ypos -= parseInt(num);
                        num -= parseInt(num);
                }
                if (dragitem.ypos < limitesupscroll) dragitem.ypos = limitesupscroll;   // Limites del scroller
                else if (dragitem.ypos > limiteinfscroll) dragitem.ypos = limiteinfscroll;
                dragitem.top = dragitem.ypos;
                anty=dragitem.ypos
        }
        temps=setTimeout('scrollup()',lentitud);
}
}

function scrolldown()
{
if (listo) {
        if (nav=="ie") {
                if (texto.style.pixelTop > -texto.scrollHeight+limiteinftexto) texto.style.pixelTop -= brusquedad;
                        num += brusquedad * longdelscroll / (texto.scrollHeight-limiteinftexto);
                        if (num >= 1) {
                                dragitem.ypos += parseInt(num);
                                num -= parseInt(num);
                        }
                        if (dragitem.ypos < limitesupscroll) dragitem.ypos = limitesupscroll;     // Limites del scroller
                        else if (dragitem.ypos > limiteinfscroll) dragitem.ypos = limiteinfscroll;
                        dragitem.pixelTop = dragitem.ypos;
                        anty=dragitem.ypos
        }
        else {
                if (document.ventana.document.texto.top > -document.ventana.document.texto.document.height+limiteinftexto) document.ventana.document.texto.top -= brusquedad;
                        num += brusquedad * longdelscroll / (document.ventana.document.texto.document.height-limiteinftexto);
                        if (num >= 1) {
                                dragitem.ypos += parseInt(num);
                                num -= parseInt(num);
                        }
                        if (dragitem.ypos < limitesupscroll) dragitem.ypos = limitesupscroll;    // Limites del scroller
                        else if (dragitem.ypos > limiteinfscroll) dragitem.ypos = limiteinfscroll;
                        dragitem.top = dragitem.ypos;
                        anty=dragitem.ypos
        }
        temps=setTimeout('scrolldown()',lentitud);
}
}

function scrolltop()
{
	dragitem.ypos = limitesupscroll;
	if (nav=="ie") {
		texto.style.pixelTop = limitesuptexto;
		dragitem.pixelTop = dragitem.ypos;
	}
	else {
		document.ventana.document.texto.top = limitesuptexto;
		dragitem.top = dragitem.ypos;
	}
    anty=dragitem.ypos;
}

function checkscroll()
{
	if (nav=="ie") {
		if (texto.scrollHeight>=limiteinftexto+limitesuptexto) {
			veure("dragcss");
			veure("cuparrow");
			veure("cdownarrow");
		}
		else {
			amagar("dragcss");
			amagar("cuparrow");
			amagar("cdownarrow");
		}
	}
	else {
		if (document.ventana.document.texto.document.height>=limiteinftexto+limitesuptexto) {
			veure("dragcss");
			veure("cuparrow");
			veure("cdownarrow");
		}
		else {
			amagar("dragcss");
			amagar("cuparrow");
			amagar("cdownarrow");
		}
	}
}

function inidragndrop() {
        if (nav=="ns") {
                dragitem = document.dragcss;
                dragitem.xpos = dragitem.left;
                dragitem.ypos = dragitem.top;
        }
        else {
                dragitem = document.all.dragcss.style;
                dragitem.xpos = dragitem.pixelLeft;
                dragitem.ypos = dragitem.pixelTop;
        }
        dragndrop = false
                
        document.onmousedown = seleccion
        document.onmousemove = drag
        document.onmouseup = drop
        if (nav=="ns") document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
}

function seleccion(e) {
                if (nav=="ns") {
                        var x=e.pageX; var y=e.pageY
                        if (x>=dragitem.left && x<=dragitem.left+dragitem.clip.width && y>=dragitem.top && y<=dragitem.top+dragitem.clip.height && document.ventana.document.texto.document.height>limiteinftexto) {
                                dragitemy = y-dragitem.ypos

                                anty = dragitem.ypos

                                dragndrop = true

                                return false                            
                        }
                        else if (x>=dragitem.left && x<=dragitem.left+dragitem.clip.width && y>=dragitem.top+dragitem.clip.height && y<=limiteinfscroll-2) {
                                for(i=0;i<brusq_salto;i++) { scrolldown(); clearTimeout(temps); }
                                return false
                        }
                        else if (x>=dragitem.left && x<=dragitem.left+dragitem.clip.width && y>=limitesupscroll+2 && y<=dragitem.top) {
                                for(i=0;i<brusq_salto;i++) { scrollup(); clearTimeout(temps); }
                                return false
                        }
                        else routeEvent(e);
                }
                else {
                        var x=event.x; var y=event.y

                        if (x>=dragitem.pixelLeft && x<=dragitem.pixelLeft+dragitem.pixelWidth && y>=dragitem.pixelTop && y<=dragitem.pixelTop+dragitem.pixelHeight && texto.scrollHeight>limiteinftexto) {
                                dragitemy = y-dragitem.ypos

                                anty = dragitem.ypos

                                dragndrop = true

                                return false                            
                        }
                        else if (x>=dragitem.pixelLeft && x<=dragitem.pixelLeft+dragitem.pixelWidth && y>=dragitem.pixelTop+dragitem.pixelHeight && y<=limiteinfscroll-2) {
                                for(i=0;i<brusq_salto;i++) { scrolldown(); clearTimeout(temps); }
                                return false
                        }
                        else if (x>=dragitem.pixelLeft && x<=dragitem.pixelLeft+dragitem.pixelWidth && y>=limitesupscroll+2 && y<=dragitem.pixelTop) {
                                for(i=0;i<brusq_salto;i++) { scrollup(); clearTimeout(temps); }
                                return false
                        }
                }
return true;
}

function drag(e) {
        if (nav=="ns") {
                var x=e.pageX; var y=e.pageY

                if (dragndrop) {
                        if (y < limitesupscroll || y-dragitemy < limitesupscroll) dragitem.ypos = limitesupscroll;             // Limites del scroller
                        else if (y > limiteinfscroll+10 || y-dragitemy > limiteinfscroll) dragitem.ypos = limiteinfscroll;
                        else dragitem.ypos = y-dragitemy
                        dragitem.top = dragitem.ypos;
                        // Incr. texto = ( Incr. scroll * (Long. texto - Long. ventana - 10 por si las moscas) / Long scroll)
                        if (dragitem.ypos == limitesupscroll) document.ventana.document.texto.top = 2;
                        else if (dragitem.ypos == limiteinfscroll) document.ventana.document.texto.top = -document.ventana.document.texto.document.height+limiteinftexto-10;
                        else {
                                suma = (anty-dragitem.ypos)*(document.ventana.document.texto.document.height-limiteinftexto+30)/longdelscroll;
                                if (suma<0 && suma>-1) suma = -1;
                                if (suma>0 && suma<1) suma = 1;

                                suma = parseInt(suma);

                                document.ventana.document.texto.top += suma;

                        }
                        anty=dragitem.ypos

                        return true;
                }
        }
        else {
                var x=event.x; var y=event.y

                if (dragndrop) {
                        if (y < limitesupscroll || y-dragitemy < limitesupscroll) dragitem.ypos = limitesupscroll;

                        else if (y > limiteinfscroll+10 || y-dragitemy > limiteinfscroll) dragitem.ypos = limiteinfscroll;
                        else dragitem.ypos = y-dragitemy
                        dragitem.pixelTop = dragitem.ypos;
                        if (dragitem.ypos == limitesupscroll) texto.style.pixelTop = 2;
                        else if (dragitem.ypos == limiteinfscroll) texto.style.pixelTop = -texto.scrollHeight+limiteinftexto-10;
                        else texto.style.pixelTop += parseInt((anty-dragitem.ypos)*(texto.scrollHeight-limiteinftexto+20)/longdelscroll);
                        anty=dragitem.ypos
                        return false
                }
        }
}

function drop(e) {
        if (nav=="ns") {var x=e.pageX; var y=e.pageY}
        else {var x=event.x; var y=event.y+document.body.scrollTop}
        dragndrop = false
        if (nav=="ns") routeEvent(e);
		return true;
}
