//JS : 连续滚动
//参数: obj:物件ID[, isVertical:是否垂直方向[, offset:偏移量[, speed:上升速度[, delay:推迟时间]]]]
function startMarquee(obj, isVertical, offset, speed, delay) { 
    if(!chkObject(obj)) return;
    var p = false;
    var t;
    var o = document.createElement('div'), t = document.getElementById(obj);
    var i = t.innerHTML;
    isVertical = chkObject(isVertical) ? isVertical : true;
    speed = chkObject(speed) ? speed : 20;
    delay = chkObject(delay) ? delay : 1500;
    o.innerHTML = i;
    t.innerHTML = ''; 
    t.appendChild(o);  
    if(isVertical) { 
        offset = chkObject(offset) ? offset : parseInt(t.style.lineHeight);
        offset = chkObject(offset) ? offset : parseInt(t.style.height);
        if(o.offsetHeight <= t.offsetHeight) return;
        o.style.marginTop = 0;
        o.innerHTML += '<div>' + i + '</div>';
    } else {
        offset = chkObject(offset) ? offset : parseInt(t.style.width);
        if(o.offsetWidth <= t.offsetWidth) return;
        o.style.marginLeft = 0;
        o.style.whiteSpace = 'nowrap';
        o.style.overFlow = 'hidden';
        o.innerHTML += i;
    }
    t = null;
    i = null; 
    o.onmouseover = function() {p = true;}
    o.onmouseout = function() {p = false;}
    
    function chkObject(obj) {
        if(typeof(obj) == 'undefined' || (typeof(obj) == 'Number' && obj == 0))
            return false;
        return true;
    }

    function start(){
        t = setInterval(scrolling, speed);
        if(!isVertical) {
            if(!p) o.style.marginLeft = parseInt(o.style.marginLeft) - 1 + 'px';
        } else {
            if(!p) o.style.marginTop = parseInt(o.style.marginTop) - 1 + 'px';
        }
    }

    function scrolling(){
        if(!isVertical && parseInt(o.offsetLeft) % offset != 0) { 
            o.style.marginLeft = parseInt(o.style.marginLeft) - 1 + 'px';
            if(Math.abs(parseInt(o.style.marginLeft)) >= o.scrollWidth / 2) o.style.marginLeft = 0;
        } else if(isVertical && parseInt(o.style.marginTop) % offset != 0) {
            o.style.marginTop = parseInt(o.style.marginTop) - 1 + 'px';
            if(Math.abs(parseInt(o.style.marginTop)) >= o.scrollHeight / 2) o.style.marginTop = 0; 
        } else { 
            clearInterval(t);
            setTimeout(start, delay);
        }
    }
    setTimeout(start, delay);
}