var l_vscrolldir=1;  //scroll direction: 1 up, -1 down
var l_div_viewed=1; //the div being viewed, firstly 1
var l_vscrollwidth="220px";
var l_vscrollheight="190px";
var l_repeat_space=50; //blank space between the end of srolling message and the start of next repeated scrolling message
var l_vscrollstep=1;   //if 1, scroll
var l_mousepause=1; //if 1, stop scroll on mouseover

var l_a_step=l_vscrollstep;
var l_iemo=document.all||document.getElementById;  //IE or Mozilla or Netscape 6+
var l_actualheight='';
var l_iemo_vscroll, l_ns_vscroll;
var l_iemo_vscroll2, l_ns_vscroll2;
var l_pausestep=(l_mousepause==0)? l_a_step: 0;
var l_reachedtop = 0;

with (document){
   if (document.all||document.getElementById){
      write('<div id="l_scReg" align=right style="position:relative;width:'+l_vscrollwidth+';height:'+l_vscrollheight+';overflow:hidden" onMouseover="l_a_step=l_pausestep" onMouseout="l_a_step=l_vscrollstep">')
      write('<div id="l_ie_vscroller" style="position:absolute;left:0px;top:0px;width:100%;"></div>')
      write('<div id="l_ie_vscroller2" style="position:absolute;left:0px;top:0px;width:100%;">')
      write('</div></div>')
   }
   else if (document.layers){
      write('<ilayer width='+l_vscrollwidth+' height='+l_vscrollheight+' name="l_nscReg">');
      write('<layer name="l_ns_vscroller" width='+l_vscrollwidth+' height='+l_vscrollheight+' left=0 top=0 onMouseover="l_a_step=l_pausestep" onMouseout="l_a_step=l_vscrollstep"></layer>');
      write('<layer name="l_ns_vscroller2" width='+l_vscrollwidth+' height='+l_vscrollheight+' left=0 top=0 onMouseover="l_a_step=l_pausestep" onMouseout="l_a_step=l_vscrollstep"></layer>');
      write('</ilayer>');
   }
}

function l_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 (l_iemo){
       l_scbox = document.getElementById("l_scrollbox").style;
       l_scbox.left = parseInt(30 * parseInt(winwidth)/800)+ "px";
       l_scbox.width = parseInt(250 * parseInt(winwidth)/ 800) + "px";
       l_scbox.top = parseInt(40 * parseInt(winheight)/408) + "px";  //win height is 408 when resolution is 800 x 600

       l_screg = document.getElementById("l_scReg").style;
       l_screg.width = parseInt(220 * parseInt(winwidth)/800) + "px";
       l_screg.height = parseInt(190 * parseInt(winheight)/408) + "px";
       l_vscrollheight = l_screg.height;
    } else {
       l_nscbox = document.l_scrollbox;
       l_nscbox.left = parseInt(winwidth) - l_nscbox.width - 40;
       l_nscbox.width = parseInt(250 * parseInt(winwidth)/ 800);
       l_nscbox.top = parseInt(40 * parseInt(winheight)/408);

       l_nscreg = document.l_nscReg;
       l_nscreg.width = parseInt(220 * parseInt(winwidth)/800);
       l_nscreg.height = parseInt(190 * parseInt(winheight)/408);
       l_vscrollheight = l_nscreg.height + "px";
    }
    l_recal_top();
}

l_setDivPosX();

function common_setDivPosX() {
   setDivPosX();
   l_setDivPosX();
}

window.onresize = common_setDivPosX;

function l_cOn(td){
   if (document.getElementById||(document.all && !(document.getElementById))){
      td.style.backgroundColor="violet";
   }
}

function l_cOut(td, the_color){
   if (document.getElementById||(document.all && !(document.getElementById))){
      td.style.backgroundColor=the_color;
   }
}

function l_recal_top() {
   if (l_iemo){
      l_iemo_vscroll = document.getElementById? document.getElementById("l_ie_vscroller") : document.all.l_ie_vscroller;
      l_iemo_vscroll2 = document.getElementById? document.getElementById("l_ie_vscroller2") : document.all.l_ie_vscroller2;
      l_actualheight = l_iemo_vscroll.offsetHeight;  //recheck actualheight as the screen may have been re-sized
      if (l_div_viewed == 1) {
         l_iemo_vscroll2.style.top = parseInt(l_iemo_vscroll.style.top) + (l_vscrolldir * (-1) * (l_actualheight + l_repeat_space)) + "px";
      } else {
         l_iemo_vscroll.style.top = parseInt(l_iemo_vscroll2.style.top) + (l_vscrolldir * (-1) * (l_actualheight + l_repeat_space)) + "px";
      }
   } else {
      l_ns_vscroll = document.l_nscReg.document.l_ns_vscroller;
      l_ns_vscroll2 = document.l_nscReg.document.l_ns_vscroller2;
      l_actualheight = l_ns_vscroll.document.height;
      if (l_div_viewed == 1) {
         l_ns_vscroll2.top = l_ns_vscroll.top + (l_vscrolldir * (-1) * (l_actualheight + l_repeat_space));
      } else {
         l_ns_vscroll.top = l_ns_vscroll2.top + (l_vscrolldir * (-1) * (l_actualheight + l_repeat_space));
      }
   }
}

function l_chg_speed(speed) {
   if ((l_vscrolldir * speed) < 0) {   //change direction
       l_recal_top();
   }

   if (speed < 0) {
      l_vscrolldir = -1;
      l_vscrollstep= 0 - speed;
      l_a_step = 0 - speed;
   } else {
      l_vscrolldir = 1;
      l_vscrollstep= speed;
      l_a_step = speed;
   }
}

