/* The scrolling text box script. Always use together with holder.js! */

// the timer variables, for cleanup later.
var timer1, timer2;

// the scroll speed. The higher the number, the slower it scrolls.
var scrollspeed = 200; 

// initalize the variable that will serve as a 'load checker'

var loaded=0;


//the object constructor's core function

 function createObject(elem,container) {
 if (document.layers) {
  if (container) {
     container = doc +container+".";
     }
   else {container = ""; }
    
  this.element = eval(container+doc + elem);
  this.styleElem = eval(container +doc+ elem);
  this.elemheight = this.styleElem.document.height;
  this.clipheight = this.styleElem.clip.height;
   }

  else if (document.all) {
  this.element = document.all[elem];
  this.styleElem = document.all[elem].style;
  this.elemheight = this.element.offsetHeight;
  this.clipheight = this.element.offsetHeight;
    }
    
  else if (document.getElementById) {
  this.element = document.getElementById(elem);
  this.styleElem = document.getElementById(elem).style;
  this.elemheight = this.element.offsetHeight;
  this.clipheight = this.element.offsetHeight;
  } 
  
  else {return false;}

  this.scrollIt = scrollIt;
  this.scrollup = scrollup; 
  this.scrolldown = scrolldown;
  this.scroller = scroller;
  this.hidearrow = hidearrow;
  return this; 
}



//the basic function to make the textbox div move
function scrollIt(xpos,ypos) {
this.x=xpos; 
this.y=ypos;
this.styleElem.left = xpos;
this.styleElem.top = ypos;
 }


var minheight, contbox, textbox;

/* function to make the textbox div move up, giving the viewer the illustion that she is 
scrolling the frame down. */

function scrolldown (incr) {
minheight = this.elemheight - contbox.clipheight;
if (this.y > - minheight) {
   this.scrollIt(0,this.y-incr);
   if (loop == 1) {
     timer1 = setTimeout(("textbox.scrolldown("+incr+")"),scrollspeed)
     }
   }
}


/* function to make the text box div move down, giving the viewer the illustion that she is 
scrolling the frame up. */

function scrollup (incr) {
if (this.y < 0) {
    this.scrollIt(0,this.y-incr);
   if (loop == 1) {
   timer2 = setTimeout("textbox.scrollup("+incr+")",scrollspeed);
    }
  }
  
}



//Calls the scrolling functions. Also checks whether the page is loaded or not.

function scroller(elem,incr){
	contbox=eval("box"+elem);
	textbox=eval("text"+elem);
	if(loaded == 1){
	    loop=1;
	    hidearrow(elem);
		if(incr > 0){
		textbox.scrolldown(incr)
		}
	else {textbox.scrollup(incr)}
	}
}



//Stops the scrolling (called on mouseout)
function stopscroller(elem,arrowdir){
	loop=0; if (timer1) clearTimeout(timer1);
	
    hidearrow(elem,arrowdir);
}


//Make the arrow disappear when there is no more to scroll.
function hidearrow(elem) {
	if (document.layers) {
	  textelem_top = parseInt(eval(doc+elem+"box"+doc2+elem+"text.height"));
      }
    else {
       textelem = eval(doc + elem + "text" + sty);
       textelem_top = parseInt(textelem.top);
 
         }
    uparrow = eval (doc + elem + "up" + sty);
    downarrow = eval (doc + elem + "down" + sty);
	
	if(textelem_top < 0 && textelem_top > -minheight) { 
       uparrow.visibility = "visible";
	    downarrow.visibility = "visible";
	  }
	
	else if (textelem_top <= -minheight) { 
	   uparrow.visibility = "visible";
	   downarrow.visibility = "hidden";
	    }
	else { 
        uparrow.visibility = "hidden";
	    downarrow.visibility = "visible";
	  } 
	}
  

// jumps to the top of the scrolling text. Called onclick.

function toTop(elem) {
 textelem = eval('text'+elem);
 textelem.scrollIt(0,0);
 }

