// Continuous text Vertical Scroller with stop/start button
// copyright 14th August 2010 by Stephen Chapman
// http://javascript.about.com
// permission to use this Javascript on your web page is granted
// provided that all of the code below in this script (including these
// comments) is used without any alteration
if (typeof  xtvert  === "undefined") {
    var xtvert = {};
}

xtvert.mqr = [];
xtvert.mqTimeout = 20;
xtvert.count = 0;

xtvert.startstopchange = function(m,txt) {
    for (var j=m.length - 1; j > -1; j--) document.getElementById('ss'+m[j].id).value = txt;
};

xtvert.startstop = function(m,n) { };

xtvert.objHeight = function(obj) {
    if(obj.offsetHeight) return  obj.offsetHeight;
    if (obj.clip) return obj.clip.height;
    return 0;
};

xtvert.mq = function(id, timeout){
    xtvert.mqTimeout = timeout;
    this.mqo = document.getElementById(id);
    var ht = xtvert.objHeight(this.mqo.getElementsByTagName('div')[0]) + 8;
    var fulht = xtvert.objHeight(this.mqo);
    var txt = this.mqo.getElementsByTagName('div')[0].innerHTML;
    this.mqo.innerHTML = '';
    var wid = this.mqo.style.width;
    this.mqo.onmouseout=function() {
        xtvert.mqRotate(xtvert.mqr);//startstopchange(mqr,'STOP');
    };
    this.mqo.onmouseover=function() {
        clearTimeout(xtvert.mqr[0].TO);
    //startstopchange(mqr,'START');
    };
    this.mqo.ary=[];
    var maxw = Math.ceil(fulht/ht)+1;
    for (var i=0;i < maxw;i++){
        this.mqo.ary[i]=document.createElement('div');
        this.mqo.ary[i].innerHTML = txt;
        this.mqo.ary[i].style.position = 'absolute';
        this.mqo.ary[i].style.top = (ht*i)+'px';
        this.mqo.ary[i].style.height = ht+'px';
        this.mqo.ary[i].style.width = wid;
        this.mqo.appendChild(this.mqo.ary[i]);
    }
    xtvert.mqr.push(this.mqo);
};

xtvert.mqRotate = function(mqr){
    if (!xtvert.mqr) return;
    
    for (var j = xtvert.mqr.length - 1; j > -1; j--) {
        maxa = xtvert.mqr[j].ary.length;
        for (var i = 0; i < maxa;i++){
            var x = xtvert.mqr[j].ary[i].style;
            x.top=(parseInt(x.top,10)-1)+'px';
        }
        var y = xtvert.mqr[j].ary[0].style;
        if (parseInt(y.top,10)+parseInt(y.height,10)<0) {
            var z = xtvert.mqr[j].ary.shift();
            z.style.top = (parseInt(z.style.top) + parseInt(z.style.height)*maxa) + 'px';
            xtvert.mqr[j].ary.push(z);
        }
    }
    xtvert.mqr[0].TO=setTimeout('xtvert.mqRotate(xtvert.mqr)',xtvert.mqTimeout);
}

xtvert.registerInstance = function(id, timeout) {
    new xtvert.mq(id, timeout);
    xtvert.count++;
    if (xtvert.count == 1) {
        $(window).load(function() {xtvert.mqRotate(xtvert.mqr)})
    }
};
