
var buttonState = 0;
var insPoint = 0;
var scBG,scMA,scNB,scAU,scAD,scNT;
var scSC;
var tagStyle;
var scSCheight = 72;
var scrollTime;
var slideTime = 130;
var slideAccel = 8;
var scrollAccel = 2;
var scrollDefTime = 50;
var scrollValue;
var valSlideScroller = 0;
var textOverflow = 0;
var textLength = 0;
var scSCscale = 0;
var onColor = "#000000";
var offColor = "#666666";

function loadScroller() {


scMA = document.getElementById("main");
scMIDDLE = document.getElementById("middle");
scNT = document.getElementById("newstext");
scNB = document.getElementById("newsbg");
scBG = document.getElementById("scrollerbg");
scSC = document.getElementById("scrollerbutton");
scAU = document.getElementById("scrollerarrowup");
scAD = document.getElementById("scrollerarrowdown");

scAU.onmousedown = startScrollUp; //startScrollUp; //if (scAU.captureEvents) scAU.captureEvents(Event.MOUSEDOWN);
scAD.onmousedown = startScrollDown; //startScrollDown;// if (scAD.captureEvents) scAD.captureEvents(Event.MOUSEDOWN);


scMIDDLE.onmousewheel = scrollWheel;// if (document.captureEvents) document.captureEvents(Event.MOUSEWHEEL);
scNT.onmousewheel = scrollWheel;
//document.onmouseup = checkUp; //if (document.captureEvents) document.captureEvents(Event.MOUSEUP);
//scBG.onmousemove = checkMove;
//scBG.onmousedown = checkDown; //if (scBG.captureEvents) scBG.captureEvents(Event.MOUSEDOWN);
//scBG.onmouseup = checkUp; //if (scBG.captureEvents) scBG.captureEvents(Event.MOUSEUP);
scSC.onmousedown = checkDown2;// if (scSC.captureEvents) scSC.captureEvents(Event.MOUSEDOWN);
//scSC.onmouseup = checkUp; //if (scSC.captureEvents) scSC.captureEvents(Event.MOUSEUP);
scBG.style.top = 127;
scSC.style.top = 1;

scSC.style.backgroundColor = offColor;
scAU.style.backgroundColor = offColor;
scAD.style.backgroundColor = offColor;


textLength = scNT.offsetHeight;

textOverflow = textLength - scNB.offsetHeight;
scSCscale = (384 / textLength);
if(scSCscale > 1) scSCscale = 1;
scSCheight = parseInt(356 * scSCscale);

scSC.style.height = scSCheight;
scSC.style.clip = "rect(2px 12px "+(scSCheight-3)+"px 2px)";




//slideAccel = 3; //0.005 * textOverflow;
}







function checkMove(e) {

	if (!e) var e = window.event;
	if(e.pageY) mouseY = e.pageY;
	if(e.y) mouseY = e.y;

	trueY = mouseY - 2 - scMA.offsetTop - scBG.offsetTop;
	if(buttonState == 1) setButtonPos(trueY - insPoint);

	return false;
}
/*
function checkDown(e) {

	if (!e) var e = window.event;
	if(e.pageY) mouseY = e.pageY;
	if(e.y) mouseY = e.y;

	trueY = mouseY - 2 - scMA.offsetTop - scBG.offsetTop;


	buttY = scSC.offsetTop;


	if(buttonState != 1) {

		document.onmousemove = checkMove;
        buttonDown = 1;
        trueY = trueY - (scSCheight/2);
        if (trueY < 1) trueY = 1;
        if (trueY > (356 - scSCheight)) trueY = 356-scSCheight;
        moveButton(trueY);
}


return false;
}
*/
function checkDown2(e) {

	if (!e) var e = window.event;
	if(e.pageY) mouseY = e.pageY;
	if(e.y) mouseY = e.y;

	trueY = mouseY - 2 - scMA.offsetTop - scBG.offsetTop;


 	buttY = scSC.offsetTop;

	if(trueY >= buttY && trueY <= (buttY + scSCheight)) {
        	buttonState = 1;
	        insPoint = trueY - buttY;
        	scSC.style.backgroundColor = onColor;
        	document.onmousemove = checkMove;
	}

  	document.onmousemove = checkMove;
   	document.onmouseup = stopScrollerMove;


return true;
}

