function scrollTexto(box, altura, dividido, resto_mov){
    this.cont_scroll = null;
    this.link_up = null;
    this.link_down = null;
    this.array_mov = new Array();
    this.mov_total = 0;
    this.click = 0;
    this.time_out = null;
    this.pos_actual = null;
    this.pos_alcanzar = null;
    this.start = null;
    var _this = this;

    this.anyadirEvento = function(elemento,evento,funcion){
	if(elemento.addEventListener)return elemento.addEventListener(evento,funcion,false);
        if(elemento.attachEvent)return elemento.attachEvent("on"+evento,funcion);
    }
    this.eliminarEvento = function(evento){
        if(window.event){
            window.event.cancelBubble=true;
            window.event.returnValue=false;
            return
        }
        if(evento.preventDefault&&evento.stopPropagation){
            evento.preventDefault();
            evento.stopPropagation();
        }
    }
    this.moverScoll = function(){
        _this.time_out = setTimeout(function(){
            if(!_this.nextStep()){
                clearTimeout(_this.time_out);
                _this.rellamada(1);
                return;
            }
            _this.rellamada(_this.nextStep());
            _this.moverScoll();
        },13)
    }
    this.init = function(){_this.anyadirEvento(window,"load",_this.load)}
    this.load = function(){
        _this.eliminarEvento(this);
        var aux_divs = document.getElementById(box).getElementsByTagName('div');
        for(var i = 0; i < aux_divs.length; i++){
            if(aux_divs[i].className.match(/cont_scroll/)){
                _this.cont_scroll = aux_divs[i];
                var aux_items = null;
                aux_items = _this.cont_scroll.getElementsByTagName('div');
                for(var j = 0; j < aux_items.length; j++){
                    if(aux_items[j].className.match(/item/)){
                        ++_this.mov_total;
                    }
                }
            }
            if(aux_divs[i].className.match(/botonera_scroll/)){
                _this.link_up = aux_divs[i].getElementsByTagName('a')[0]
                _this.link_down = aux_divs[i].getElementsByTagName('a')[1]
            }
        }
        if(dividido != null){
            _this.mov_total = Math.ceil(_this.mov_total / dividido) - resto_mov;
        }
        else{
            _this.mov_total = 2;
        }
        for(i = 0; i < _this.mov_total; i++){
            _this.array_mov.push(-altura * i);
        }
        _this.link_up.onclick = function(){
            /*if(_this.click == _this.mov_total-1){
                _this.click = _this.mov_total-1;
                return;
            }*/
            if(_this.click == 0){
                _this.click = 0;
                return;
            }
            _this.eliminarEvento(this);
            clearTimeout(_this.time_out);
            _this.pos_actual = _this.cont_scroll.offsetTop;
            //_this.pos_alcanzar = _this.array_mov[++_this.click];
            _this.pos_alcanzar = _this.array_mov[--_this.click];
            _this.start = new Date().getTime();
            _this.moverScoll();
        }
        _this.link_down.onclick = function(){
            /*if(_this.click == 0){
                _this.click = 0;
                return;
            }*/
            if(_this.click == _this.mov_total-1){
                _this.click = _this.mov_total-1;
                return;
            }
            _this.eliminarEvento(this);
            clearTimeout(_this.time_out);
            _this.pos_actual = _this.cont_scroll.offsetTop;
            //_this.pos_alcanzar = _this.array_mov[--_this.click];
            _this.pos_alcanzar = _this.array_mov[++_this.click];
            _this.start = new Date().getTime();
            _this.moverScoll();
        }
    }
    this.rellamada = function(p){
        var mov_scroll = _this.pos_actual + ((_this.pos_alcanzar - _this.pos_actual)*p);
        _this.cont_scroll.style.top = mov_scroll +'px';
    }
    this.nextStep = function(){
        var now = new Date().getTime();
        if((now - _this.start)>1000){
            return false;
        }
        return _this.easing((now - _this.start+.001)/1000);
    }
    this.easing = function(p){
        return (Math.pow((p-1), 3) +1);
    }
}
var scroll = new scrollTexto('trb_ordenacion', 453, 2, 0);
scroll.init();
scroll = null;
scroll = new scrollTexto('trb_ingenieria', 453, 2, 0);
scroll.init();
scroll = null;
scroll = new scrollTexto('trb_arquitectura', 453, 2, 0);
scroll.init();
scroll = null;
scroll = new scrollTexto('trb_tecnologia', 453, 2, 0);
scroll.init();
scroll = null;
scroll = new scrollTexto('cont_clientes', 360, null, 0);
scroll.init();
scroll = null;
scroll = new scrollTexto('cont_comunicacion', 440, 2, 0);
scroll.init();
scroll = null;
scroll = new scrollTexto('cont_enlaces', 110, 1, 3);
scroll.init();
scroll = null;
scroll = new scrollTexto('scroll_estudio', 360, null, 0);
scroll.init();
scroll = null;scroll = new scrollTexto('scroll_estudio_eusk', 90, null, 0);
scroll.init();
scroll = null;