function l_run_vscroll(vscrollmsg){
   if (l_iemo){
      l_iemo_vscroll = document.getElementById? document.getElementById("l_ie_vscroller") : document.all.l_ie_vscroller;
      l_iemo_vscroll.innerHTML = vscrollmsg;
      l_actualheight = l_iemo_vscroll.offsetHeight;
      l_iemo_vscroll2 = document.getElementById? document.getElementById("l_ie_vscroller2") : document.all.l_ie_vscroller2;
      l_iemo_vscroll2.innerHTML = vscrollmsg;
      l_iemo_vscroll.style.top = (l_vscrolldir * parseInt(l_vscrollheight)) + "px";
      l_iemo_vscroll2.style.top = parseInt(l_iemo_vscroll.style.top) + (l_vscrolldir * (l_actualheight + l_repeat_space)) + "px";
   }
   else if (document.layers){
      l_ns_vscroll = document.nscReg.document.l_ns_vscroller;
      l_ns_vscroll.document.write(vscrollmsg);
      l_ns_vscroll.document.close();
      l_actualheight = l_ns_vscroll.document.height;
      l_ns_vscroll2 = document.l_nscReg.document.l_ns_vscroller2;
      l_ns_vscroll2.document.write(vscrollmsg);
      l_ns_vscroll2.document.close();
      l_ns_vscroll.top = l_vscrolldir * parseInt(l_vscrollheight);
      l_ns_vscroll2.top = l_ns_vscroll.top + (l_vscrolldir * (l_actualheight + l_repeat_space));
   }
   l_lefttime=setInterval("l_vscroll()",30);  //control scroll speed
}

function l_vscroll(){
//   if (reachedtop > 0) reachedtop -= 1;  //stop scroll about 2 sec at the top
//   if (iemo && !reachedtop){
   if (l_iemo){
      if (l_actualheight == 0) {
  	     l_actualheight = l_iemo_vscroll.offsetHeight;  //recheck actualheight as iemo_vscroll may not have fully developed in run_vscroll() in IE
    		 l_iemo_vscroll2.style.top = parseInt(l_iemo_vscroll2.style.top) + l_actualheight + "px";
	  }
      l_actualheight = l_iemo_vscroll.offsetHeight;   //recheck acutalheight as the screen may have been re-sized
      if (l_div_viewed == 1){
         if ((l_vscrolldir == 1 && (parseInt(l_iemo_vscroll.style.top)>(0 - l_actualheight))) ||
            (l_vscrolldir == -1 && (parseInt(l_iemo_vscroll.style.top)<parseInt(l_vscrollheight)))) {
            l_iemo_vscroll.style.top = (parseInt(l_iemo_vscroll.style.top) - (l_a_step * l_vscrolldir)) +"px";
            l_iemo_vscroll2.style.top = (parseInt(l_iemo_vscroll2.style.top) - (l_a_step * l_vscrolldir)) +"px";
         } else {
            l_div_viewed = 2;
            l_iemo_vscroll.style.top = parseInt(l_iemo_vscroll2.style.top) + ((l_actualheight + l_repeat_space) * l_vscrolldir) +"px";
         }
      } else {
         if ((l_vscrolldir == 1 && (parseInt(l_iemo_vscroll2.style.top)>(0 - l_actualheight))) ||
            (l_vscrolldir == -1 && (parseInt(l_iemo_vscroll2.style.top)<parseInt(l_vscrollheight)))) {
            l_iemo_vscroll.style.top = (parseInt(l_iemo_vscroll.style.top) - (l_a_step * l_vscrolldir)) +"px";
            l_iemo_vscroll2.style.top = (parseInt(l_iemo_vscroll2.style.top) - (l_a_step * l_vscrolldir)) +"px";
         } else {
            l_div_viewed = 1;
            l_iemo_vscroll2.style.top = parseInt(l_iemo_vscroll.style.top) + ((l_actualheight + l_repeat_space) * l_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 {
      l_actualheight = l_ns_vscroll.document.height;
      if (l_div_viewed == 1){
         if ((l_vscrolldir == 1 && (l_ns_vscroll.top>(0 - l_actualheight))) ||
            (l_vscrolldir == -1 && (l_ns_vscroll.top<parseInt(l_vscrollheight)))) {
            l_ns_vscroll.top = l_ns_vscroll.top - (l_a_step * l_vscrolldir);
            l_ns_vscroll2.top = l_ns_vscroll2.top - (l_a_step * l_vscrolldir);
         } else {
            l_div_viewed = 2;
            l_ns_vscroll.top = l_ns_vscroll2.top+ ((l_actualheight + l_repeat_space) * l_vscrolldir);
         }
      } else {
         if ((l_vscrolldir == 1 && (l_ns_vscroll2.top>(0 - l_actualheight))) ||
            (l_vscrolldir == -1 && (l_ns_vscroll2.top<parseInt(l_vscrollheight)))) {
            l_ns_vscroll.top = l_ns_vscroll.top - (l_a_step * l_vscrolldir);
            l_ns_vscroll2.top = l_ns_vscroll2.top - (l_a_step * l_vscrolldir);
         } else {
            l_div_viewed = 1;
            l_ns_vscroll2.top = l_ns_vscroll.top+ ((l_actualheight + l_repeat_space) * l_vscrolldir);
         }
//      if (ns_vscroll.top == 0) reachedtop = 0;     //reachedtop = 100  stop scroll about 2 sec at the top
      }
   }
}



