var vscrolldir=1;  //scroll direction: 1 up, -1 down
var div_viewed=1; //the div being viewed, firstly 1
var vscrollwidth="220px";
var vscrollheight="190px";
var repeat_space=50; //blank space between the end of srolling message and the start of next repeated scrolling message
var vscrollstep=1;   //if 1, scroll
var mousepause=1; //if 1, stop scroll on mouseover

var a_step=vscrollstep;
var iemo=document.all||document.getElementById;  //IE or Mozilla or Netscape 6+
var actualheight='';
var iemo_vscroll, ns_vscroll;
var iemo_vscroll2, ns_vscroll2;
var pausestep=(mousepause==0)? a_step: 0;
var reachedtop = 0;

with (document){
   if (document.all||document.getElementById){
      write('<div id="scReg" align=right style="position:relative;width:'+vscrollwidth+';height:'+vscrollheight+';overflow:hidden" onMouseover="a_step=pausestep" onMouseout="a_step=vscrollstep">')
      write('<div id="ie_vscroller" style="position:absolute;left:0px;top:0px;width:100%;"></div>')
      write('<div id="ie_vscroller2" style="position:absolute;left:0px;top:0px;width:100%;">')
      write('</div></div>')
   }
   else if (document.layers){
      write('<ilayer width='+vscrollwidth+' height='+vscrollheight+' name="nscReg">');
      write('<layer name="ns_vscroller" width='+vscrollwidth+' height='+vscrollheight+' left=0 top=0 onMouseover="a_step=pausestep" onMouseout="a_step=vscrollstep"></layer>');
      write('<layer name="ns_vscroller2" width='+vscrollwidth+' height='+vscrollheight+' left=0 top=0 onMouseover="a_step=pausestep" onMouseout="a_step=vscrollstep"></layer>');
      write('</ilayer>');
   }
}

function setDivPosX() {
   //default for 800 x 600 resolution, div defined in html screen is "top:40px;left:520px;width:250px;"
   //while the scrolling region defined in scrolltext.js is "width:220px; height:190px;"
   winwidth=document.all?document.body.clientWidth:window.innerWidth;
   winheight=document.all?document.body.clientHeight:window.innerHeight;
   if (iemo){
       scbox = document.getElementById("scrollbox").style;
       scbox.left = parseInt(520 * parseInt(winwidth)/800)+ "px";
       scbox.width = parseInt(250 * parseInt(winwidth)/ 800) + "px";
       scbox.top = parseInt(40 * parseInt(winheight)/408) + "px";  //win height is 408 when resolution is 800 x 600

       screg = document.getElementById("scReg").style;
       screg.width = parseInt(220 * parseInt(winwidth)/800) + "px";
       screg.height = parseInt(190 * parseInt(winheight)/408) + "px";
       vscrollheight = screg.height;
    } else {
       nscbox = document.scrollbox;
       nscbox.left = parseInt(winwidth) - nscbox.width - 40;
       nscbox.width = parseInt(250 * parseInt(winwidth)/ 800);
       nscbox.top = parseInt(40 * parseInt(winheight)/408);

       nscreg = document.nscReg;
       nscreg.width = parseInt(220 * parseInt(winwidth)/800);
       nscreg.height = parseInt(190 * parseInt(winheight)/408);
       vscrollheight = nscreg.height + "px";
    }
    recal_top();
}

setDivPosX();
window.onresize = setDivPosX;

function cOn(td){
   if (document.getElementById||(document.all && !(document.getElementById))){
      td.style.backgroundColor="violet";
   }
}

function cOut(td, the_color){
   if (document.getElementById||(document.all && !(document.getElementById))){
      td.style.backgroundColor=the_color;
   }
}

function recal_top() {
   if (iemo){
      iemo_vscroll = document.getElementById? document.getElementById("ie_vscroller") : document.all.ie_vscroller;
      iemo_vscroll2 = document.getElementById? document.getElementById("ie_vscroller2") : document.all.ie_vscroller2;
      actualheight = iemo_vscroll.offsetHeight;  //recheck actualheight as the screen may have been re-sized
      if (div_viewed == 1) {
         iemo_vscroll2.style.top = parseInt(iemo_vscroll.style.top) + (vscrolldir * (-1) * (actualheight + repeat_space)) + "px";
      } else {
         iemo_vscroll.style.top = parseInt(iemo_vscroll2.style.top) + (vscrolldir * (-1) * (actualheight + repeat_space)) + "px";
      }
   } else {
      ns_vscroll = document.nscReg.document.ns_vscroller;
      ns_vscroll2 = document.nscReg.document.ns_vscroller2;
      actualheight = ns_vscroll.document.height;
      if (div_viewed == 1) {
         ns_vscroll2.top = ns_vscroll.top + (vscrolldir * (-1) * (actualheight + repeat_space));
      } else {
         ns_vscroll.top = ns_vscroll2.top + (vscrolldir * (-1) * (actualheight + repeat_space));
      }
   }
}

function chg_speed(speed) {
   if ((vscrolldir * speed) < 0) {   //change direction
       recal_top();
   }

   if (speed < 0) {
      vscrolldir = -1;
      vscrollstep= 0 - speed;
      a_step = 0 - speed;
   } else {
      vscrolldir = 1;
      vscrollstep= speed;
      a_step = speed;
   }
}

