var ie = /MSIE/.test(navigator.userAgent);
var moz = !ie && navigator.product == "Gecko";

var idDiv;
var ancho;
var alto;
var delay = 20;
var left;
var toop;
var clipLeft;
var clipRight;
var clipTop;
var clipBottom;
var time;

function initScroll(valIdDiv, valIdPos, valAncho, valAlto) {
    idDiv = valIdDiv;
    ancho = valAncho;
    alto  = valAlto;
    moverObj(valIdDiv, valIdPos);
    obj = document.getElementById(idDiv);
    clipLeft = 0;
    clipTop = 0;
    clipRight = ancho;
    clipBottom = alto;
    obj.style.clip = 'rect(0px,' + ancho + 'px,' + alto + 'px,0px)';
}

function  moverObj(valIdDiv, valIdPos) {
    obj = document.getElementById(valIdDiv);
    objPos = document.getElementById(valIdPos);
    left = findX(objPos);
    toop  = findY(objPos);
    obj.style.left = left + 'px';
    obj.style.top = toop + 'px';
    if (moz) {
//        obj.style.top = (parseInt(obj.style.top) - parseInt(objPos.style.height)) + 'px' ;
    }
}

function scrollDch() {
    obj = document.getElementById(idDiv);
    if (clipRight < parseInt(obj.style.width)) {
        clipRight = clipRight + 1;
        clipLeft  = clipLeft  + 1;
        left = left - 1;
        obj.style.clip = 'rect(' + clipTop + 'px,' + clipRight + 'px,' + clipBottom + 'px,' + clipLeft + 'px)';
        obj.style.left = left + 'px';
        time = setTimeout('scrollDch()',delay);
    }
}

function scrollIzq() {
    obj = document.getElementById(idDiv);
    if (clipLeft > 0) {
        clipRight = clipRight - 1;
        clipLeft  = clipLeft  - 1;
        left = left + 1;
        obj.style.clip = 'rect(' + clipTop + 'px,' + clipRight + 'px,' + clipBottom + 'px,' + clipLeft + 'px)';
        obj.style.left = left + 'px';
        time = setTimeout('scrollIzq()',delay);
    }
}

function stopScroll() {
    if (time) clearTimeout(time);
}

function findX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
        }
    }
    return curleft;
}

function findY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curtop += obj.offsetTop
        }
    }
    return curtop;
}
