var unitWidth
var rightEdge
function initScroll(len, re) {
    var length = len
    rightEdge = re
    var contents = new Array(length)
    for (i=0;i<length;i++) {
        contents[i] = "news" + i
    }

    myscroll = new ClinkScroll("ENVLOP", contents)
    myscroll.init()
    myscroll.timerOn = true;
    myscroll.scroll()
    return 1
}

function stopScroll() {
    if (myscroll && myscroll != null) myscroll.stop()
}
 
function startScroll() {
    if (myscroll.inited) {
        myscroll.canScroll = true
        myscroll.timerOn = true;
        myscroll.scroll()
     }
}

function Clink_scroll() {
    if (!this.canScroll) return 0
    for (i=0; i<this.length; i++) {
        var obj = this.pop(i) 
        if (obj.x <= -rightEdge) {
           obj.reset(unitWidth)
           this.lastOne = i
        } else {
           obj.moveBy(-1)
        }
    }
//   repeat
    this.timerID = setTimeout(this.obj+".scroll()", this.timeinterval)
    return 1
}

function Clink_stop() {
    this.canScroll = false
    if (this.timerOn) clearTimeout(this.timerID)
    this.timerOn = false
}

function Clink_init() {
    this.doOffSet = (!this.browser._n)
    this.setWidth()
    for (i=0;i<this.length;i++) {
       var mylayer = this.contentLayers[i]
       var content = new Object()
       content = new ClinkLayer(mylayer, this.win)
       this.push(content, i)
    }
    this.canScroll = true
    this.inited = true
}

function setWidth() {
unitWidth = (document.layers) ? window.innerWidth : document.body.clientWidth
}
function ClinkBrowser() {
    this._n = (document.layers)? true:false
    this._ie = (document.all)? true:false
    this._n = (document.layers)? true:false
    this._ie = (document.all)? true:false
    var agt = navigator.userAgent.toLowerCase();
    var ar = new Array();
    ar = agt.split(";")
    var id1 = ar[1].indexOf("e")
    var version = ar[1].substring(id1+1,ar[1].length)
    ar = version.split(".")
    this._major = ar[0]
    this._minor = ar[1]
}

function ClinkScroll(windowLayer, contentLayers) {
    this.browser = new ClinkBrowser()
    this.win = new ClinkLayer(windowLayer, null)
    this.length = contentLayers.length
    this.lastOne = this.length - 1
    this.contentLayers = contentLayers
    this.push = Clink_push
    this.pop = Clink_pop
    this.timeinterval = 20
    this.init = Clink_init
    this.setWidth = setWidth
    this.stop = Clink_stop
    this.scroll = Clink_scroll
    this.canScroll = false
    this.inited = false
    this.obj = (this.browser._n)? windowLayer : eval("windowLayer.style")
    eval(this.obj + "=this")
}

function Clink_push(clink_layer, i) {
    if (i > 6) 
    window.alert('Error: this setup works only for 7 scrolling objects')
    if (i == 0) {
           this.content_0 = clink_layer
    } else if (i == 1) {
           this.content_1 = clink_layer
    } else if (i ==2 ) {
           this.content_2 = clink_layer
    } else if (i == 3) {
           this.content_3 = clink_layer
    } else if (i ==4) {
           this.content_4 = clink_layer
    } else if (i ==5 ) {
           this.content_5 = clink_layer
    } else if (i == 6) {
           this.content_6 = clink_layer
    }
}

function Clink_pop(i) {
    if (i > 6) 
    window.alert('Error: this setup works only for 7 scrolling objects')
    if (i == 0) {
           return this.content_0
    } else if (i == 1) {
           return this.content_1
    } else if (i == 2) {
           return this.content_2
    } else if (i == 3) {
           return this.content_3
    } else if (i == 4) {
           return this.content_4
    } else if (i == 5) {
           return this.content_5
    } else if ( i == 6) {
           return this.content_6
    }
}

// Stuff to Incarnate the layer
function ClinkLayer(mylayer, myParent) {
    this.name = mylayer
    this.browser = new ClinkBrowser()
    if (this.browser._n) {
         if (myParent != null) {
         this.doc = eval('myParent.doc.document.'+mylayer)
         } else {
         this.doc = eval('document.'+mylayer)
         }
         this.x = this.doc.left
         this.width = this.doc.posWidth
    } else {
         this.doc = eval(mylayer + '.style')
         this.event = eval("document.all."+mylayer)
         this.css = this.event.style
         this.x = this.css.pixelLeft
         this.width = this.css.pixelWidth
    }
// make some internal interfaces visible to outside
    this.moveBy = Clink_moveBy
    this.moveTo = Clink_moveTo
    this.reset = Clink_reset
    return 1
}

// external interfaces
 
function Clink_reset(x) {
    this.moveTo(x)
}
 
function Clink_moveTo(x) {
        this.x = x
        if (this.browser._n) {
        this.doc.left = this.x
        } else {
        this.css.pixelLeft = this.x
        }
}
 
function Clink_moveBy(dx) {
        this.x += dx
        if (this.browser._n) {
        this.doc.left = this.x
        } else {
        this.css.pixelLeft = this.x
        }
}