function run_vscroll(vscrollmsg){
   if (iemo){
      iemo_vscroll = document.getElementById? document.getElementById("ie_vscroller") : document.all.ie_vscroller;
      iemo_vscroll.innerHTML = vscrollmsg;
      actualheight = iemo_vscroll.offsetHeight;
      iemo_vscroll2 = document.getElementById? document.getElementById("ie_vscroller2") : document.all.ie_vscroller2;
      iemo_vscroll2.innerHTML = vscrollmsg;
      iemo_vscroll.style.top = (vscrolldir * parseInt(vscrollheight)) + "px";
      iemo_vscroll2.style.top = parseInt(iemo_vscroll.style.top) + (vscrolldir * (actualheight + repeat_space)) + "px";
   }
   else if (document.layers){
      ns_vscroll = document.nscReg.document.ns_vscroller;
      ns_vscroll.document.write(vscrollmsg);
      ns_vscroll.document.close();
      actualheight = ns_vscroll.document.height;
      ns_vscroll2 = document.nscReg.document.ns_vscroller2;
      ns_vscroll2.document.write(vscrollmsg);
      ns_vscroll2.document.close();
      ns_vscroll.top = vscrolldir * parseInt(vscrollheight);
      ns_vscroll2.top = ns_vscroll.top + (vscrolldir * (actualheight + repeat_space));
   }
   lefttime=setInterval("vscroll()",30);  //control scroll speed
}

function vscroll(){
//   if (reachedtop > 0) reachedtop -= 1;  //stop scroll about 2 sec at the top
//   if (iemo && !reachedtop){
   if (iemo){
      if (actualheight == 0) {
  	     actualheight = iemo_vscroll.offsetHeight;  //recheck actualheight as iemo_vscroll may not have fully developed in run_vscroll() in IE
    		 iemo_vscroll2.style.top = parseInt(iemo_vscroll2.style.top) + actualheight + "px";
	  }
      actualheight = iemo_vscroll.offsetHeight;   //recheck acutalheight as the screen may have been re-sized
      if (div_viewed == 1){
         if ((vscrolldir == 1 && (parseInt(iemo_vscroll.style.top)>(0 - actualheight))) ||
            (vscrolldir == -1 && (parseInt(iemo_vscroll.style.top)<parseInt(vscrollheight)))) {
            iemo_vscroll.style.top = (parseInt(iemo_vscroll.style.top) - (a_step * vscrolldir)) +"px";
            iemo_vscroll2.style.top = (parseInt(iemo_vscroll2.style.top) - (a_step * vscrolldir)) +"px";
         } else {
            div_viewed = 2;
            iemo_vscroll.style.top = parseInt(iemo_vscroll2.style.top) + ((actualheight + repeat_space) * vscrolldir) +"px";
         }
      } else {
         if ((vscrolldir == 1 && (parseInt(iemo_vscroll2.style.top)>(0 - actualheight))) ||
            (vscrolldir == -1 && (parseInt(iemo_vscroll2.style.top)<parseInt(vscrollheight)))) {
            iemo_vscroll.style.top = (parseInt(iemo_vscroll.style.top) - (a_step * vscrolldir)) +"px";
            iemo_vscroll2.style.top = (parseInt(iemo_vscroll2.style.top) - (a_step * vscrolldir)) +"px";
         } else {
            div_viewed = 1;
            iemo_vscroll2.style.top = parseInt(iemo_vscroll.style.top) + ((actualheight + repeat_space) * vscrolldir) +"px";
         }
      }
//      if (parseInt(iemo_vscroll.style.top) == 0) reachedtop = 0;   //reachedtop = 100  stop scroll about 2 sec at the top
   }
//   else if (document.layers && !reachedtop){
   else {
      actualheight = ns_vscroll.document.height;
      if (div_viewed == 1){
         if ((vscrolldir == 1 && (ns_vscroll.top>(0 - actualheight))) ||
            (vscrolldir == -1 && (ns_vscroll.top<parseInt(vscrollheight)))) {
            ns_vscroll.top = ns_vscroll.top - (a_step * vscrolldir);
            ns_vscroll2.top = ns_vscroll2.top - (a_step * vscrolldir);
         } else {
            div_viewed = 2;
            ns_vscroll.top = ns_vscroll2.top+ ((actualheight + repeat_space) * vscrolldir);
         }
      } else {
         if ((vscrolldir == 1 && (ns_vscroll2.top>(0 - actualheight))) ||
            (vscrolldir == -1 && (ns_vscroll2.top<parseInt(vscrollheight)))) {
            ns_vscroll.top = ns_vscroll.top - (a_step * vscrolldir);
            ns_vscroll2.top = ns_vscroll2.top - (a_step * vscrolldir);
         } else {
            div_viewed = 1;
            ns_vscroll2.top = ns_vscroll.top+ ((actualheight + repeat_space) * vscrolldir);
         }
//      if (ns_vscroll.top == 0) reachedtop = 0;     //reachedtop = 100  stop scroll about 2 sec at the top
      }
   }
}