function stopScrollerMove(e) {

	document.onmousemove = null;
	document.onmouseup = null;
	scAU.onmouseup = null;
	scAD.onmouseup = null;
	valSlideScroller = 0;
	scSC.style.backgroundColor = offColor;
	scAD.style.backgroundColor = offColor;
	scAU.style.backgroundColor = offColor;
	return false;

}


function setButtonPos(trueY) {

if(scSCscale < 1) {

if(trueY < 1) trueY = 1;
if(trueY > (356-scSCheight)) trueY = (356-scSCheight);
//if(NS) scSC.top = trueY;// - insPoint;
scSC.style.top = trueY;// - insPoint;
scrollValue = trueY - 1;

scrollRange = (356 - scSCheight)-1;
scrollPos = (scrollValue / scrollRange);
//scrollPos = (scrollValue/scrollRange);

textPos = parseInt(0 - (textOverflow * scrollPos));


//if(NS) scNT.top = textPos;
scNT.style.top = textPos;

window.status = parseInt(scrollPos * 100) + " %";
}
}

function doNothing(e) {

	return false;
}

function startScrollDown(e) {

	document.onmouseup = stopScrollerMove;
	document.onmousemove = doNothing;

 scAD.style.backgroundColor = onColor;
valSlideScroller = 1;
startScrolls(1);
return false;

}
function startScrollUp(e) {

		document.onmouseup = stopScrollerMove;
	document.onmousemove = doNothing;
//if(NS) scAU.document.bgColor = onColor;
scAU.style.backgroundColor = onColor;
valSlideScroller = 1;
startScrolls(2);
return false;
}

function startScrolls(direction) {
if(valSlideScroller == 1) {
curPos = scSC.offsetTop;
//if(NS) scSC.document.bgColor = onColor;
scSC.style.backgroundColor = onColor;
if(direction == 1) setButtonPos(curPos + slideAccel);
if(direction == 2) setButtonPos(curPos - slideAccel);
eval("setTimeout(\"startScrolls("+direction+")\","+slideTime+")");
}
}

function scrollWheel() {

if(event.wheelDelta >= 1) startScrollUp(0);
if(event.wheelDelta <= -1) startScrollDown(0);

setTimeout("stopScrollerMove(0)",100);

}

/*

function moveButtonDown(toVal) {
buttonTop = scSC.offsetTop;
        if(toVal > buttonTop && buttonDown == 1) {
        if((scrollTime + scrollAccel + 1) > 0 ) scrollTime -= scrollAccel;
        //if(NS) scSC.document.bgColor = onColor;
         scSC.style.backgroundColor = onColor;
        setButtonPos(buttonTop + 5);

                eval("setTimeout(\"moveButtonDown("+toVal+")\","+scrollTime+")");
        }

        if(toVal <= buttonTop) {
                //if(NS)scSC.top = toVal;
                scSC.style.top =toVal;
                buttonState = 1;
                insPoint = scSCheight / 2;
                return false;
        }
}
function moveButtonUp(toVal) {
buttonTop = scSC.offsetTop;
        if(toVal < buttonTop && buttonDown == 1) {
                if((scrollTime + scrollAccel + 1) > 0 ) scrollTime -= scrollAccel;
                   //     if(NS) scSC.document.bgColor = onColor;
                       scSC.style.backgroundColor = onColor;
                setButtonPos(buttonTop - 5);
                eval("setTimeout(\"moveButtonUp("+toVal+")\","+scrollTime+")");
        }

        if(toVal >= buttonTop) {
                //if(NS)scSC.top = toVal;
                scSC.style.top =toVal;
                buttonState = 1;
                insPoint = scSCheight / 2;
                return false;
        }
}
*/

function moveButton(toVal) {
scrollTime = scrollDefTime;
buttonTop = scSC.offsetTop;
if(buttonTop < toVal) moveButtonDown(toVal);
if(buttonTop > toVal) moveButtonUp(toVal);
}