// <script>

var agt=navigator.userAgent.toLowerCase();
var is_ie4  = agt.indexOf("msie 4")!=-1;
var IE = document.all?true:false;
var NS = document.layers?true:false;
var NS6 = (!IE && document.getElementById)?true:false;

var idscrcnt = new Array();

function scroller(x, y, width, height)
{
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;

        this.bgColor = "";
        this.bgImage = "";

        this.itemLeft = 10;
        this.itemWidth = 0;

        this.delay = 50;
        this.pause = 2000;
        this.mousePause = 500;
        this.mouseStop = true;

        this.ID = idscrcnt.length;
        idscrcnt[idscrcnt.length] = this;

        this.items = new Array();

        this.curItem = 0;

        this.addItem = scrAddItem;
        this.init = scrInit;
}

function scrAddItem(text)
{
        // Text should be a fully qualified HTML string
        this.items[this.items.length] = text;
}

function scrInit()
{
var scrText,i, mItem, o;
var tp=2;

        if (this.itemWidth == 0)
                this.itemWidth = this.width - 2 * this.itemLeft;
        if (IE)
        {
                var s;

                scrText = "<div id='idscr" + this.ID + "' style=\"position:absolute;z-index:99; visibility:visible; width:" + this.width + "px;\"></div>";
                document.body.insertAdjacentHTML ("BeforeEnd", scrText);

                o = eval("idscr" + this.ID);

                this.o = o;
                o.obj = this;

                s = o.style;

                s.pixelLeft = this.x;
                s.pixelTop = this.y;
                s.pixelWidth = this.width;
                s.pixelHeight = this.height;

                s.backgroundColor = this.bgColor;
                s.backgroundImage = "url(" + this.bgImage + ")";
                s.clip = "rect(0,"+ s.pixelWidth + "," + s.pixelHeight + ",0)";


                this.loPos = is_ie4?this.height:o.clientHeight + 2;
                if(is_ie4) tp=this.loPos;
                for (i=0;i<this.items.length;++i)
                {
                        o.insertAdjacentHTML("BeforeEnd", "<span id=sci" + i + " style=\"position:absolute;\">" + this.items[i] + "</span>");
                        mItem = eval("sci" + i);
                        mItem.style.pixelLeft = this.itemLeft;
                        mItem.style.pixelWidth = this.itemWidth;
                        mItem.style.pixelTop = tp;
                        tp += mItem.clientHeight + 5;
                        if (tp>this.loPos) tp=this.loPos;
                        this.items[i] = mItem;
                }
        }
        else if (NS)
        {
                eval ("idscr" + this.ID + "= new Layer("+ this.width +",window)");

                o = eval("idscr" + this.ID);

                this.o = o;
                o.obj = this;

                o.left = this.x;
                o.top = this.y;
                o.width = this.width;
                o.height = this.height;
                o.visibility = "show";
                o.clip.right = this.width;
                o.clip.bottom = this.height;
                o.clip.top = 0;
                o.clip.left = 0;
                if (this.bgColor.length != 0) o.bgColor = this.bgColor;
                o.background.src = this.bgImage;
                this.loPos = this.height;
                for (i=0;i<this.items.length;++i)
                {
                        eval ("sci" + i + "= new Layer("+this.itemWidth+",idscr" + this.ID + ")");
                        mItem = eval("sci" + i);
                        mItem.left = this.itemLeft;
                        mItem.document.write( this.items[i] );
                        mItem.document.close();
                        mItem.top = tp;
                        tp+=mItem.document.height + 5;
                        if (tp>this.loPos) tp=this.loPos;
                        mItem.clip.right = this.itemWidth;
                        mItem.visibility = "show";
                        this.items[i] = mItem;
                }
        } else if (NS6)
        {
                var s;

                scrText = "<div id='idscr" + this.ID + "' style=\"position:absolute; visibility:visible; width:" + this.width + "px;\"></div>";

                var o = document.createElement("DIV");
                o.id = "idscr" + this.ID;
                o.style.position = "absolute";
                o.style.visibility = "visible";
                o.style.width = this.width;
                o.style.zIndex = 99;

                mybody=document.getElementsByTagName("body").item(0);
                mybody.appendChild(o);

                //document.getElementByID("body").insertAdjacentHTML ("BeforeEnd", scrText);

                this.o = o;
                o.obj = this;

                s = o.style;

                s.left = this.x;
                s.top = this.y;
                s.width = this.width;
                s.height = this.height;

                s.backgroundColor = this.bgColor;
                s.backgroundImage = "url(" + this.bgImage + ")";
                s.clip = "rect(0,"+ s.width + "," + s.height + ",0)";


                this.loPos = o.offsetHeight + 5;
                for (i=0;i<this.items.length;++i)
                {
                        mItem = document.createElement("SPAN");
                        mItem.id = "sci" + i;
                        mItem.style.position = "absolute";
                        mItem.innerHTML = this.items[i];
                        o.appendChild(mItem);

                        mItem.style.left = this.itemLeft;
                        mItem.style.width = this.itemWidth;
                        mItem.style.top = tp;
                        tp += mItem.offsetHeight + 10;
                        if (tp>this.loPos) tp=this.loPos;

                        this.items[i] = mItem;

                        mItem = document.createElement("BR");
                        o.appendChild(mItem);


                }
        }
        if (tp==this.loPos)
        {
                if (this.mouseStop)
                {
                        o.onmouseover = scrMOver;
                        o.onmouseout  = scrMOut;
                }
                scrTimer = window.setTimeout("scrScroll(" + this.ID + ")",this.pause);
        }
}
var slgvar = 0;
function scrScroll(idx)
{
var i, prevItem, nxt, pause, o, oi;

        o = idscrcnt[idx];
        oi = o.items;
        window.clearTimeout(scrTimer);
        nxt = false;
        pause = false;
        i = o.curItem;
        prevItem = i-1;
        if (prevItem < 0) prevItem = oi.length-1;
        do
        {
                if (IE)
                {
                        if (i == o.curItem || (oi[prevItem].style.pixelTop + oi[prevItem].clientHeight + 2)<o.loPos)
                        {
                                oi[i].style.pixelTop -= 1;
                                if (oi[i].style.pixelTop == 2) pause = true;
                        }
                }
                else if (NS)
                {
                        if (i == o.curItem || (oi[prevItem].top + oi[prevItem].document.height + 2)<o.loPos)
                        {
                                oi[i].top -= 1;
                                if (oi[i].top == 2) pause = true;
                        }
                }
                else if (NS6)
                {
                        //alert("slgvar="+slgvar);
                        //if (slgvar <10) alert("oi[prevItem].style.top="+oi[prevItem].style.top);
                        //slgvar += 1
                        if (i == o.curItem || (parseInt(oi[prevItem].style.top) + oi[prevItem].offsetHeight + 2)<o.loPos)
                        {
                                oi[i].style.top = parseInt(oi[i].style.top)-1;
                                if (parseInt(oi[i].style.top) == 2) pause = true;
                        }
                }
                prevItem = i;
                if (++i == oi.length) i=0;
        }
        while (i != o.curItem);

        if (pause)
                o.timer = window.setTimeout("scrRotate(" + idx + ")",o.pause);
        else
                o.timer = window.setTimeout("scrRotate(" + idx + ")",o.delay);
}

function scrRotate(idx)
{
var o, oi;
        o = idscrcnt[idx];
        oi = o.items;
        for (var i=0; i<oi.length;++i)
        {
                if (IE)
                {
                        if ((oi[i].style.pixelTop + oi[i].clientHeight)<0)
                        {
                                oi[i].style.pixelTop = o.loPos;
                                if (++(o.curItem) == oi.length)
                                        o.curItem = 0;
                        }
                }
                else if (NS)
                {
                        if ((oi[i].top + oi[i].document.height)<0)
                        {
                                oi[i].top = o.loPos;
                                if (++(o.curItem) == oi.length)
                                        o.curItem = 0;
                        }
                }
                else if (NS6)
                {
                        if ((parseInt(oi[i].style.top) + oi[i].offsetHeight)<0)
                        {
                                oi[i].style.top = o.loPos;
                                if (++(o.curItem) == oi.length)
                                        o.curItem = 0;
                        }
                }
        }
        scrScroll(idx);
}

function scrMOver(){window.clearTimeout(this.obj.timer);}
function scrMOut(){this.obj.timer = window.setTimeout("scrRotate(" + this.obj.ID + ")",this.obj.mousePause);}