var iterations = 3;

function opacityElement(element, optStep, delay, callback) {
    var opacity = setInterval(function() {
        element.style.opacity=parseFloat(element.style.opacity)+optStep;
        if ((element.style.opacity >= 1 && optStep > 0) || (element.style.opacity <= 0 && optStep < 0)) {
            clearInterval(opacity);
            callback();
        }
    }, delay);
}

function startScroll(idClip, idText) {
    setTimeout(function() {
        var divClip = document.getElementById(idClip);
        var divText = document.getElementById(idText);
        var timer = setInterval(function() {
            divClip.scrollTop++;
            if (divClip.scrollTop == (divClip.scrollHeight-divClip.clientHeight)) {
                clearInterval(timer);
                divText.style.opacity=1;
                setTimeout(function() {
                    opacityElement(divText, -0.05, 100, function(){
                        setTimeout(function() {
                            divClip.scrollTop = 0;
                            opacityElement(divText, 0.05, 20, function(){
                                if (iterations > 1) {
                                    iterations--;
                                    startScroll(idClip, idText);
                                }
                            });
                        }, 100);
                    });
                }, 3000);
            }
        }, 25);
        divClip.onmouseover=function(){clearInterval(timer)};
    }, 5000);
}