/*
Junciona-JS Simple Scroll : Copyright (C) 2001 Luis Navalpotro.
Distributed under the terms of the GNU Library General Public License
Avalaible at http://sourceforge.net/projects/junciona/
questions&contact: lnavalpotro@terra.es
http://ns1.junciona.com
version 0.2. 07-September-2001.
modified for Residencia Unamuno
*/

junciona.virtualScroll = function(obj,parent,x,y,w,h,bgColor,visib,stack,content) {
  objeto = new junciona.scroll(obj,parent,x,y,w,h,bgColor,visib,stack,content);
  eval(obj+"=objeto");
  eval ("self."+obj+" = objeto");
  return objeto;
}

junciona.scroll = function(obj,parent,x,y,w,h,bgColor,visib,stack,content){
  this.id = obj;
  this.maxTop = 0;
  this.maxRight = w - 30;
  this.scrollActive = false;
  this.frame =  junciona(obj,parent,x,y,w,h,bgColor,visib,15,null);
  this.scrollTxt = junciona(this.id+"Txt",this.frame,0,0,this.maxRight,null,null,"show",19,null);
}

junciona.scroll.prototype.setContent = function(content){
  this.scrollTxt.setContent(content,true);
  setTimeout(this.id+".updLimits()",0);
}

junciona.scroll.prototype.updLimits = function(){
  this.scrollTxt.h = this.scrollTxt.getLayerHeight();
  this.maxBottom = this.frame.h-this.scrollTxt.h;
}

junciona.scroll.prototype.setArrows = function(fup,xup,yup,fdown,xdown,ydown,rollOver){
  this.fup = junciona(fup,this.frame,xup,yup,11,18,null,"show",20,"<a href=javascript:void(null) onmouseover="+fup+".rollOver('ON');"+this.id+".scrollOn(1) onmouseout="+fup+".rollOver('OFF');"+this.id+".scrollOff()><img src=img/"+fup+"OFF.gif id="+fup+"Img name="+fup+"Img border=0></a>");

  this.fdown = junciona(fdown,this.frame,xdown,ydown,11,18,null,"show",20,"<a href=javascript:void(null) onmouseover="+fdown+".rollOver('ON');"+this.id+".scrollOn(-1) onmouseout="+fdown+".rollOver('OFF');"+this.id+".scrollOff()><img src=img/"+fdown+"OFF.gif id="+fdown+"Img name="+fdown+"Img border=0></a>");
}

junciona.scroll.prototype.start = function(){
  setTimeout(this.id+".scrollOn(1)",10);
}

junciona.scroll.prototype.scrollOn = function(dir){
  if (this.scrollActive == false){
    this.scrollActive = true;
    this.doScroll(dir);
  }
}

junciona.scroll.prototype.doScroll = function(dir){
  if (this.scrollTxt.y<=0 && this.scrollTxt.y >= this.maxBottom){
    if (this.scrollTxt.y+dir != 1 && this.scrollTxt.y+dir != this.maxBottom){
      this.scrollTxt.move(this.scrollTxt.x,this.scrollTxt.y+dir);
    }else if (this.scrollTxt.y+dir == 1){
      this.scrollActive = false;
    }else if (this.scrollTxt.y+dir == this.maxBottom){
      this.scrollActive = false;
    }
    if (this.scrollActive == true) this.timeScroll = setTimeout(this.id+".doScroll("+dir+")",20);
  }
}

junciona.scroll.prototype.scrollOff = function(){
  this.scrollActive=false;
  clearTimeout(this.timeScroll);
}
